error in creating temporary table when pages shows several embedded galleries.

liyanguo - January 18, 2009 - 18:10
Project:Fast Gallery
Version:6.x-3.2-beta2
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:postponed (maintainer needs more info)
Description

getPicsHierarchy() in fast_gallery.class.php seemed to be called every time when a [fg:xxxx/xxxx] tag is rendered. The function creates temporary databases table with names such as fast_gallery_images, fast_gallery_folders, fast_gallery_images_noexif, fast_gallery_folders_noexif etc.

If I included a gallery in my blog using [fg:xxx/xxxx] html filter and the my front page is displaying several blogs with [fg:xxxx/xxxx] filter. Then I get a temporary table already exist error on the page. Nothing is displayed. When I search on google, there are a handful of sites running fast gallery with this error.

This is because the temporary table is only destroyed per page view where we want the temporary tables to be destroyed per getPicsHierarchy() call. The db_query_temporary() call is colliding with the previous ones on table names.

One solution is to have different temporary table name per call.

I am not an experience program but I added these lines to the getPicsHierarchy function to fix the problem

//fix duplicate temporary table problem.
// this function is called a couple times if fast gallery is embedded in to a webpage, which cause a table name conflict.
$table_postfix = "_" . (rand()%10000000);
if ( preg_match( "/[a-zA-Z]+$/", $folder, $matches) )
{
$table_postfix= $table_post_fix . "_" . $matches[0];
}
//end

I then appended all $table_postfix to all temporary table queries.

I could not use full gallery path name as table postfix because mysql requires table name to be less than 64 characters. Some of my url, because of SEO, are longer that that. So I took the last couple of letters of my folder name plus a random integer. For my purpose it is unique enough and hopefully less than 64 characters long.

This seems to solve my problem. I just want to post it here in case some other people have the same problem. I enjoyed using fast_gallery module. The website I am working on is http://www.urbancooking.net in case anyone want to see another demo of fast gallery. :-)

#1

rapsli - January 23, 2009 - 21:48
Status:active» postponed (maintainer needs more info)

thanks for the fix. I don't have time to test, so that's why I ask: where did you append $table_postfix. For example:

db_query_temporary($sql_images, $folder, $image_direction, 'fast_gallery_images'); ... where would it be here? I assume it's every db_query_temporary the same.

 
 

Drupal is a registered trademark of Dries Buytaert.