diff options
Diffstat (limited to 'includes')
-rw-r--r-- | includes/bootstrap.inc | 9 | ||||
-rw-r--r-- | includes/cache.inc | 7 | ||||
-rw-r--r-- | includes/database.mysql.inc | 8 | ||||
-rw-r--r-- | includes/database.mysqli.inc | 8 |
4 files changed, 14 insertions, 18 deletions
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc index d3c35b5f2..a394a7c75 100644 --- a/includes/bootstrap.inc +++ b/includes/bootstrap.inc @@ -444,10 +444,11 @@ function variable_get($name, $default) { function variable_set($name, $value) { global $conf; - db_lock_table('variable'); - db_query("DELETE FROM {variable} WHERE name = '%s'", $name); - db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", $name, serialize($value)); - db_unlock_tables(); + $serialized_value = serialize($value); + db_query("UPDATE {variable} SET value = '%s' WHERE name = '%s'", $serialized_value, $name); + if (!db_affected_rows()) { + @db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", $name, $serialized_value); + } cache_clear_all('variables', 'cache'); diff --git a/includes/cache.inc b/includes/cache.inc index 992b3749d..9bf209044 100644 --- a/includes/cache.inc +++ b/includes/cache.inc @@ -104,12 +104,11 @@ function cache_set($cid, $data, $table = 'cache', $expire = CACHE_PERMANENT, $he $data = serialize($data); $serialized = 1; } - db_lock_table($table); - db_query("UPDATE {". $table ."} SET data = %b, created = %d, expire = %d, headers = '%s', serialized = %d WHERE cid = '%s'", $data, time(), $expire, $headers, $serialized, $cid); + $created = time(); + db_query("UPDATE {". $table ."} SET data = %b, created = %d, expire = %d, headers = '%s', serialized = %d WHERE cid = '%s'", $data, $created, $expire, $headers, $serialized, $cid); if (!db_affected_rows()) { - @db_query("INSERT INTO {". $table ."} (cid, data, created, expire, headers, serialized) VALUES ('%s', %b, %d, %d, '%s', %d)", $cid, $data, time(), $expire, $headers, $serialized); + @db_query("INSERT INTO {". $table ."} (cid, data, created, expire, headers, serialized) VALUES ('%s', %b, %d, %d, '%s', %d)", $cid, $data, $created, $expire, $headers, $serialized); } - db_unlock_tables(); } /** diff --git a/includes/database.mysql.inc b/includes/database.mysql.inc index 166017621..45426fff2 100644 --- a/includes/database.mysql.inc +++ b/includes/database.mysql.inc @@ -250,13 +250,11 @@ function db_error() { * 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('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'); + db_query('INSERT INTO {sequences} VALUES ("%s", LAST_INSERT_ID(1)) ON DUPLICATE KEY UPDATE id = LAST_INSERT_ID(id + 1)', $name); - return $id; + return mysql_insert_id($active_db); } /** diff --git a/includes/database.mysqli.inc b/includes/database.mysqli.inc index ad58a6f24..baac124de 100644 --- a/includes/database.mysqli.inc +++ b/includes/database.mysqli.inc @@ -242,13 +242,11 @@ function db_error() { * 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('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'); + db_query('INSERT INTO {sequences} VALUES ("%s", LAST_INSERT_ID(1)) ON DUPLICATE KEY UPDATE id = LAST_INSERT_ID(id + 1)', $name); - return $id; + return mysqli_insert_id($active_db); } /** |