I hope this isn't a duplicate, but I couldn't find one.
It appears that when you attempt to expose a filter in a View that has included Image Attach fields, and the filtration query does not pull up any nodes (i.e., the query is empty), it produces this error.
warning: implode() [function.implode]: Invalid arguments passed in /SITEROOT/MYSITE.info/httpdocs/sites/all/modules/image/contrib/image_attach/image_attach_views_handler_field_attached_images.inc on line 73.
user warning: 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 ') ORDER BY weight' at line 1 query: SELECT nid, iid FROM image_attach WHERE nid IN () ORDER BY weight in /SITEROOT/MYSITE.info/httpdocs/sites/all/modules/image/contrib/image_attach/image_attach_views_handler_field_attached_images.inc on line 74.
This can be traced to the image_attach_views_handler_field_attached_images.inc file, specifically this piece of code.
$nids_string = implode(',', $nids);
$result = db_query("SELECT nid, iid FROM {image_attach} WHERE nid IN (" . $nids_string . ") ORDER BY weight");
while ($data = db_fetch_object($result)) {
// Store all the attached image nids (iid) keyed by attaching nid.
$attached_images[$data->nid][] = $data->iid;
}
}
This code appears to be running whenever the view is produced, so if the filter returns a null value, the query will run anyway.
I have temporarily fixed it like this:
if ($nid != ''){
$nids_string = implode(',', $nids);
$result = db_query("SELECT nid, iid FROM {image_attach} WHERE nid IN (" . $nids_string . ") ORDER BY weight");
while ($data = db_fetch_object($result)) {
// Store all the attached image nids (iid) keyed by attaching nid.
$attached_images[$data->nid][] = $data->iid;
}
}
This has not yet produced any problems, but I am wholly unaware of the implications of my actions so I hope this can be fixed in a future patch.
Again, if this is already a known issue, let this post die a horrid death.
Warmest regards,
Comments
Comment #1
jasonb-2 commentedComment #2
joachim commentedThis sounds familiar.
Can you try the dev version please? also check its CHANGELOG for anything that looks similar.
Comment #3
jasonb-2 commentedThat fixed it.
And right in the damn upgrade notes.
"#592852 by joachim: Fixed SQL error when View attached images field is empty."
Thanks.
Comment #4
jasonb-2 commentedClosing.
Comment #5
joachim commentedHeh, technically a duplicate :)
Thanks for taking the time to report this anyway, and especially for being so thorough!
Comment #6
jasonb-2 commentedA small oversight.
And my pleasure. This is a great module, I use it on many of my sites.