The following code is flawed:
<?php
function db_query_temporary($query) {
$args = func_get_args();
$tablename = array_pop($args);
array_shift($args);
$query = preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE '. $tablename .' AS 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);
}
?>
Notice the line:
$query = preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE '. $tablename .' AS SELECT', db_prefix_tables($query));
In this line, the query gets processed by db_prefix_tables, but tablename does not.
The end result is that when "{mytablename}" gets evaluated in both occurances, the temporary table will be called "{mytablename}" but the query might call it "drupaldb_mytablename"
So when query tries to access the temporary table, it cannot because it is being called by the wrong name.
The solution is easy, wrap the tablename call with the db_prefix_tables() function.
I have attached a patch that fixes this for all occurrences that I could find.
| Comment | File | Size | Author |
|---|---|---|---|
| drupal-6.9-db_query_temporary_prefix_issue-1.patch | 1.66 KB | thekevinday |
Comments
Comment #1
miglius commentedsubscribe
Comment #2
thekevinday commentedThis is still a problem, updating affected version.