#626790 by justinrandell: Fixed bug where drupal_write_record() returns FALSE for valid update queries.
parent
b12a25d24f
commit
06c5979961
|
@ -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
|
// If we have a single-field primary key but got no insert ID, the
|
||||||
// query failed.
|
// query failed. Note that we explicitly check for FALSE, because
|
||||||
elseif (count($primary_keys) == 1) {
|
// 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;
|
$return = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1476,6 +1476,12 @@ class DrupalDataApiTest extends DrupalWebTestCase {
|
||||||
$update_result = drupal_write_record('taxonomy_vocabulary', $vocabulary, array('vid'));
|
$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.'));
|
$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.
|
// Insert an object record for a table with a multi-field primary key.
|
||||||
$node_access = new stdClass();
|
$node_access = new stdClass();
|
||||||
$node_access->nid = mt_rand();
|
$node_access->nid = mt_rand();
|
||||||
|
|
Loading…
Reference in New Issue