This isn't a 'bug' in behaviour per say, but an error I think that should be caught.

Calls to db_insert() and db_merge() silently fail when a small typo is made in calling them:

  $query = db_merge('tablename')
    ->key(array('colname', $fieldvalue))
    ->fields(array(
      'col1' => $val1,
      'col2' => $val2,
      'col3' => $val3,
    ))
    ->execute();

Note how in $key the fields are listed numerically, not associatively. The corrected line would look like:

    ->key(array('colname' => $fieldvalue))

If this programming error is made either in key() or fields(), the return value is a simple integer and the query fail with no error output or message in the site logs.

Comments

gaurav.bajpai’s picture

Assigned: Unassigned » gaurav.bajpai
gaurav.bajpai’s picture

Hi stewart.adam,

Give the file name where you found this bug.

Thanks,
Gaurav

skatheeth’s picture

A file name would help us out to find a solution.

stewart.adam’s picture

There's no place this happens in core (to my knowledge), but you can reproduce this easily in custom code. I was pointing out that the database system in Drupal, while its implementation is technically correct, doesn't perform sufficient validation on its input and it's easy to cause a silent error.

If you place a code snipped like I included in my original post that uses an numerically indexes array for ->key() instead of an associative one, you'll get a silent error instead of an traceback or invalid result set.

Version: 7.34 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.