diff -ur drupal-4.7.4/includes/bootstrap.inc drupal-4.7.4-patched/includes/bootstrap.inc --- drupal-4.7.4/includes/bootstrap.inc 2006-08-03 14:53:15.000000000 +0100 +++ drupal-4.7.4-patched/includes/bootstrap.inc 2006-12-19 00:08:32.000000000 +0000 @@ -281,10 +281,11 @@ 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(); +// From chx's patch http://drupal.org/node/55516 http://drupal.org/files/issues/no_block.patch.txt + db_query_replace( + array("DELETE FROM {variable} WHERE name = '%s'", $name), + array("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", $name, serialize($value)) + ); cache_clear_all('variables'); @@ -368,12 +369,11 @@ * A string containing HTTP header information for cached pages. */ function cache_set($cid, $data, $expire = CACHE_PERMANENT, $headers = NULL) { - db_lock_table('cache'); - db_query("UPDATE {cache} SET data = %b, created = %d, expire = %d, headers = '%s' WHERE cid = '%s'", $data, time(), $expire, $headers, $cid); - if (!db_affected_rows()) { - @db_query("INSERT INTO {cache} (cid, data, created, expire, headers) VALUES ('%s', %b, %d, %d, '%s')", $cid, $data, time(), $expire, $headers); - } - db_unlock_tables(); +// From chx's patch http://drupal.org/node/55516 http://drupal.org/files/issues/no_block.patch.txt + db_query_replace( + array("DELETE FROM {%s} WHERE cid = '%s'", $table, $cid), + array("INSERT INTO {%s} (cid, data, created, expire, headers) VALUES ('%s', %b, %d, %d, '%s')", $table, $cid, $data, time(), $expire, $headers) + ); } /** diff -ur drupal-4.7.4/includes/database.mysql.inc drupal-4.7.4-patched/includes/database.mysql.inc --- drupal-4.7.4/includes/database.mysql.inc 2006-09-26 15:14:33.000000000 +0100 +++ drupal-4.7.4-patched/includes/database.mysql.inc 2006-12-19 01:14:53.000000000 +0000 @@ -196,21 +196,26 @@ } /** - * 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. +// From chx's patch http://drupal.org/node/55516 http://drupal.org/files/issues/no_block.patch.txt + * Return a new unique ID. */ function db_next_id($name) { - $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'); - - return $id; + // Prefix any curly-bracket "{table}" names + $name = db_prefix_tables($name); + // Assume initially that the sequence already exists. Attempt to update it atomically. + // LAST_INSERT_ID lets us get its value later. IGNORE suppresses update failures. + db_query("UPDATE IGNORE {sequences} SET id=LAST_INSERT_ID(id + 1) WHERE name = '%s'", $name); + // Check whether that worked + if (!db_affected_rows()) { + // Updated failed, so the sequence doesn't exist yet. + // In either case, try to create a new sequence starting from zero + // IGNORE suppresses insert error if e.g. a concurrent process got there first. + db_query("INSERT IGNORE INTO {sequences} VALUES ('%s', %d)", $name, 0); + // Sequence now exists (unless some database error occurred to prevent it) + // Retry update, allowing for possible concurrent process. It should work this time. + db_query("UPDATE {sequences} SET id = LAST_INSERT_ID(id + 1) WHERE name = '%s'", $name); + } + return mysql_insert_id(); } /** @@ -308,7 +313,13 @@ $tablename = array_pop($args); array_shift($args); - $query = preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE '. $tablename .' SELECT', db_prefix_tables($query)); +// $user->sid is part of niosop's +// remove TEMPORARY TABLE patch at +// http://drupal.org/node/49644#comment-111742 + global $user; + + db_query("DROP TABLE IF EXISTS ".$tablename.$user->sid); + $query = preg_replace('/^SELECT/i', 'CREATE TABLE '.$tablename . $user->sid.' SELECT', db_prefix_tables($query)); if (isset($args[0]) and is_array($args[0])) { // 'All arguments in one array' syntax $args = $args[0]; } @@ -364,6 +375,22 @@ db_query('UNLOCK TABLES'); } +// From chx's patch http://drupal.org/node/55516 http://drupal.org/files/issues/no_block.patch.txt +/** + * Perform a replace query. + * + * @param $delete + * An array, where the first value is a query which deletes one row, + * subsequent values are arguments. Same syntax as of db_query. + * @param + * An array, where the first value is a query which inserts the new row, + * subsequent values are arguments. Same syntax as of db_query. + */ +function db_query_replace($delete, $insert) { + $insert_query = array_shift($insert); + db_query(preg_replace('/^INSERT /', 'REPLACE ', $insert_query), $insert); +} + /** * @} End of "ingroup database". */ Only in drupal-4.7.4-patched/includes: database.mysql.inc~ diff -ur drupal-4.7.4/modules/search.module drupal-4.7.4-patched/modules/search.module --- drupal-4.7.4/modules/search.module 2006-08-05 15:36:41.000000000 +0100 +++ drupal-4.7.4-patched/modules/search.module 2006-12-19 00:44:31.000000000 +0000 @@ -832,6 +832,10 @@ * @ingroup search */ function do_search($keywords, $type, $join1 = '', $where1 = '1', $arguments1 = array(), $select2 = 'i.relevance AS score', $join2 = '', $arguments2 = array(), $sort_parameters = 'ORDER BY score DESC') { +// $user->sid is part of niosop's +// remove TEMPORARY TABLE patch at +// http://drupal.org/node/49644#comment-111742 + global $user; $query = search_parse_query($keywords); if ($query[2] == '') { @@ -848,7 +852,7 @@ $result = db_query_temporary("SELECT i.type, i.sid, SUM(i.score * t.count) AS relevance, COUNT(*) AS matches FROM {search_index} i INNER JOIN {search_total} t ON i.word = t.word $join1 WHERE $conditions GROUP BY i.type, i.sid HAVING COUNT(*) >= %d", $arguments, 'temp_search_sids'); // Calculate maximum relevance, to normalize it - $normalize = db_result(db_query('SELECT MAX(relevance) FROM temp_search_sids')); + $normalize = db_result(db_query('SELECT MAX(relevance) FROM temp_search_sids'.$user->sid)); if (!$normalize) { return array(); } @@ -857,18 +861,22 @@ // Second pass: only keep items that match the complicated keywords conditions (phrase search, negative keywords, ...) $conditions = '('. $query[0] .')'; $arguments = array_merge($arguments2, $query[1]); - $result = db_query_temporary("SELECT i.type, i.sid, $select2 FROM temp_search_sids i INNER JOIN {search_dataset} d ON i.sid = d.sid AND i.type = d.type $join2 WHERE $conditions $sort_parameters", $arguments, 'temp_search_results'); - if (($count = db_result(db_query('SELECT COUNT(*) FROM temp_search_results'))) == 0) { + $result = db_query_temporary("SELECT i.type, i.sid, $select2 FROM temp_search_sids".$user->sid." i INNER JOIN {search_dataset} d ON i.sid = d.sid AND i.type = d.type $join2 WHERE $conditions $sort_parameters", $arguments, 'temp_search_results'); + if (($count = db_result(db_query('SELECT COUNT(*) FROM temp_search_results'.$user->sid))) == 0) { + db_query('DROP TABLE temp_search_results'.$user->sid); + db_query('DROP TABLE temp_search_sids'.$user->sid); return array(); } $count_query = "SELECT $count"; // Do actual search query - $result = pager_query("SELECT * FROM temp_search_results", 10, 0, $count_query); + $result = pager_query("SELECT * FROM temp_search_results".$user->sid, 10, 0, $count_query); $results = array(); while ($item = db_fetch_object($result)) { $results[] = $item; } + db_query('DROP TABLE temp_search_results'.$user->sid); + db_query('DROP TABLE temp_search_sids'.$user->sid); return $results; }