summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rothstein <drothstein@gmail.com>2014-05-05 23:14:24 -0400
committerDavid Rothstein <drothstein@gmail.com>2014-05-05 23:14:24 -0400
commit20c04c587beb78094cdc1302f9c226af8931747c (patch)
tree7f5e9cd596b21fe2b42f4edf0cd607085416f32a
parent57bd9625f312ad4edea6b9fc45589b5be3a7933b (diff)
downloadbrdo-20c04c587beb78094cdc1302f9c226af8931747c.tar.gz
brdo-20c04c587beb78094cdc1302f9c226af8931747c.tar.bz2
Issue #1868972 by jweowu, DanChadwick: Db_query_temporary() fails to create a table when the SQL has leading whitespace.
-rw-r--r--CHANGELOG.txt4
-rw-r--r--includes/database/mysql/database.inc2
-rw-r--r--includes/database/pgsql/database.inc2
-rw-r--r--includes/database/sqlite/database.inc2
-rw-r--r--modules/simpletest/tests/database_test.test9
5 files changed, 16 insertions, 3 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index d4960de90..eb47606c9 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,6 +1,10 @@
Drupal 7.28, xxxx-xx-xx (development version)
-----------------------
+- Changed the behavior of db_query_temporary() so that it works on SELECT
+ queries even when they have leading comments/whitespace. A side effect of
+ this fix is that db_query_temporary() will now fail with an error if it is
+ ever used on non-SELECT queries.
- Added a "node_admin_filter" tag to the database query used to build the list
of nodes on the content administration page, to make it easier to alter.
- Made the cron queue system log any exceptions that are thrown while an item
diff --git a/includes/database/mysql/database.inc b/includes/database/mysql/database.inc
index 00d81f473..4907a39dd 100644
--- a/includes/database/mysql/database.inc
+++ b/includes/database/mysql/database.inc
@@ -90,7 +90,7 @@ class DatabaseConnection_mysql extends DatabaseConnection {
public function queryTemporary($query, array $args = array(), array $options = array()) {
$tablename = $this->generateTemporaryTableName();
- $this->query(preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE {' . $tablename . '} Engine=MEMORY SELECT', $query), $args, $options);
+ $this->query('CREATE TEMPORARY TABLE {' . $tablename . '} Engine=MEMORY ' . $query, $args, $options);
return $tablename;
}
diff --git a/includes/database/pgsql/database.inc b/includes/database/pgsql/database.inc
index 00ed7990e..67b49fed7 100644
--- a/includes/database/pgsql/database.inc
+++ b/includes/database/pgsql/database.inc
@@ -146,7 +146,7 @@ class DatabaseConnection_pgsql extends DatabaseConnection {
public function queryTemporary($query, array $args = array(), array $options = array()) {
$tablename = $this->generateTemporaryTableName();
- $this->query(preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE {' . $tablename . '} AS SELECT', $query), $args, $options);
+ $this->query('CREATE TEMPORARY TABLE {' . $tablename . '} AS ' . $query, $args, $options);
return $tablename;
}
diff --git a/includes/database/sqlite/database.inc b/includes/database/sqlite/database.inc
index b302b3e32..8a5ba8c97 100644
--- a/includes/database/sqlite/database.inc
+++ b/includes/database/sqlite/database.inc
@@ -250,7 +250,7 @@ class DatabaseConnection_sqlite extends DatabaseConnection {
$prefixes[$tablename] = '';
$this->setPrefix($prefixes);
- $this->query(preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE ' . $tablename . ' AS SELECT', $query), $args, $options);
+ $this->query('CREATE TEMPORARY TABLE ' . $tablename . ' AS ' . $query, $args, $options);
return $tablename;
}
diff --git a/modules/simpletest/tests/database_test.test b/modules/simpletest/tests/database_test.test
index c3f52551e..dba04b27b 100644
--- a/modules/simpletest/tests/database_test.test
+++ b/modules/simpletest/tests/database_test.test
@@ -3137,6 +3137,15 @@ class DatabaseTemporaryQueryTestCase extends DrupalWebTestCase {
$this->assertEqual($this->countTableRows($table_name_system), $this->countTableRows("system"), 'A temporary table was created successfully in this request.');
$this->assertEqual($this->countTableRows($table_name_users), $this->countTableRows("users"), 'A second temporary table was created successfully in this request.');
+
+ // Check that leading whitespace and comments do not cause problems
+ // in the modified query.
+ $sql = "
+ -- Let's select some rows into a temporary table
+ SELECT name FROM {test}
+ ";
+ $table_name_test = db_query_temporary($sql, array());
+ $this->assertEqual($this->countTableRows($table_name_test), $this->countTableRows('test'), 'Leading white space and comments do not interfere with temporary table creation.');
}
}