Page 1 of 1

serendipity_event_includeentry - Show RANDOM blocks

Posted: Mon Mar 04, 2013 6:20 am
by mangeshgokhale
Hi,

I want to report a bug in serendipity_event_includeentry plugin. I am using Serendipity 1.7-rc3 and PHP 5.3.1 with SQLite DB.

From the Serendipity Administration UI, if I go to "Configure Plugins", select "Show random blocks" to Yes and Save, and then if I go to "Back to Weblog" , it shows the following :

== TESTING ERROR MODE ==

Fatal error: Uncaught exception 'ErrorException' with message 'Serendipity error: sqlite_query() [<a href='function.sqlite-query'>function.sqlite-query</a>]: no such function: RAND' in D:\Mangesh\xampp\htdocs\serendipity\include\compat.inc.php:118
Stack trace:
#0 [internal function]: errorToExceptionHandler(2, 'sqlite_query() ...', 'D:\Mangesh\xamp...', 233, Array)
#1 D:\Mangesh\xampp\htdocs\serendipity\include\db\sqlite.inc.php(233): sqlite_query('SELECT *? ...', Resource id #18)
#2 D:\Mangesh\xampp\htdocs\serendipity\plugins\serendipity_event_includeentry\serendipity_event_includeentry.php(420): serendipity_db_query('SELECT *? ...', true, 'assoc', 1)
#3 D:\Mangesh\xampp\htdocs\serendipity\plugins\serendipity_event_includeentry\serendipity_event_includeentry.php(684): serendipity_event_includeentry->fetchStaticBlocks('block', 'RAND()', 1)
#4 D:\Mangesh\xampp\htdocs\serendipity\include\plugin_api.inc.php(1073): serendipity_event_includeentry->event_hook('frontend_displa...', Object(serendipity_property_bag), Arr in D:\Mangesh\xampp\htdocs\serendipity\include\compat.inc.php on line 118

This error shows up because probably there is no RAND function in SQLite. So we need to change it to RANDOM instead of RAND for SQLite..

- Mangesh Gokhale

Re: serendipity_event_includeentry - Show RANDOM blocks

Posted: Mon Mar 04, 2013 10:25 am
by Timbalu
Thanks for noting!
Could you try to replace the
$this->staticblock = $this->fetchStaticBlocks('block', 'RAND()', 1);
at line ~684 in serendipity_event_includeentry.php with this

Code: Select all

if (stristr($serendipity['dbType'], 'sqlite') === FALSE) {
    $this->staticblock = $this->fetchStaticBlocks('block', 'RAND()', 1);
} else {
    $this->staticblock = $this->fetchStaticBlocks('block', 'RANDOM()', 1);
}
and see if that works, please?

Re: serendipity_event_includeentry - Show RANDOM blocks

Posted: Mon Mar 04, 2013 10:30 am
by mangeshgokhale
Hi Ian.

I replaced the code and it works now.

Thanks a lot.

Mangesh

Re: serendipity_event_includeentry - Show RANDOM blocks

Posted: Mon Mar 04, 2013 10:50 am
by Timbalu
Thank you!

Garvin, is that the way to go, since we have sqlite, sqlite3 and pdo-sqlite?
I don't really know if that does have to fit to all three ....?!
I also found http://jan.kneschke.de/projects/mysql/order-by-rand/ which should be worth to note about optimizing that RAND query.

Re: serendipity_event_includeentry - Show RANDOM blocks

Posted: Mon Mar 04, 2013 3:51 pm
by onli
Hi Ian
I think i can answer that for you. This is a candiate for a {RANDOM}-Variable in serendipity_db_schema_import. But to fix the plugin for the time being, you should probably indeed catch all sqlite-dbType: 'sqlite', 'sqlite3', 'pdo-sqlite'.

But: afaik RAND() is mysql-specific, postgresql also uses RANDOM. So we should write it the other way around:

Code: Select all

if (mysql)
     RAND
else
    RANDOM