Search functions gives Database_Exception [ Database Error ]

DiegoS

Joined: 2012-01-16
Posts: 20
Posted: Thu, 2013-03-14 09:00

Hello I'm experiencing a proble that looks very similar as post
http://galleryproject.org/node/109194.

I'll try to explain what happens.

When search for a keyword that is common in more than than two items ( can be in the photo name, description or tag field) the result of the search shows the thumbnail of the photo , but when clicked on the thumbnail an error page opens ( at the and of the post you will find it).

Please note if on the sidebar the block popular tag is active and if clicked on a specific tag that is present on multiple photos everything works fine.

It looks like that the search modules could be the cause.

DiegoS

----------------------------------------------------
Here is the error page

:-(
Dang... Something went wrong!

We tried really hard, but it's broken.

Hey wait, you're an admin! We can tell you stuff.

There's an error message below and you can find more details in gallery3/var/logs (look for the file with the most recent date on it). Stuck? Stop by the Gallery 3 Forums and ask for help. You can also look at our list of open tickets to see if the problem you're seeing has been reported. If you post a request, here's some useful information to include:

Platform information

Host name: localhost
Operating system: Darwin 11.4.2
Apache: Apache/2.2.23 (Unix) mod_ssl/2.2.23 OpenSSL/0.9.8r DAV/2 PHP/5.4.10
PHP: 5.4.10
MySQL: 5.5.29
Server load: 0.06494140625 0.17041015625 0.1669921875
Graphics toolkit: gd
Gallery stats

Version: 3.0.5 (Daydreaming)
Albums: 0
Photos: 2
Database_Exception [ Database Error ]:
#1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'BY `score` DESC' at line 1 [ SELECT SQL_CALC_FOUND_ROWS `items`.*, MATCH(`search_records`.`data`) AGAINST ('1Ztest 1Ztest*') AS `score` FROM `items` JOIN `search_records` ON (`items`.`id` = `search_records`.`item_id`) WHERE MATCH(`search_records`.`data`) AGAINST ('1Ztest 1Ztest*' IN BOOLEAN MODE) HAVING `score` >= 0ORDER BY `score` DESC ]
SYSPATH/libraries/Database_Mysqli_Result.php[ 27 ]

22 }
23 elseif (is_bool($result))
24 {
25 if ($result == FALSE)
26 {
27 throw new Database_Exception('#:errno: :error [ :query ]',
28 array(':error' => $link->error,
29 ':query' => $sql,
30 ':errno' => $link->errno));
31 }
32 else
SYSPATH/libraries/Database_Mysqli.php[ 79 ] » Database_Mysqli_Result_Core->__construct( arguments )

SYSPATH/libraries/Database.php[ 272 ] » Database_Mysqli_Core->query_execute( arguments )

MODPATH/gallery/libraries/MY_Database.php[ 48 ] » Database_Core->query( arguments )

MODPATH/search/helpers/search.php[ 156 ] » Database->query( arguments )

MODPATH/search/controllers/search.php[ 83 ] » search_Core::get_position_within_album( arguments )

{PHP internal call} » Search_Controller::get_display_context( arguments )

MODPATH/gallery/helpers/item.php[ 419 ] » call_user_func_array( arguments )

MODPATH/gallery/controllers/photos.php[ 34 ] » item_Core::get_display_context( arguments )

{PHP internal call} » Photos_Controller->show( arguments )

SYSPATH/core/Kohana.php[ 331 ] » ReflectionMethod->invokeArgs( arguments )

{PHP internal call} » Kohana_Core::instance( arguments )

SYSPATH/core/Event.php[ 208 ] » call_user_func_array( arguments )

APPPATH/Bootstrap.php[ 67 ] » Event_Core::run( arguments )

DOCROOT/index.php[ 116 ] » require( arguments )

Environment

 
shadlaws

Joined: 2012-03-14
Posts: 183
Posted: Thu, 2013-03-14 11:33

@DiegoS - Hmm, I suspect this might be related to a recent bug we fixed. Try swapping modules/gallery/libraries/Theme_View.php with the revised one:

For viewing:
http://github.com/gallery/gallery3/blob/3.0.x/modules/gallery/libraries/Theme_View.php

For raw download:
http://raw.github.com/gallery/gallery3/3.0.x/modules/gallery/libraries/Theme_View.php

If you want, you can also get the latest updates for 3.0.5 as a complete zip here:
http://github.com/gallery/gallery3/zipball/3.0.x

Take care,
Shad

 
DiegoS

Joined: 2012-01-16
Posts: 20
Posted: Thu, 2013-03-14 14:00

Hi shadlaws,

I've tried but nothing changes.

I modified file gallery3>modules>search>helpers>search.php

and I've replaced all occurences of "ORDER BY `score` DESC "

with

" ORDER BY `score` DESC "

As you can see I've just added a space before ORDER BY.

It works but I'm afraid that can hits some other Gallery function.

 
shadlaws

Joined: 2012-03-14
Posts: 183
Posted: Thu, 2013-03-14 14:55

@DiegoS - ah, I see the problem! Yes, you're right - there's a bug there. Thanks for catching that!

I opened a ticket (https://sourceforge.net/apps/trac/gallery/ticket/2062) and posted a fix up to Github which should be in the 3.0.x branch soon.

Thanks,
Shad

 
DiegoS

Joined: 2012-01-16
Posts: 20
Posted: Thu, 2013-03-14 14:59

Good !

Thanks,

DiegoS

 
shadlaws

Joined: 2012-03-14
Posts: 183
Posted: Thu, 2013-03-14 17:54

@DiegoS - Alright, should be all fixed! The updated search.php is below.

For viewing:
http://github.com/gallery/gallery3/blob/3.0.x/modules/search/helpers/search.php

For raw download:
http://raw.github.com/gallery/gallery3/3.0.x/modules/search/helpers/search.php

As before if you want, you can also get the latest updates for 3.0.5 as a complete zip here:
http://github.com/gallery/gallery3/zipball/3.0.x

Take care,
Shad

 
DiegoS

Joined: 2012-01-16
Posts: 20
Posted: Fri, 2013-03-15 11:52

Thanks shad laws!

Diego