Viewing an empty image gallery produces an SQL error. The following one-line patch fixes it.

--- orig/image/contrib/image_gallery/image_gallery.module       2007-08-22 13:39:45.000000000 -0400
+++ patched/image/contrib/image_gallery/image_gallery.module    2007-09-06 14:08:13.000000000 -0400
@@ -145,7 +145,7 @@
     $tree = taxonomy_get_tree(_image_gallery_get_vid(), $galleries[$i]->tid, -1);
     $descendant_tids = array_merge(array($galleries[$i]->tid), array_map('_taxonomy_get_tid_from_term', $tree));
     $last = db_fetch_object(db_query_range(db_rewrite_sql('SELECT n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN (%s) AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC'), implode(',', $descendant_tids), 0, 1));
-    $galleries[$i]->latest = node_load(array('nid' => $last->nid));
+    $galleries[$i]->latest = node_load(array('nid' => intval($last->nid)));
   }

   $images = array();

Comments

drewish’s picture

what's the error? it's a good habit to post those, it makes it easier for others with the same problem to search for and find your issue. is this related to: http://drupal.org/node/133044 ?

drewish’s picture

it might not be related. why not just check check if ($last) rather than calling node load with a null that's been cast to 0... seems kind of wasteful.

pillarsdotnet’s picture

Thanks. The error was about a type mismatch and might occur only on Postgres; it referred to a bad WHERE n.nid='' clause because the db_fetch_object() call was returning array('nid' => '').

So here's a a re-patch according to your suggestion, but it's no longer a one-liner:

--- orig/image/contrib/image_gallery/image_gallery.module       2007-08-22 13:39:45.000000000 -0400
+++ patched/image/contrib/image_gallery/image_gallery.module    2007-09-06 14:42:23.000000000 -0400
@@ -145,7 +145,9 @@
     $tree = taxonomy_get_tree(_image_gallery_get_vid(), $galleries[$i]->tid, -1);
     $descendant_tids = array_merge(array($galleries[$i]->tid), array_map('_taxonomy_get_tid_from_term', $tree));
     $last = db_fetch_object(db_query_range(db_rewrite_sql('SELECT n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN (%s) AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC'), implode(',', $descendant_tids), 0, 1));
-    $galleries[$i]->latest = node_load(array('nid' => $last->nid));
+    if ($last->nid) {
+      $galleries[$i]->latest = node_load(array('nid' => $last->nid));
+    }
   }
 
   $images = array();

Well, it *could* be a one-liner, but I'd rather preserve existing code practice than stuff the whole if-block on a single line.

drewish’s picture

Status: Needs review » Fixed
StatusFileSize
new1.08 KB

okay, i'd committed #133044 so i had to adjust this. i committed the attached patch to HEAD and DRUPAL-5.

Anonymous’s picture

Status: Fixed » Closed (fixed)