Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
gaurav.bajpai CreditAttribution: gaurav.bajpai as a volunteer and at Faichi Solutions Pvt Ltd commentedComment #2
gaurav.bajpai CreditAttribution: gaurav.bajpai as a volunteer and at Faichi Solutions Pvt Ltd commentedHi stewart.adam,
Give the file name where you found this bug.
Thanks,
Gaurav
Comment #3
skatheeth CreditAttribution: skatheeth commentedA file name would help us out to find a solution.
Comment #4
stewart.adam CreditAttribution: stewart.adam commentedThere'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.