The webform_get_submissions function in webform_submission.inc appears to be have been broken with the addition of a new parameter. This function sets up a parameterized query on the database. The problem is that the query construction is conditional based on the invocation with a zero or non-zero pagercount, but the query execution does not conditionally pass arguments...it always supplies nid, sids and uid. Thus, when pagercount is zero, the null sids variable will be consumed by the desired uid value thus breaking the query.

Suggested fix: I think the query execution must be conditional because either the sid or the uid could be zero so you probably need to do something like:

if ( $pager_count )
    $res = db_query($query, $nid, $sids, $uid); 
else
    $res = db_query($query, $nid, $uid);

I don't know if this problem manifests itself in normal usage. I am calling the webform_get_submissions function in a custom module and this functionality broke when I updated from 6.x-2.3 to 6.x-2.4. I'm also not sure what the drupal module development conventions are. Is this function considered part of the API or was it not supposed to be used outside this module and that is why it exists in an .inc file? How does a module designate its API functions from its internal functions? Regardless, the logic appears incorrect.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quicksketch’s picture

Status: Active » Fixed
FileSize
1.02 KB

Probably related to #360443: Empty results tab generates SQL error.

I've fixed this by rearranging the query slightly so that $sids are the last query parameter, so they'll be ignored if they're extra.

quicksketch’s picture

FileSize
649 bytes

Ah, that's not going to work at all. Here's a version that uses the fix you suggested.

quicksketch’s picture

Title: webform_get_submissions appears broken when new pagercount parameter not supplied » webform_get_submissions() Breaks When Pagercount Ommitted

Title for posterity.

quicksketch’s picture

Title: webform_get_submissions() Breaks When Pagercount Ommitted » webform_get_submissions() Breaks When $pager_count Ommitted

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.