diff -urpN ../drupal-5.2.orig/./includes/common.inc ./includes/common.inc --- ../drupal-5.2.orig/./includes/common.inc 2007-09-27 11:14:40.000000000 +0200 +++ ./includes/common.inc 2007-09-27 12:20:45.000000000 +0200 @@ -2015,6 +2015,18 @@ function drupal_cron_run() { // Lock cron semaphore variable_set('cron_semaphore', time()); + // Delete temporary tables + //echo "Deleting Temporary Tables"; + $deltime=time()-(15*60); + //print "SELECT ttable FROM temporary_table WHERE creationdate < %d ($deltime)"; + $result = db_query("SELECT ttable FROM {temporary_table} WHERE creationdate < %d", $deltime); + while ($temptable = db_fetch_object($result)) { + //print 'DROP TABLE '.$temptable->ttable; + db_query('DROP TABLE '.$temptable->ttable); + } + //print "DELETE FROM temporary_table WHERE creationdate < %d ($deltime)"; + db_query('DELETE FROM {temporary_table} WHERE creationdate < %d', $deltime); + // Iterate through the modules calling their cron handlers (if any): module_invoke_all('cron'); diff -urpN ../drupal-5.2.orig/./includes/database.mysqli.inc ./includes/database.mysqli.inc --- ../drupal-5.2.orig/./includes/database.mysqli.inc 2007-09-27 11:14:40.000000000 +0200 +++ ./includes/database.mysqli.inc 2007-09-27 15:03:37.000000000 +0200 @@ -338,13 +338,26 @@ function db_query_temporary($query) { $tablename = array_pop($args); array_shift($args); - $query = preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE '. $tablename .' SELECT', db_prefix_tables($query)); + // Check if table exist + $result=db_query("SHOW TABLES LIKE '$tablename'"); + if(db_fetch_object($result)) { + // It does exist: Remove it + db_query("DROP TABLE $tablename"); + db_query("DELETE FROM {temporary_table} where ttable like '$tablename'"); + } + + $query = preg_replace('/^SELECT/i', 'CREATE TABLE '. $tablename .' SELECT', db_prefix_tables($query)); if (isset($args[0]) and is_array($args[0])) { // 'All arguments in one array' syntax $args = $args[0]; } _db_query_callback($args, TRUE); $query = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $query); - return _db_query($query); + $ret=_db_query($query); + + // Insert into tt-table + db_query("INSERT INTO {temporary_table} (ttable, creationdate) VALUES ('%s', %d)", $tablename, time()); + + return $ret; } /** diff -urpN ../drupal-5.2.orig/./includes/database.mysql.inc ./includes/database.mysql.inc --- ../drupal-5.2.orig/./includes/database.mysql.inc 2007-09-27 11:14:40.000000000 +0200 +++ ./includes/database.mysql.inc 2007-09-27 15:03:42.000000000 +0200 @@ -358,13 +358,26 @@ function db_query_temporary($query) { $tablename = array_pop($args); array_shift($args); - $query = preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE '. $tablename .' SELECT', db_prefix_tables($query)); + // Check if table exist + $result=db_query("SHOW TABLES LIKE '$tablename'"); + if(db_fetch_object($result)) { + // It does exist: Remove it + db_query("DROP TABLE $tablename"); + db_query("DELETE FROM {temporary_table} where ttable like '$tablename'"); + } + + $query = preg_replace('/^SELECT/i', 'CREATE TABLE '. $tablename .' SELECT', db_prefix_tables($query)); if (isset($args[0]) and is_array($args[0])) { // 'All arguments in one array' syntax $args = $args[0]; } _db_query_callback($args, TRUE); $query = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $query); - return _db_query($query); + $ret=_db_query($query); + + // Insert into tt-table + db_query("INSERT INTO {temporary_table} (ttable, creationdate) VALUES ('%s', %d)", $tablename, time()); + + return $ret; } /** diff -urpN ../drupal-5.2.orig/./modules/system/system.install ./modules/system/system.install --- ../drupal-5.2.orig/./modules/system/system.install 2007-09-27 11:14:40.000000000 +0200 +++ ./modules/system/system.install 2007-09-27 11:27:55.000000000 +0200 @@ -154,6 +154,12 @@ function system_install() { switch ($GLOBALS['db_type']) { case 'mysql': case 'mysqli': + db_query("CREATE TABLE {temporary_table} ( + aid int NOT NULL auto_increment, + ttable varchar(255) NOT NULL default '', + creationdate int NOT NULL default '0', + PRIMARY KEY (aid) + ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); db_query("CREATE TABLE {access} ( aid int NOT NULL auto_increment, mask varchar(255) NOT NULL default '',