diff options
author | Dries Buytaert <dries@buytaert.net> | 2007-06-05 12:13:23 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2007-06-05 12:13:23 +0000 |
commit | 27388f66557cddce6aff1cc945601c5f843304cd (patch) | |
tree | 3a12f2afdc14b5af5be1b03d9c1fde6ac3d77928 | |
parent | 745222200e0670f55c6d695e467558171b7bb5d8 (diff) | |
download | brdo-27388f66557cddce6aff1cc945601c5f843304cd.tar.gz brdo-27388f66557cddce6aff1cc945601c5f843304cd.tar.bz2 |
- Patch #149176 by chx, David et al: getting rid of the sequences table, using db_last_insert_id() instead of db_next_id().
-rw-r--r-- | includes/database.mysql-common.inc | 12 | ||||
-rw-r--r-- | includes/database.mysql.inc | 25 | ||||
-rw-r--r-- | includes/database.mysqli.inc | 19 | ||||
-rw-r--r-- | includes/database.pgsql.inc | 24 | ||||
-rw-r--r-- | includes/file.inc | 4 | ||||
-rw-r--r-- | includes/form.inc | 5 | ||||
-rw-r--r-- | includes/menu.inc | 60 | ||||
-rw-r--r-- | modules/aggregator/aggregator.module | 11 | ||||
-rw-r--r-- | modules/block/block.module | 5 | ||||
-rw-r--r-- | modules/comment/comment.module | 4 | ||||
-rw-r--r-- | modules/drupal/drupal.module | 4 | ||||
-rw-r--r-- | modules/node/node.module | 46 | ||||
-rw-r--r-- | modules/node/node.schema | 4 | ||||
-rw-r--r-- | modules/system/system.install | 10 | ||||
-rw-r--r-- | modules/taxonomy/taxonomy.module | 8 | ||||
-rw-r--r-- | modules/user/user.module | 7 |
16 files changed, 103 insertions, 145 deletions
diff --git a/includes/database.mysql-common.inc b/includes/database.mysql-common.inc index 80f78ff36..99fde133e 100644 --- a/includes/database.mysql-common.inc +++ b/includes/database.mysql-common.inc @@ -448,6 +448,18 @@ function db_update_field(&$ret, $table, $field) { } /** + * Returns the last insert id. + * + * @param $table + * The name of the table you inserted into. + * @param $field + * The name of the autoincrement field. + */ +function db_last_insert_id($table, $field) { + return db_result(db_query('SELECT LAST_INSERT_ID()')); +} + +/** * @} End of "ingroup schemaapi". */ diff --git a/includes/database.mysql.inc b/includes/database.mysql.inc index 45426fff2..c3c6b0710 100644 --- a/includes/database.mysql.inc +++ b/includes/database.mysql.inc @@ -47,12 +47,6 @@ function db_version() { /** * Initialize a database connection. - * - * Note that you can change the mysql_connect() call to mysql_pconnect() if you - * want to use persistent connections. This is not recommended on shared hosts, - * and might require additional database/webserver tuning. It can increase - * performance, however, when the overhead to connect to your database is high - * (e.g. your database and web server live on different machines). */ function db_connect($url) { $url = parse_url($url); @@ -239,25 +233,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 mysql_insert_id($active_db); -} - -/** * Determine the number of rows changed by the preceding query. */ function db_affected_rows() { diff --git a/includes/database.mysqli.inc b/includes/database.mysqli.inc index baac124de..3bc058da8 100644 --- a/includes/database.mysqli.inc +++ b/includes/database.mysqli.inc @@ -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() { diff --git a/includes/database.pgsql.inc b/includes/database.pgsql.inc index deb6bfe58..399a72178 100644 --- a/includes/database.pgsql.inc +++ b/includes/database.pgsql.inc @@ -43,12 +43,6 @@ function db_version() { /** * Initialize a database connection. - * - * Note that you can change the pg_connect() call to pg_pconnect() if you - * want to use persistent connections. This is not recommended on shared hosts, - * and might require additional database/webserver tuning. It can increase - * performance, however, when the overhead to connect to your database is high - * (e.g. your database and web server live on different machines). */ function db_connect($url) { // Check if MySQL support is present in PHP @@ -258,19 +252,15 @@ 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. + * Returns the last insert id. This function is thread safe. * - * Note that the table name should be in curly brackets to preserve compatibility - * with table prefixes. For example, db_next_id('{node}_nid'); + * @param $table + * The name of the table you inserted into. + * @param $field + * The name of the autoincrement field. */ -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($table, $field) { + return db_result(db_query("SELECT currval('%s_seq')", db_prefix_tables('{'. $table .'}') . '_'. $field)); } /** diff --git a/includes/file.inc b/includes/file.inc index 9bf86930b..32f331b5a 100644 --- a/includes/file.inc +++ b/includes/file.inc @@ -574,8 +574,8 @@ function file_save_upload($source, $validators = array(), $dest = FALSE, $replac } // If we made it this far it's safe to record this file in the database. - $file->fid = db_next_id('{files}_fid'); - db_query("INSERT INTO {files} (fid, uid, filename, filepath, filemime, filesize, status, timestamp) VALUES (%d, %d, '%s', '%s', '%s', %d, %d, %d)", $file->fid, $user->uid, $file->filename, $file->filepath, $file->filemime, $file->filesize, FILE_STATUS_TEMPORARY, time()); + db_query("INSERT INTO {files} (uid, filename, filepath, filemime, filesize, status, timestamp) VALUES (%d, '%s', '%s', '%s', %d, %d, %d)", $user->uid, $file->filename, $file->filepath, $file->filemime, $file->filesize, FILE_STATUS_TEMPORARY, time()); + $file->fid = db_last_insert_id('files', 'fid'); // Add file to the cache. $upload_cache[$source] = $file; diff --git a/includes/form.inc b/includes/form.inc index 81ee1ea16..1bd9542b6 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -1867,7 +1867,6 @@ function batch_set($batch_definition) { // Initialize the batch if (empty($batch)) { $batch = array( - 'id' => db_next_id('{batch}_bid'), 'sets' => array(), ); } @@ -1948,7 +1947,9 @@ function batch_process($redirect = NULL, $url = NULL) { $batch['destination'] = $_REQUEST['edit']['destination']; unset($_REQUEST['edit']['destination']); } - db_query("INSERT INTO {batch} (bid, token, timestamp, batch) VALUES (%d, %d, %d, '%s')", $batch['id'], drupal_get_token($batch['id']), time(), serialize($batch)); + db_query('INSERT INTO {batch} (timestamp) VALUES (%d)', time()); + $batch['id'] = db_last_insert_id('batch', 'bid'); + db_query("UPDATE {batch} SET token = '%s', batch = '%s' WHERE bid = %d", drupal_get_token($batch['id']), serialize($batch), $batch['id']); drupal_goto($batch['url'], 'op=start&id='. $batch['id']); } else { diff --git a/includes/menu.inc b/includes/menu.inc index 9bb816276..888715548 100644 --- a/includes/menu.inc +++ b/includes/menu.inc @@ -1320,10 +1320,7 @@ function menu_link_save(&$item) { $existing_item = db_fetch_array(db_query("SELECT * FROM {menu_links} WHERE menu_name = '%s' AND link_path = '%s'", $menu_name, $item['link_path'])); } - if (!$existing_item) { - $item['mlid'] = db_next_id('{menu_links}_mlid'); - } - else { + if ($existing_item) { $item['mlid'] = $existing_item['mlid']; } @@ -1346,6 +1343,21 @@ function menu_link_save(&$item) { else { $item['plid'] = $parent['mlid']; } + db_query("INSERT INTO {menu_links} ( + menu_name, plid, link_path, + hidden, external, has_children, + expanded, weight, + module, link_title, options) VALUES ( + '%s', %d, '%s', + %d, %d, %d, + %d, %d, + '%s', '%s', '%s')", + $item['menu_name'], $item['plid'], $item['link_path'], + $item['hidden'], $item['_external'], $item['has_children'], + $item['expanded'], $item['weight'], + $item['module'], $item['link_title'], serialize($item['options'])); + $item['mlid'] = db_last_insert_id('menu_links', 'mlid'); + if (!$item['plid']) { $item['p1'] = $item['mlid']; @@ -1390,36 +1402,16 @@ function menu_link_save(&$item) { } } } - if ($existing_item) { - db_query("UPDATE {menu_links} SET menu_name = '%s', plid = %d, link_path = '%s', - router_path = '%s', hidden = %d, external = %d, has_children = %d, - expanded = %d, weight = %d, depth = %d, - p1 = %d, p2 = %d, p3 = %d, p4 = %d, p5 = %d, p6 = %d, - module = '%s', link_title = '%s', options = '%s' WHERE mlid = %d", - $item['menu_name'], $item['plid'], $item['link_path'], - $item['router_path'], $item['hidden'], $item['_external'], $item['has_children'], - $item['expanded'], $item['weight'], $item['depth'], - $item['p1'], $item['p2'], $item['p3'], $item['p4'], $item['p5'], $item['p6'], - $item['module'], $item['link_title'], serialize($item['options']), $item['mlid']); - } - else { - db_query("INSERT INTO {menu_links} ( - menu_name, mlid, plid, link_path, - router_path, hidden, external, has_children, - expanded, weight, depth, - p1, p2, p3, p4, p5, p6, - module, link_title, options) VALUES ( - '%s', %d, %d, '%s', - '%s', %d, %d, %d, - %d, %d, %d, - %d, %d, %d, %d, %d, %d, - '%s', '%s', '%s')", - $item['menu_name'], $item['mlid'], $item['plid'], $item['link_path'], - $item['router_path'], $item['hidden'], $item['_external'], $item['has_children'], - $item['expanded'], $item['weight'], $item['depth'], - $item['p1'], $item['p2'], $item['p3'], $item['p4'], $item['p5'], $item['p6'], - $item['module'], $item['link_title'], serialize($item['options'])); - } + db_query("UPDATE {menu_links} SET menu_name = '%s', plid = %d, link_path = '%s', + router_path = '%s', hidden = %d, external = %d, has_children = %d, + expanded = %d, weight = %d, depth = %d, + p1 = %d, p2 = %d, p3 = %d, p4 = %d, p5 = %d, p6 = %d, + module = '%s', link_title = '%s', options = '%s' WHERE mlid = %d", + $item['menu_name'], $item['plid'], $item['link_path'], + $item['router_path'], $item['hidden'], $item['_external'], $item['has_children'], + $item['expanded'], $item['weight'], $item['depth'], + $item['p1'], $item['p2'], $item['p3'], $item['p4'], $item['p5'], $item['p6'], + $item['module'], $item['link_title'], serialize($item['options']), $item['mlid']); // Check the has_children status of the parent. if ($item['plid']) { $parent_has_children = (bool)db_result(db_query("SELECT COUNT(*) FROM {menu_links} WHERE plid = %d AND hidden = 0", $item['plid'])); diff --git a/modules/aggregator/aggregator.module b/modules/aggregator/aggregator.module index 9e11a668d..e27c847c2 100644 --- a/modules/aggregator/aggregator.module +++ b/modules/aggregator/aggregator.module @@ -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)) { diff --git a/modules/block/block.module b/modules/block/block.module index 8de8f4952..21379b5d2 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -538,7 +538,8 @@ function block_add_block_form_validate($form, &$form_state) { * Save the new custom block. */ function block_add_block_form_submit($form, &$form_state) { - $delta = db_next_id('{boxes}_bid'); + db_query("INSERT INTO {boxes} (body, info, format) VALUES ('%s', '%s', %d)", $form_state['values']['body'], $form_state['values']['info'], $form_state['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($form, &$form_state) { db_query("INSERT INTO {blocks_roles} (rid, module, delta) VALUES (%d, '%s', '%s')", $rid, $form_state['values']['module'], $delta); } - db_query("INSERT INTO {boxes} (bid, body, info, format) VALUES (%d, '%s', '%s', %d)", $delta, $form_state['values']['body'], $form_state['values']['info'], $form_state['values']['format']); - drupal_set_message(t('The block has been created.')); cache_clear_all(); diff --git a/modules/comment/comment.module b/modules/comment/comment.module index 7654be15b..5fa5f4e6c 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -805,7 +805,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 @@ -813,7 +812,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']); diff --git a/modules/drupal/drupal.module b/modules/drupal/drupal.module index 67d526d5e..3a99fa42d 100644 --- a/modules/drupal/drupal.module +++ b/modules/drupal/drupal.module @@ -196,8 +196,8 @@ function drupal_client_ping($client, $system) { 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']); diff --git a/modules/node/node.module b/modules/node/node.module index eb8f6c513..14cddb13a 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -621,9 +621,6 @@ function node_save(&$node) { if (empty($node->nid)) { // Insert a new node. $node->is_new = TRUE; - - $node->nid = db_next_id('{node}_nid'); - $node->vid = db_next_id('{node_revisions}_vid'); } else { // We need to ensure that all node fields are filled. @@ -635,7 +632,6 @@ function node_save(&$node) { if (!empty($node->revision)) { $node->old_vid = $node->vid; - $node->vid = db_next_id('{node_revisions}_vid'); } } @@ -647,11 +643,11 @@ function node_save(&$node) { $node->changed = time(); // Split off revisions data to another structure - $revisions_table_values = array('nid' => $node->nid, 'vid' => $node->vid, + $revisions_table_values = array('nid' => &$node->nid, 'title' => $node->title, 'body' => $node->body, 'teaser' => $node->teaser, 'timestamp' => $node->changed, 'uid' => $user->uid, 'format' => $node->format); - $revisions_table_types = array('nid' => '%d', 'vid' => '%d', + $revisions_table_types = array('nid' => '%d', 'title' => "'%s'", 'body' => "'%s'", 'teaser' => "'%s'", 'timestamp' => '%d', 'uid' => '%d', 'format' => '%d'); @@ -662,22 +658,27 @@ function node_save(&$node) { $revisions_table_values['log'] = $node->log; $revisions_table_types['log'] = "'%s'"; } - $node_table_values = array('nid' => $node->nid, 'vid' => $node->vid, + $node_table_values = array( 'title' => $node->title, 'type' => $node->type, 'uid' => $node->uid, 'status' => $node->status, 'language' => $node->language, 'created' => $node->created, 'changed' => $node->changed, 'comment' => $node->comment, 'promote' => $node->promote, 'sticky' => $node->sticky); - $node_table_types = array('nid' => '%d', 'vid' => '%d', + $node_table_types = array( 'title' => "'%s'", 'type' => "'%s'", 'uid' => '%d', 'status' => '%d', 'language' => "'%s'",'created' => '%d', 'changed' => '%d', 'comment' => '%d', 'promote' => '%d', 'sticky' => '%d'); - + $update_node = TRUE; //Generate the node table query and the //the node_revisions table query if ($node->is_new) { - $node_query = 'INSERT INTO {node} ('. implode(', ', array_keys($node_table_types)) .') VALUES ('. implode(', ', $node_table_types) .')'; + $node_query = 'INSERT INTO {node} (vid, '. implode(', ', array_keys($node_table_types)) .') VALUES (NULL, '. implode(', ', $node_table_types) .')'; + db_query($node_query, $node_table_values); + $node->nid = db_last_insert_id('node', 'nid'); $revisions_query = 'INSERT INTO {node_revisions} ('. implode(', ', array_keys($revisions_table_types)) .') VALUES ('. implode(', ', $revisions_table_types) .')'; + db_query($revisions_query, $revisions_table_values); + $node->vid = db_last_insert_id('node_revisions', 'vid'); + $op = 'insert'; } else { $arr = array(); @@ -686,8 +687,11 @@ function node_save(&$node) { } $node_table_values[] = $node->nid; $node_query = 'UPDATE {node} SET '. implode(', ', $arr) .' WHERE nid = %d'; + db_query($node_query, $node_table_values); if (!empty($node->revision)) { $revisions_query = 'INSERT INTO {node_revisions} ('. implode(', ', array_keys($revisions_table_types)) .') VALUES ('. implode(', ', $revisions_table_types) .')'; + db_query($revisions_query, $revisions_table_values); + $node->vid = db_last_insert_id('node_revisions', 'vid'); } else { $arr = array(); @@ -696,23 +700,19 @@ function node_save(&$node) { } $revisions_table_values[] = $node->vid; $revisions_query = 'UPDATE {node_revisions} SET '. implode(', ', $arr) .' WHERE vid = %d'; + db_query($revisions_query, $revisions_table_values); + $update_node = FALSE; } + $op = 'update'; } - - // Insert the node into the database: - db_query($node_query, $node_table_values); - db_query($revisions_query, $revisions_table_values); - - // Call the node specific callback (if any): - if ($node->is_new) { - node_invoke($node, 'insert'); - node_invoke_nodeapi($node, 'insert'); - } - else { - node_invoke($node, 'update'); - node_invoke_nodeapi($node, 'update'); + if ($update_node) { + db_query('UPDATE node SET vid = %d WHERE nid = %d', $node->vid, $node->nid); } + // Call the node specific callback (if any): + node_invoke($node, $op); + node_invoke_nodeapi($node, $op); + // Update the node access table for this node. node_access_acquire_grants($node); diff --git a/modules/node/node.schema b/modules/node/node.schema index 812ef9508..69a8981a8 100644 --- a/modules/node/node.schema +++ b/modules/node/node.schema @@ -5,7 +5,7 @@ function node_schema() { $schema['node'] = array( 'fields' => array( 'nid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), - 'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => 0), 'type' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''), 'language' => array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => ''), 'title' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''), @@ -65,7 +65,7 @@ function node_schema() { $schema['node_revisions'] = array( 'fields' => array( - 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE), + 'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), 'vid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), 'uid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), 'title' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''), diff --git a/modules/system/system.install b/modules/system/system.install index 96d64bfab..e36f34f14 100644 --- a/modules/system/system.install +++ b/modules/system/system.install @@ -3339,6 +3339,16 @@ function system_update_6022() { return $ret; } + +function system_update_6023() { + $ret = array(); + // vid is NULL + db_change_field($ret, 'node', 'vid'); + // nid is DEFAULT 0 + db_change_field($ret, 'node_revisions', 'nid'); + return $ret; +} + /** * @} End of "defgroup updates-5.x-to-6.x" * The next series of updates should start at 7000. diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module index c04750ecd..1bff59ebc 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -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_values) { 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; } diff --git a/modules/user/user.module b/modules/user/user.module index abfeafdc9..741af7e0e 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -210,8 +210,6 @@ function user_save($account, $array = array(), $category = 'account') { 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 = array(), $category = 'account') { $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 = array(), $category = 'account') { } } 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'])); @@ -1789,8 +1788,8 @@ function user_admin_access_add($mask = NULL, $type = NULL) { form_set_error('mask', t('You must enter a mask.')); } else { - $aid = db_next_id('{access}_aid'); db_query("INSERT INTO {access} (aid, mask, type, status) VALUES ('%s', '%s', '%s', %d)", $aid, $edit['mask'], $edit['type'], $edit['status']); + $aid = db_last_insert_id('access', 'aid'); drupal_set_message(t('The access rule has been added.')); drupal_goto('admin/user/rules'); } |