rendered paste body=== modified file 'includes/database.mysql.inc'--- includes/database.mysql.inc 2007-05-25 21:01:29 +0000+++ includes/database.mysql.inc 2007-05-29 23:27:02 +0000@@ -434,6 +434,11 @@ function db_distinct_field($table, $fiel return preg_replace('/(SELECT.*)(?:'. $table .'\.|\s)(?<!DISTINCT\()(?<!DISTINCT\('. $table .'\.)'. $field .'(.*FROM )/AUsi', '\1 '. $field_to_select .'\2', $query); }+function db_last_insert_id() {+ return mysql_query('SELECT LAST_INSERT_ID()');+}++ /** * @} End of "ingroup database". */=== modified file 'includes/database.mysqli.inc'--- includes/database.mysqli.inc 2007-05-25 21:01:29 +0000+++ includes/database.mysqli.inc 2007-05-29 23:27:32 +0000@@ -231,25 +231,6 @@ function db_error() { } /**- * Return a new unique ID in the given sequence.- *- * For compatibility reasons, Drupal does not use auto-numbered fields in its- * database tables. Instead, this function is used to return a new unique ID- * of the type requested. If necessary, a new sequence with the given name- * will be created.- *- * Note that the table name should be in curly brackets to preserve compatibility- * with table prefixes. For example, db_next_id('{node}_nid');- */-function db_next_id($name) {- global $active_db;- $name = db_prefix_tables($name);- db_query('INSERT INTO {sequences} VALUES ("%s", LAST_INSERT_ID(1)) ON DUPLICATE KEY UPDATE id = LAST_INSERT_ID(id + 1)', $name);-- return mysqli_insert_id($active_db);-}--/** * Determine the number of rows changed by the preceding query. */ function db_affected_rows() {@@ -426,6 +407,11 @@ function db_distinct_field($table, $fiel return preg_replace('/(SELECT.*)(?:'. $table .'\.|\s)(?<!DISTINCT\()(?<!DISTINCT\('. $table .'\.)'. $field .'(.*FROM )/AUsi', '\1 '. $field_to_select .'\2', $query); }+function db_last_insert_id() {+ global $active_db,+ return mysqli_query($active_db, 'SELECT LAST_INSERT_ID()');+}+ /** * @} End of "ingroup database". */=== modified file 'includes/database.pgsql.inc'--- includes/database.pgsql.inc 2007-05-29 11:36:33 +0000+++ includes/database.pgsql.inc 2007-05-29 23:28:13 +0000@@ -221,20 +221,8 @@ function db_error() { return pg_last_error($active_db); }-/**- * Return a new unique ID in the given sequence.- *- * For compatibility reasons, Drupal does not use auto-numbered fields in its- * database tables. Instead, this function is used to return a new unique ID- * of the type requested. If necessary, a new sequence with the given name- * will be created.- *- * Note that the table name should be in curly brackets to preserve compatibility- * with table prefixes. For example, db_next_id('{node}_nid');- */-function db_next_id($name) {- $id = db_result(db_query("SELECT nextval('%s_seq')", db_prefix_tables($name)));- return $id;+function db_last_insert_id($name) {+ return db_result(db_query("SELECT currval('%s_seq')", db_prefix_tables($name))); } /**=== modified file 'modules/aggregator/aggregator.module'--- modules/aggregator/aggregator.module 2007-05-29 14:37:49 +0000+++ modules/aggregator/aggregator.module 2007-05-29 23:29:56 +0000@@ -427,8 +427,7 @@ function aggregator_save_category($edit) } else if (!empty($edit['title'])) { // A single unique id for bundles and feeds, to use in blocks- $next_id = db_next_id('{aggregator_category}_cid');- db_query("INSERT INTO {aggregator_category} (cid, title, description, block) VALUES (%d, '%s', '%s', 5)", $next_id, $edit['title'], $edit['description']);+ db_query("INSERT INTO {aggregator_category} (title, description, block) VALUES ('%s', '%s', 5)", $edit['title'], $edit['description']); } }@@ -578,9 +577,9 @@ function aggregator_save_feed($edit) { db_query('DELETE FROM {aggregator_item} WHERE fid = %d', $edit['fid']); } else if ($edit['title']) {+ db_query("INSERT INTO {aggregator_feed} (title, url, refresh, block) VALUES ('%s', '%s', %d, 5)", $edit['title'], $edit['url'], $edit['refresh']); // A single unique id for bundles and feeds, to use in blocks.- $edit['fid'] = db_next_id('{aggregator_feed}_fid');- db_query("INSERT INTO {aggregator_feed} (fid, title, url, refresh, block) VALUES (%d, '%s', '%s', %d, 5)", $edit['fid'], $edit['title'], $edit['url'], $edit['refresh']);+ $edit['fid'] = db_last_insert_id('{aggregator_feed}_fid'); } if ($edit['title']) { // The feed is being saved, save the categories as well.@@ -985,8 +984,8 @@ function aggregator_save_item($edit) { db_query('DELETE FROM {aggregator_category_item} WHERE iid = %d', $edit['iid']); } else if ($edit['title'] && $edit['link']) {- $edit['iid'] = db_next_id('{aggregator_item}_iid');- db_query("INSERT INTO {aggregator_item} (iid, fid, title, link, author, description, timestamp, guid) VALUES (%d, %d, '%s', '%s', '%s', '%s', %d, '%s')", $edit['iid'], $edit['fid'], $edit['title'], $edit['link'], $edit['author'], $edit['description'], $edit['timestamp'], $edit['guid']);+ db_query("INSERT INTO {aggregator_item} (fid, title, link, author, description, timestamp, guid) VALUES (%d, '%s', '%s', '%s', '%s', %d, '%s')", $edit['fid'], $edit['title'], $edit['link'], $edit['author'], $edit['description'], $edit['timestamp'], $edit['guid']);+ $edit['iid'] = db_last_insert_id('{aggregator_item}_iid'); // file the items in the categories indicated by the feed $categories = db_query('SELECT cid FROM {aggregator_category_feed} WHERE fid = %d', $edit['fid']); while ($category = db_fetch_object($categories)) {=== modified file 'modules/block/block.module'--- modules/block/block.module 2007-05-28 06:08:37 +0000+++ modules/block/block.module 2007-05-29 23:31:50 +0000@@ -538,7 +538,8 @@ function block_add_block_form_validate($ * Save the new custom block. */ function block_add_block_form_submit($form, &$form_state, $form_values) {- $delta = db_next_id('{boxes}_bid');+ db_query("INSERT INTO {boxes} (body, info, format) VALUES ('%s', '%s', %d)", $form_values['body'], $form_values['info'], $form_values['format']);+ $delta = db_last_insert_id('{boxes}_bid'); foreach (list_themes() as $key => $theme) { if ($theme->status) {@@ -550,8 +551,6 @@ function block_add_block_form_submit($fo db_query("INSERT INTO {blocks_roles} (rid, module, delta) VALUES (%d, '%s', '%s')", $rid, $form_values['module'], $delta); }- db_query("INSERT INTO {boxes} (bid, body, info, format) VALUES (%d, '%s', '%s', %d)", $delta, $form_values['body'], $form_values['info'], $form_values['format']);- drupal_set_message(t('The block has been created.')); cache_clear_all();=== modified file 'modules/comment/comment.module'--- modules/comment/comment.module 2007-05-29 06:27:37 +0000+++ modules/comment/comment.module 2007-05-29 23:32:30 +0000@@ -812,7 +812,6 @@ function comment_save($edit) { } }- $edit['cid'] = db_next_id('{comments}_cid'); $edit['timestamp'] = time(); if ($edit['uid'] === $user->uid) { // '===' because we want to modify anonymous users too@@ -820,7 +819,8 @@ function comment_save($edit) { } $edit += array('mail' => '', 'homepage' => '');- db_query("INSERT INTO {comments} (cid, nid, pid, uid, subject, comment, format, hostname, timestamp, status, score, users, thread, name, mail, homepage) VALUES (%d, %d, %d, %d, '%s', '%s', %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s')", $edit['cid'], $edit['nid'], $edit['pid'], $edit['uid'], $edit['subject'], $edit['comment'], $edit['format'], ip_address(), $edit['timestamp'], $status, $score, $users, $thread, $edit['name'], $edit['mail'], $edit['homepage']);+ db_query("INSERT INTO {comments} (nid, pid, uid, subject, comment, format, hostname, timestamp, status, score, users, thread, name, mail, homepage) VALUES %d, %d, %d, '%s', '%s', %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s')", $edit['nid'], $edit['pid'], $edit['uid'], $edit['subject'], $edit['comment'], $edit['format'], ip_address(), $edit['timestamp'], $status, $score, $users, $thread, $edit['name'], $edit['mail'], $edit['homepage']);+ $edit['cid'] = db_last_insert_id('{comments}_cid'); _comment_update_node_statistics($edit['nid']);=== modified file 'modules/drupal/drupal.module'--- modules/drupal/drupal.module 2007-04-30 17:03:22 +0000+++ modules/drupal/drupal.module 2007-05-29 23:33:16 +0000@@ -196,8 +196,8 @@ function drupal_client_ping($client, $sy db_query("UPDATE {client} SET link = '%s', name = '%s', mail = '%s', slogan = '%s', mission = '%s', users = %d, nodes = %d, version = '%s', changed = '%s' WHERE cid = %d", $client['uid'], $client['link'], $client['name'], $client['mail'], $client['slogan'], $client['mission'], $client['users'], $client['nodes'], $client['version'], time(), $client['cid']); } else {- $client['cid'] = db_next_id('{client}_cid');- db_query("INSERT INTO {client} (cid, link, name, mail, slogan, mission, users, nodes, version, created, changed) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $client['cid'], $client['link'], $client['name'], $client['mail'], $client['slogan'], $client['mission'], $client['users'], $client['nodes'], $client['version'], time(), time());+ db_query("INSERT INTO {client} (link, name, mail, slogan, mission, users, nodes, version, created, changed) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $client['link'], $client['name'], $client['mail'], $client['slogan'], $client['mission'], $client['users'], $client['nodes'], $client['version'], time(), time());+ $client['cid'] = db_last_insert_id('{client}_cid'); } if (is_array($system)) { db_query("DELETE FROM {client_system} WHERE cid = %d", $client['cid']);=== modified file 'modules/taxonomy/taxonomy.module'--- modules/taxonomy/taxonomy.module 2007-05-28 06:08:37 +0000+++ modules/taxonomy/taxonomy.module 2007-05-29 23:34:49 +0000@@ -339,8 +339,8 @@ function taxonomy_save_vocabulary(&$edit $status = taxonomy_del_vocabulary($edit['vid']); } else {- $edit['vid'] = db_next_id('{vocabulary}_vid');- db_query("INSERT INTO {vocabulary} (vid, name, description, help, multiple, required, hierarchy, relations, tags, weight, module) VALUES (%d, '%s', '%s', '%s', %d, %d, %d, %d, %d, %d, '%s')", $edit['vid'], $edit['name'], isset($edit['description']) ? $edit['description'] : NULL, isset($edit['help']) ? $edit['help'] : NULL, $edit['multiple'], $edit['required'], $edit['hierarchy'], $edit['relations'], isset($edit['tags']) ? $edit['tags'] : NULL, $edit['weight'], isset($edit['module']) ? $edit['module'] : 'taxonomy');+ db_query("INSERT INTO {vocabulary} (name, description, help, multiple, required, hierarchy, relations, tags, weight, module) VALUES ('%s', '%s', '%s', %d, %d, %d, %d, %d, %d, '%s')", $edit['name'], isset($edit['description']) ? $edit['description'] : NULL, isset($edit['help']) ? $edit['help'] : NULL, $edit['multiple'], $edit['required'], $edit['hierarchy'], $edit['relations'], isset($edit['tags']) ? $edit['tags'] : NULL, $edit['weight'], isset($edit['module']) ? $edit['module'] : 'taxonomy');+ $edit['vid'] = db_last_insert_id('{vocabulary}_vid'); foreach ($edit['nodes'] as $type => $selected) { db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, '%s')", $edit['vid'], $type); }@@ -518,8 +518,8 @@ function taxonomy_save_term(&$form_value return taxonomy_del_term($form_values['tid']); } else {- $form_values['tid'] = db_next_id('{term_data}_tid');- db_query("INSERT INTO {term_data} (tid, name, description, vid, weight) VALUES (%d, '%s', '%s', %d, %d)", $form_values['tid'], $form_values['name'], $form_values['description'], $form_values['vid'], $form_values['weight']);+ db_query("INSERT INTO {term_data} (name, description, vid, weight) VALUES ('%s', '%s', %d, %d)", $form_values['name'], $form_values['description'], $form_values['vid'], $form_values['weight']);+ $form_values['tid'] = db_last_insert_id('{term_data}_tid'); $hook = 'insert'; $status = SAVED_NEW; }=== modified file 'modules/upload/upload.module'--- modules/upload/upload.module 2007-05-29 16:06:07 +0000+++ modules/upload/upload.module 2007-05-29 23:35:21 +0000@@ -721,8 +721,8 @@ function upload_save(&$node) { // New file upload elseif (strpos($file->fid, 'upload') !== FALSE) { if ($file = file_save_upload($file, $file->filename)) {- $file->fid = db_next_id('{files}_fid');- db_query("INSERT INTO {files} (fid, nid, filename, filepath, filemime, filesize) VALUES (%d, %d, '%s', '%s', '%s', %d)", $file->fid, $node->nid, $file->filename, $file->filepath, $file->filemime, $file->filesize);+ db_query("INSERT INTO {files} (nid, filename, filepath, filemime, filesize) VALUES (%d, '%s', '%s', '%s', %d)", $node->nid, $file->filename, $file->filepath, $file->filemime, $file->filesize);+ $file->fid = db_last_insert_id('{files}_fid'); db_query("INSERT INTO {file_revisions} (fid, vid, list, description) VALUES (%d, %d, %d, '%s')", $file->fid, $node->vid, $file->list, $file->description); // Tell other modules where the file was stored. $node->files[$fid] = $file;=== modified file 'modules/user/user.module'--- modules/user/user.module 2007-05-28 06:08:37 +0000+++ modules/user/user.module 2007-05-29 23:37:19 +0000@@ -210,8 +210,6 @@ function user_save($account, $array = ar user_module_invoke('after_update', $array, $user, $category); } else {- $array['uid'] = db_next_id('{users}_uid');- if (!isset($array['created'])) { // Allow 'created' to be set by hook_auth $array['created'] = time(); }@@ -226,7 +224,7 @@ function user_save($account, $array = ar $values[] = md5($value); $s[] = "'%s'"; break;- case 'uid': case 'mode': case 'sort':+ case 'mode': case 'sort': case 'threshold': case 'created': case 'access': case 'login': case 'status': $fields[] = $key;@@ -243,6 +241,7 @@ function user_save($account, $array = ar } } db_query('INSERT INTO {users} ('. implode(', ', $fields) .') VALUES ('. implode(', ', $s) .')', $values);+ $array['uid'] = db_last_insert_id('{users}_uid'); // Build the initial user object. $user = user_load(array('uid' => $array['uid']));