Commit 8ea4186e authored by Gábor Hojtsy's avatar Gábor Hojtsy
Browse files

#207170 by hswong3i slightly modified: drupal_write_record() did not return...

#207170 by hswong3i slightly modified: drupal_write_record() did not return FALSE on query failure and had bad documentation on the returned values
parent 6d191fb5
...@@ -3204,14 +3204,16 @@ function drupal_schema_fields_sql($table, $prefix = NULL) { ...@@ -3204,14 +3204,16 @@ function drupal_schema_fields_sql($table, $prefix = NULL) {
* The object to write. This is a reference, as defaults according to * The object to write. This is a reference, as defaults according to
* the schema may be filled in on the object, as well as ID on the serial * the schema may be filled in on the object, as well as ID on the serial
* type(s). Both array an object types may be passed. * type(s). Both array an object types may be passed.
* @param update * @param $update
* If this is an update, specify the primary keys' field names. It is the * If this is an update, specify the primary keys' field names. It is the
* caller's responsibility to know if a record for this object already * caller's responsibility to know if a record for this object already
* exists in the database. If there is only 1 key, you may pass a simple string. * exists in the database. If there is only 1 key, you may pass a simple string.
* @return (boolean) Failure to write a record will return FALSE. Otherwise, * @return
* TRUE is returned. The $object parameter contains values for any serial * Failure to write a record will return FALSE. Otherwise SAVED_NEW or
* fields defined by the $table. For example, $object->nid will be populated * SAVED_UPDATED is returned depending on the operation performed. The
* after inserting a new node. * $object parameter contains values for any serial fields defined by
* the $table. For example, $object->nid will be populated after inserting
* a new node.
*/ */
function drupal_write_record($table, &$object, $update = array()) { function drupal_write_record($table, &$object, $update = array()) {
// Standardize $update to an array. // Standardize $update to an array.
...@@ -3292,8 +3294,9 @@ function drupal_write_record($table, &$object, $update = array()) { ...@@ -3292,8 +3294,9 @@ function drupal_write_record($table, &$object, $update = array()) {
$query = "UPDATE {". $table ."} SET $query WHERE ". implode(' AND ', $conditions); $query = "UPDATE {". $table ."} SET $query WHERE ". implode(' AND ', $conditions);
$return = SAVED_UPDATED; $return = SAVED_UPDATED;
} }
db_query($query, $values);
// Execute the SQL.
if (db_query($query, $values)) {
if ($serials) { if ($serials) {
// Get last insert ids and fill them in. // Get last insert ids and fill them in.
foreach ($serials as $field) { foreach ($serials as $field) {
...@@ -3303,10 +3306,13 @@ function drupal_write_record($table, &$object, $update = array()) { ...@@ -3303,10 +3306,13 @@ function drupal_write_record($table, &$object, $update = array()) {
// If we began with an array, convert back so we don't surprise the caller. // If we began with an array, convert back so we don't surprise the caller.
if ($array) { if ($array) {
$object = (array)$object; $object = (array) $object;
} }
return $return; return $return;
}
return FALSE;
} }
/** /**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment