Closed (outdated)
Project:
Drupal core
Version:
7.x-dev
Component:
database system
Priority:
Minor
Category:
Bug report
Assigned:
Reporter:
Created:
9 Jan 2015 at 21:00 UTC
Updated:
24 Nov 2015 at 10:30 UTC
Jump to comment: Most recent
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 commentedComment #2
gaurav.bajpai commentedHi stewart.adam,
Give the file name where you found this bug.
Thanks,
Gaurav
Comment #3
skatheeth commentedA file name would help us out to find a solution.
Comment #4
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.