diff --git a/includes/common.inc b/includes/common.inc index 470402ab8eccfa612bf2f61f28a32d48acc8026d..48f27bd29b7d6297067b16c94e731a2486bbaf67 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -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 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. - * @param update + * @param $update * 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 * 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, - * TRUE is returned. The $object parameter contains values for any serial - * fields defined by the $table. For example, $object->nid will be populated - * after inserting a new node. + * @return + * Failure to write a record will return FALSE. Otherwise SAVED_NEW or + * SAVED_UPDATED is returned depending on the operation performed. The + * $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()) { // Standardize $update to an array. @@ -3292,21 +3294,25 @@ function drupal_write_record($table, &$object, $update = array()) { $query = "UPDATE {". $table ."} SET $query WHERE ". implode(' AND ', $conditions); $return = SAVED_UPDATED; } - db_query($query, $values); - if ($serials) { - // Get last insert ids and fill them in. - foreach ($serials as $field) { - $object->$field = db_last_insert_id($table, $field); + // Execute the SQL. + if (db_query($query, $values)) { + if ($serials) { + // Get last insert ids and fill them in. + foreach ($serials as $field) { + $object->$field = db_last_insert_id($table, $field); + } + } + + // If we began with an array, convert back so we don't surprise the caller. + if ($array) { + $object = (array) $object; } - } - // If we began with an array, convert back so we don't surprise the caller. - if ($array) { - $object = (array)$object; + return $return; } - return $return; + return FALSE; } /**