- Applied a (modified) version of Marco's SQL sequence patch.

4.1.x
Dries Buytaert 2002-08-20 19:29:16 +00:00
parent afd87425d9
commit bfe5b85dbd
8 changed files with 58 additions and 40 deletions

View File

@ -93,18 +93,6 @@ CREATE TABLE cache (
PRIMARY KEY (cid)
) TYPE=MyISAM;
#
# Table structure for table 'collection'
#
CREATE TABLE collection (
cid int(10) unsigned NOT NULL auto_increment,
name varchar(32) NOT NULL default '',
types varchar(128) NOT NULL default '',
PRIMARY KEY (cid),
UNIQUE KEY name (name)
) TYPE=MyISAM;
#
# Table structure for table 'comments'
#
@ -385,19 +373,14 @@ CREATE TABLE system (
description varchar(255) NOT NULL default '',
status int(2) NOT NULL default '0',
PRIMARY KEY (filename)
) TYPE=MyISAM;
#
# Table structure for table 'tag'
# Table structure for table 'sequences'
#
CREATE TABLE tag (
tid int(10) unsigned NOT NULL auto_increment,
name varchar(32) NOT NULL default '',
attributes varchar(255) NOT NULL default '',
collections varchar(32) NOT NULL default '',
PRIMARY KEY (tid),
UNIQUE KEY name (name,collections)
CREATE TABLE sequences (
name VARCHAR(255) NOT NULL PRIMARY KEY,
id INT UNSIGNED NOT NULL
) TYPE=MyISAM;
#

View File

@ -93,4 +93,19 @@ function db_error() {
return mysql_errno();
}
function db_next_id($name) {
/*
** Note that REPLACE query below correctly creates a new sequence
** when needed
*/
db_query("LOCK TABLES sequences WRITE");
$id = db_result(db_query("SELECT id FROM sequences WHERE name = '%s'", $name)) + 1;
db_query("REPLACE INTO sequences VALUES ('%s', '%d')", $name, $id);
db_query("UNLOCK TABLES");
return $id;
}
?>

View File

@ -100,4 +100,10 @@ function db_error($result) {
return DB::isError($db_handle);
}
function db_next_id($name) {
global $db_handle;
return $db_handle->nextID($name);
}
?>

View File

@ -149,8 +149,7 @@ function node_save($node, $filter) {
// Set some required fields:
$node->created = time();
$node->changed = time();
$node->nid = db_result(db_query("SELECT MAX(nid) + 1 FROM node"));
$node->nid = empty($node->nid) ? 1 : $node->nid;
$node->nid = db_next_id("node");
// Prepare the query:
foreach ($node as $key => $value) {
@ -1073,7 +1072,7 @@ function node_submit($node) {
else {
$fields = array("nid", "uid" => ($user->uid ? $user->uid : 0), "body", "teaser", "title", "type" => $node->type);
}
$nid = node_save($node, array_merge($fields, module_invoke($node->type, "save", "update", $node)));
/*
@ -1120,7 +1119,7 @@ function node_submit($node) {
else {
$fields = array("uid" => ($user->uid ? $user->uid : 0), "body", "comment" => 2, "teaser", "title", "type" => $node->type);
}
$nid = node_save($node, array_merge($fields, module_invoke($node->type, "save", "create", $node)));
/*

View File

@ -149,8 +149,7 @@ function node_save($node, $filter) {
// Set some required fields:
$node->created = time();
$node->changed = time();
$node->nid = db_result(db_query("SELECT MAX(nid) + 1 FROM node"));
$node->nid = empty($node->nid) ? 1 : $node->nid;
$node->nid = db_next_id("node");
// Prepare the query:
foreach ($node as $key => $value) {
@ -1073,7 +1072,7 @@ function node_submit($node) {
else {
$fields = array("nid", "uid" => ($user->uid ? $user->uid : 0), "body", "teaser", "title", "type" => $node->type);
}
$nid = node_save($node, array_merge($fields, module_invoke($node->type, "save", "update", $node)));
/*
@ -1120,7 +1119,7 @@ function node_submit($node) {
else {
$fields = array("uid" => ($user->uid ? $user->uid : 0), "body", "comment" => 2, "teaser", "title", "type" => $node->type);
}
$nid = node_save($node, array_merge($fields, module_invoke($node->type, "save", "create", $node)));
/*

View File

@ -153,11 +153,7 @@ function taxonomy_save_term($edit) {
taxonomy_del_term($edit["tid"]);
}
else {
$edit["tid"] = db_result(db_query("SELECT MAX(tid) + 1 FROM term_data"));
if (!$edit["tid"]) {
// first term
$edit["tid"] = 1;
}
$edit["tid"] = db_next_id("term_data");
$data = array("tid" => $edit["tid"], "name" => $edit["name"], "description" => $edit["description"], "vid" => $edit["vid"], "weight" => $edit["weight"]);
db_query("INSERT INTO term_data ". _prepare_insert($data, 1) ." VALUES ". _prepare_insert($data, 2));
}

View File

@ -153,11 +153,7 @@ function taxonomy_save_term($edit) {
taxonomy_del_term($edit["tid"]);
}
else {
$edit["tid"] = db_result(db_query("SELECT MAX(tid) + 1 FROM term_data"));
if (!$edit["tid"]) {
// first term
$edit["tid"] = 1;
}
$edit["tid"] = db_next_id("term_data");
$data = array("tid" => $edit["tid"], "name" => $edit["name"], "description" => $edit["description"], "vid" => $edit["vid"], "weight" => $edit["weight"]);
db_query("INSERT INTO term_data ". _prepare_insert($data, 1) ." VALUES ". _prepare_insert($data, 2));
}

View File

@ -48,7 +48,8 @@ $mysql_updates = array(
"2002-07-07" => "update_33",
"2002-07-31" => "update_34",
"2002-08-10" => "update_35",
"2002-08-16" => "update_36"
"2002-08-16" => "update_36",
"2002-08-19" => "update_37"
);
// Update functions
@ -508,6 +509,29 @@ function update_36() {
update_sql("ALTER TABLE rating CHANGE new current int(6) NOT NULL default '0';");
}
function update_37() {
update_sql("DROP TABLE IF EXISTS sequences;");
update_sql("CREATE TABLE sequences (
name VARCHAR(255) NOT NULL PRIMARY KEY,
id INT UNSIGNED NOT NULL
) TYPE=MyISAM;");
if ($max = db_result(db_query("SELECT MAX(nid) FROM node;"))) {
update_sql("REPLACE INTO sequences VALUES ('node', $max);");
}
if ($max = db_result(db_query("SELECT MAX(cid) FROM comments;"))) {
update_sql("REPLACE INTO sequences VALUES ('comments', $max);");
}
// NOTE: move the comments bit down as soon as we switched to use the new comment module!
if ($max = db_result(db_query("SELECT MAX(tid) FROM term_data;"))) {
update_sql("REPLACE INTO sequences VALUES ('term_data', $max);");
}
}
function update_upgrade3() {
update_sql("INSERT INTO system VALUES ('archive.module','archive','module','',1);");
update_sql("INSERT INTO system VALUES ('block.module','block','module','',1);");