Commit 03a7c55f authored by alexpott's avatar alexpott

Issue #1868972 by jweowu: db_query_temporary() fails to create a table when...

Issue #1868972 by jweowu: db_query_temporary() fails to create a table when the SQL has leading whitespace.
parent 9da7e4cd
......@@ -140,7 +140,7 @@ public function queryRange($query, $from, $count, array $args = array(), array $
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;
}
......
......@@ -179,7 +179,7 @@ public function queryRange($query, $from, $count, array $args = array(), array $
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;
}
......
......@@ -266,7 +266,7 @@ public function queryTemporary($query, array $args = array(), array $options = a
$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;
}
......
......@@ -54,5 +54,14 @@ function testTemporaryQuery() {
$this->assertEqual($this->countTableRows($table_name_test), $this->countTableRows('test'), 'A temporary table was created successfully in this request.');
$this->assertEqual($this->countTableRows($table_name_task), $this->countTableRows('test_task'), '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.');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment