=== modified file 'includes/database/database.inc' --- includes/database/database.inc 2008-10-25 02:03:54 +0000 +++ includes/database/database.inc 2008-10-25 04:42:01 +0000 @@ -638,7 +638,7 @@ abstract class DatabaseConnection extend * A database query result resource, or FALSE if the query was not executed * correctly. */ - abstract function queryTemporary($query, Array $args, $tablename, $options = array()); + abstract function queryTemporary($query, Array $args, $tablename, Array $options = array()); /** * Returns the type of database driver. === modified file 'includes/database/mysql/database.inc' --- includes/database/mysql/database.inc 2008-10-25 02:03:54 +0000 +++ includes/database/mysql/database.inc 2008-10-25 04:43:50 +0000 @@ -46,7 +46,7 @@ class DatabaseConnection_mysql extends D return $this->query($query . ' LIMIT ' . $from . ', ' . $count, $args, $options); } - public function queryTemporary($query, Array $args, $tablename, $options = array()) { + public function queryTemporary($query, Array $args, $tablename, Array $options = array()) { $query = preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE ' . $tablename . ' Engine=HEAP SELECT', $this->prefixTables($query)); return $this->query($query, $args, $options); === modified file 'includes/database/pgsql/database.inc' --- includes/database/pgsql/database.inc 2008-10-25 02:12:35 +0000 +++ includes/database/pgsql/database.inc 2008-10-25 04:43:45 +0000 @@ -82,7 +82,7 @@ class DatabaseConnection_pgsql extends D return $this->query($query . ' LIMIT ' . $count . ' OFFSET ' . $from, $args, $options); } - public function queryTemporary($query, Array $args, $tablename, $options = array()) { + public function queryTemporary($query, Array $args, $tablename, Array $options = array()) { $query = preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE ' . $tablename . ' Engine=HEAP SELECT', $this->prefixTables($query)); return $this->query($query, $args, $options); === modified file 'modules/simpletest/tests/database_test.module' --- modules/simpletest/tests/database_test.module 2008-09-15 20:48:06 +0000 +++ modules/simpletest/tests/database_test.module 2008-10-25 05:01:59 +0000 @@ -35,3 +35,24 @@ function database_test_query_alter(Selec $expressions['double_age']['expression'] = 'age*3'; } } + +function database_test_menu() { + $items['database_test'] = array( + 'access callback' => TRUE, + 'page callback' => 'database_test_page', + ); + return $items; +} + +/** + * Run a db_temporary_query and print the number of rows in the resulting table. + * + * We need to test that the table created is temporary, so we run it here, in a + * separate request -- after this request is done, the table is automatically + * dropped. + */ +function database_test_page() { + db_query_temporary('SELECT status FROM {system}', array(), 'temporary'); + print db_query('SELECT COUNT(*) FROM temporary')->fetchField(); + exit; +} === modified file 'modules/simpletest/tests/database_test.test' --- modules/simpletest/tests/database_test.test 2008-10-22 04:01:03 +0000 +++ modules/simpletest/tests/database_test.test 2008-10-25 05:04:01 +0000 @@ -1837,3 +1837,39 @@ class DatabaseLoggingTestCase extends Da } } } + +/** + * Test that db_query_temporary creates a temporary table. + * + */ +class DatabaseTestQueryTemporaryCase extends DrupalWebTestCase { + + /** + * Define metadata for this test subclass. + */ + function getInfo() { + return array( + 'name' => t('Temporary table test.'), + 'description' => t('Tests the queryTemporary functionality.'), + 'group' => t('Database'), + ); + } + + /** + * Implementation of setUp(). + */ + function setUp() { + parent::setUp('database_test'); + } + + /** + * Get a db_temporary_query query ran and get back the number of rows in the + * resulting table. + */ + function testQueryTemporary() { + $this->drupalGet('database_test'); + $this->pass($this->_content); + $this->assertEqual(db_query('SELECT COUNT(*) FROM {system}')->fetchField(), $this->_content, t('The temporary table exists and contains the correct amount of rowws')); + $this->assertFalse(db_table_exists('temporary'), t('The temporary table is, indeed, temporary')); + } +}