Commit 742410aa authored by Dries's avatar Dries

- Bugfix: prefix not prepended to sequences.  Fixes bug #3639.

  Make sure to write:

    db_next_id({table}_field);

  instead of:

    db_next_id(table_field);
parent 90e5e355
......@@ -126,6 +126,7 @@ function db_next_id($name) {
** when needed
*/
$name = db_prefix_tables($name);
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);
......
......@@ -127,6 +127,7 @@ function db_error() {
function db_next_id($name) {
global $db_handle;
$name = db_prefix_tables($name);
$result = $db_handle->nextID($name);
if (DB::isError($result)) {
watchdog("error", "database: ". $result->getMessage() ."\nsequence table: $name");
......
......@@ -453,7 +453,7 @@ function import_save_bundle($edit) {
}
else if ($edit["title"]) {
// a single unique id for bundles and feeds, to use in blocks
$next_id = db_next_id("bundle_bid");
$next_id = db_next_id("{bundle}_bid");
db_query("INSERT INTO {bundle} (bid, title, attributes) VALUES (%d, '%s', '%s')", $next_id, $edit["title"], $edit["attributes"]);
}
}
......@@ -492,7 +492,7 @@ function import_save_feed($edit) {
}
else if ($edit["title"]) {
// a single unique id for bundles and feeds, to use in blocks
$next_id = db_next_id("feed_fid");
$next_id = db_next_id("{feed}_fid");
db_query("INSERT INTO {feed} (fid, title, url, attributes, refresh) VALUES (%d, '%s', '%s', '%s', %d)", $next_id, $edit["title"], $edit["url"], $edit["attributes"], $edit["refresh"]);
}
}
......
......@@ -453,7 +453,7 @@ function import_save_bundle($edit) {
}
else if ($edit["title"]) {
// a single unique id for bundles and feeds, to use in blocks
$next_id = db_next_id("bundle_bid");
$next_id = db_next_id("{bundle}_bid");
db_query("INSERT INTO {bundle} (bid, title, attributes) VALUES (%d, '%s', '%s')", $next_id, $edit["title"], $edit["attributes"]);
}
}
......@@ -492,7 +492,7 @@ function import_save_feed($edit) {
}
else if ($edit["title"]) {
// a single unique id for bundles and feeds, to use in blocks
$next_id = db_next_id("feed_fid");
$next_id = db_next_id("{feed}_fid");
db_query("INSERT INTO {feed} (fid, title, url, attributes, refresh) VALUES (%d, '%s', '%s', '%s', %d)", $next_id, $edit["title"], $edit["url"], $edit["attributes"], $edit["refresh"]);
}
}
......
......@@ -452,7 +452,7 @@ function comment_post($edit) {
}
$edit["cid"] = db_next_id("comments_cid");
$edit["cid"] = db_next_id("{comments}_cid");
db_query("INSERT INTO {comments} (cid, nid, pid, uid, subject, comment, hostname, timestamp, status, score, users, thread) VALUES (%d, %d, %d, %d, '%s', '%s', '%s', %d, %d, %d, '%s', '%s')", $edit["cid"], $edit["nid"], $edit["pid"], $user->uid, $edit["subject"], $edit["comment"], getenv("REMOTE_ADDR"), time(), $status, $score, $users, $thread);
......
......@@ -452,7 +452,7 @@ function comment_post($edit) {
}
$edit["cid"] = db_next_id("comments_cid");
$edit["cid"] = db_next_id("{comments}_cid");
db_query("INSERT INTO {comments} (cid, nid, pid, uid, subject, comment, hostname, timestamp, status, score, users, thread) VALUES (%d, %d, %d, %d, '%s', '%s', '%s', %d, %d, %d, '%s', '%s')", $edit["cid"], $edit["nid"], $edit["pid"], $user->uid, $edit["subject"], $edit["comment"], getenv("REMOTE_ADDR"), time(), $status, $score, $users, $thread);
......
......@@ -453,7 +453,7 @@ function import_save_bundle($edit) {
}
else if ($edit["title"]) {
// a single unique id for bundles and feeds, to use in blocks
$next_id = db_next_id("bundle_bid");
$next_id = db_next_id("{bundle}_bid");
db_query("INSERT INTO {bundle} (bid, title, attributes) VALUES (%d, '%s', '%s')", $next_id, $edit["title"], $edit["attributes"]);
}
}
......@@ -492,7 +492,7 @@ function import_save_feed($edit) {
}
else if ($edit["title"]) {
// a single unique id for bundles and feeds, to use in blocks
$next_id = db_next_id("feed_fid");
$next_id = db_next_id("{feed}_fid");
db_query("INSERT INTO {feed} (fid, title, url, attributes, refresh) VALUES (%d, '%s', '%s', '%s', %d)", $next_id, $edit["title"], $edit["url"], $edit["attributes"], $edit["refresh"]);
}
}
......
......@@ -317,7 +317,7 @@ function node_save($node) {
$node->created = time();
}
$node->changed = time();
$node->nid = db_next_id("node_nid");
$node->nid = db_next_id("{node}_nid");
// Prepare the query:
foreach ($node as $key => $value) {
......
......@@ -317,7 +317,7 @@ function node_save($node) {
$node->created = time();
}
$node->changed = time();
$node->nid = db_next_id("node_nid");
$node->nid = db_next_id("{node}_nid");
// Prepare the query:
foreach ($node as $key => $value) {
......
......@@ -101,7 +101,7 @@ function taxonomy_save_vocabulary($edit) {
$message = taxonomy_del_vocabulary($edit["vid"]);
}
else {
$data["vid"] = $edit["vid"] = db_next_id("vocabulary_vid");
$data["vid"] = $edit["vid"] = db_next_id("{vocabulary}_vid");
db_query("INSERT INTO {vocabulary} ". _prepare_insert($data, 1) ." VALUES ". _prepare_insert($data, 2));
module_invoke_all("taxonomy", "insert", "vocabulary", $edit);
$message = t("created new vocabulary '%name'.", array("%name" => $edit["name"]));
......@@ -194,7 +194,7 @@ function taxonomy_save_term($edit) {
return taxonomy_del_term($edit["tid"]);
}
else {
$edit["tid"] = db_next_id("term_data_tid");
$edit["tid"] = db_next_id("{term_data}_tid");
$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));
module_invoke_all("taxonomy", "insert", "term", $edit);
......
......@@ -101,7 +101,7 @@ function taxonomy_save_vocabulary($edit) {
$message = taxonomy_del_vocabulary($edit["vid"]);
}
else {
$data["vid"] = $edit["vid"] = db_next_id("vocabulary_vid");
$data["vid"] = $edit["vid"] = db_next_id("{vocabulary}_vid");
db_query("INSERT INTO {vocabulary} ". _prepare_insert($data, 1) ." VALUES ". _prepare_insert($data, 2));
module_invoke_all("taxonomy", "insert", "vocabulary", $edit);
$message = t("created new vocabulary '%name'.", array("%name" => $edit["name"]));
......@@ -194,7 +194,7 @@ function taxonomy_save_term($edit) {
return taxonomy_del_term($edit["tid"]);
}
else {
$edit["tid"] = db_next_id("term_data_tid");
$edit["tid"] = db_next_id("{term_data}_tid");
$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));
module_invoke_all("taxonomy", "insert", "term", $edit);
......
......@@ -141,7 +141,7 @@ function user_save($account, $array = array()) {
}
else {
$array["timestamp"] = time();
$array["uid"] = db_next_id("users_uid");
$array["uid"] = db_next_id("{users}_uid");
foreach ($array as $key => $value) {
if ($key == "pass") {
......@@ -1296,7 +1296,7 @@ function user_admin_access($edit = array()) {
}
if ($op == t("Add rule")) {
$aid = db_next_id("access_aid");
$aid = db_next_id("{access}_aid");
db_query("INSERT INTO {access} (aid, mask, type, status) VALUES ('%s', '%s', '%s', %d)", $aid, $edit["mask"], $type, $edit["status"]);
$output .= status(t("access rule added."));
}
......
......@@ -141,7 +141,7 @@ function user_save($account, $array = array()) {
}
else {
$array["timestamp"] = time();
$array["uid"] = db_next_id("users_uid");
$array["uid"] = db_next_id("{users}_uid");
foreach ($array as $key => $value) {
if ($key == "pass") {
......@@ -1296,7 +1296,7 @@ function user_admin_access($edit = array()) {
}
if ($op == t("Add rule")) {
$aid = db_next_id("access_aid");
$aid = db_next_id("{access}_aid");
db_query("INSERT INTO {access} (aid, mask, type, status) VALUES ('%s', '%s', '%s', %d)", $aid, $edit["mask"], $type, $edit["status"]);
$output .= status(t("access rule added."));
}
......
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