diff options
-rw-r--r-- | includes/common.inc | 6 | ||||
-rw-r--r-- | modules/simpletest/tests/common.test | 6 |
2 files changed, 10 insertions, 2 deletions
diff --git a/includes/common.inc b/includes/common.inc index 679c3cbd0..050e8e77f 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -5875,8 +5875,10 @@ function drupal_write_record($table, &$object, $primary_keys = array()) { } } // If we have a single-field primary key but got no insert ID, the - // query failed. - elseif (count($primary_keys) == 1) { + // query failed. Note that we explicitly check for FALSE, because + // a valid update query which doesn't change any values will return + // zero (0) affected rows. + elseif ($last_insert_id === FALSE && count($primary_keys) == 1) { $return = FALSE; } diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test index 8b2e24e21..35a2a7f87 100644 --- a/modules/simpletest/tests/common.test +++ b/modules/simpletest/tests/common.test @@ -1476,6 +1476,12 @@ class DrupalDataApiTest extends DrupalWebTestCase { $update_result = drupal_write_record('taxonomy_vocabulary', $vocabulary, array('vid')); $this->assertTrue($update_result == SAVED_UPDATED, t('Correct value returned when a record updated with drupal_write_record() for table with single-field primary key.')); + // Run an update query where no field values are changed. The database + // layer should return zero for number of affected rows, but + // db_write_record() should still return SAVED_UPDATED. + $update_result = drupal_write_record('taxonomy_vocabulary', $vocabulary, array('vid')); + $this->assertTrue($update_result == SAVED_UPDATED, t('Correct value returned when a valid update is run without changing any values.')); + // Insert an object record for a table with a multi-field primary key. $node_access = new stdClass(); $node_access->nid = mt_rand(); |