Issue #1868972 by jweowu: db_query_temporary() fails to create a table when the SQL has leading whitespace.
parent
9da7e4cdc7
commit
03a7c55fdb
|
@ -140,7 +140,7 @@ class Connection 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -179,7 +179,7 @@ class Connection 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -266,7 +266,7 @@ class Connection 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,5 +54,14 @@ class TemporaryQueryTest extends DatabaseWebTestBase {
|
|||
|
||||
$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.');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue