summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-01-11 10:57:20 +0000
committerDries Buytaert <dries@buytaert.net>2009-01-11 10:57:20 +0000
commitf80c6184276793e60cd67ef0bad39c2c1914e10e (patch)
tree1d2d678aa64b8d080941cfe8b4e2dcec6c79747d /includes
parent08f263fb23b2f6a59085dcf39ca8647982c49446 (diff)
downloadbrdo-f80c6184276793e60cd67ef0bad39c2c1914e10e.tar.gz
brdo-f80c6184276793e60cd67ef0bad39c2c1914e10e.tar.bz2
- Patch #349500 by Damien Tournoud et al: made db_query_temporary() generate its own temporary table names.
Diffstat (limited to 'includes')
-rw-r--r--includes/database/database.inc34
-rw-r--r--includes/database/mysql/database.inc6
-rw-r--r--includes/database/pgsql/database.inc6
-rw-r--r--includes/database/sqlite/database.inc6
4 files changed, 35 insertions, 17 deletions
diff --git a/includes/database/database.inc b/includes/database/database.inc
index 2ca7747ac..4f97afd40 100644
--- a/includes/database/database.inc
+++ b/includes/database/database.inc
@@ -296,6 +296,13 @@ abstract class DatabaseConnection extends PDO {
protected $transactionalDDLSupport = FALSE;
/**
+ * An index used to generate unique temporary table names.
+ *
+ * @var integer
+ */
+ protected $temporaryNameIndex = 0;
+
+ /**
* The schema object for this connection.
*
* @var object
@@ -910,6 +917,16 @@ abstract class DatabaseConnection extends PDO {
abstract public function queryRange($query, array $args, $from, $count, array $options = array());
/**
+ * Generate a temporary table name.
+ *
+ * @return
+ * A table name.
+ */
+ protected function generateTemporaryTableName() {
+ return "db_temporary_" . $this->temporaryNameIndex++;
+ }
+
+ /**
* Runs a SELECT query and stores its results in a temporary table.
*
* Use this as a substitute for ->query() when the results need to stored
@@ -925,17 +942,13 @@ abstract class DatabaseConnection extends PDO {
* A string containing a normal SELECT SQL query.
* @param $args
* An array of values to substitute into the query at placeholder markers.
- * @param $tablename
- * The name of the temporary table to select into. This name will not be
- * prefixed as there is no risk of collision.
* @param $options
* An associative array of options to control how the query is run. See
* the documentation for DatabaseConnection::defaultOptions() for details.
* @return
- * A database query result resource, or FALSE if the query was not executed
- * correctly.
+ * The name of the temporary table.
*/
- abstract function queryTemporary($query, array $args, $tablename, array $options = array());
+ abstract function queryTemporary($query, array $args, array $options = array());
/**
* Returns the type of database driver.
@@ -1788,20 +1801,19 @@ function db_query_range($query, $args, $from = 0, $count = 0, $options = array()
* placeholders, this is an associative array in any order. If the query uses
* unnamed placeholders (?), this is an indexed array and the order must match
* the order of placeholders in the query string.
- * @param $tablename
- * The name of the temporary table to select into. This name will not be
- * prefixed as there is no risk of collision.
* @param $options
* An array of options to control how the query operates.
+ * @return
+ * The name of the temporary table.
*/
-function db_query_temporary($query, $args, $tablename, $options = array()) {
+function db_query_temporary($query, $args, $options = array()) {
if (!is_array($args)) {
$args = func_get_args();
array_shift($args);
}
list($query, $args, $options) = _db_query_process_args($query, $args, $options);
- return Database::getActiveConnection($options['target'])->queryTemporary($query, $args, $tablename, $options);
+ return Database::getActiveConnection($options['target'])->queryTemporary($query, $args, $options);
}
/**
diff --git a/includes/database/mysql/database.inc b/includes/database/mysql/database.inc
index b03c03ca3..281bcfa09 100644
--- a/includes/database/mysql/database.inc
+++ b/includes/database/mysql/database.inc
@@ -50,8 +50,10 @@ class DatabaseConnection_mysql extends DatabaseConnection {
return $this->query($query . ' LIMIT ' . $from . ', ' . $count, $args, $options);
}
- public function queryTemporary($query, array $args, $tablename, array $options = array()) {
- return $this->query(preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE ' . $tablename . ' Engine=MEMORY SELECT', $query), $args, $options);
+ public function queryTemporary($query, array $args, array $options = array()) {
+ $tablename = $this->generateTemporaryTableName();
+ $this->query(preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE {' . $tablename . '} Engine=MEMORY SELECT', $query), $args, $options);
+ return $tablename;
}
public function driver() {
diff --git a/includes/database/pgsql/database.inc b/includes/database/pgsql/database.inc
index 477845053..6e39bb232 100644
--- a/includes/database/pgsql/database.inc
+++ b/includes/database/pgsql/database.inc
@@ -82,8 +82,10 @@ class DatabaseConnection_pgsql extends DatabaseConnection {
return $this->query($query . ' LIMIT ' . $count . ' OFFSET ' . $from, $args, $options);
}
- public function queryTemporary($query, array $args, $tablename, array $options = array()) {
- return $this->query(preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE ' . $tablename . ' AS SELECT', $query), $args, $options);
+ public function queryTemporary($query, array $args, array $options = array()) {
+ $tablename = $this->generateTemporaryTableName();
+ $this->query(preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE {' . $tablename . '} AS SELECT', $query), $args, $options);
+ return $tablename;
}
public function driver() {
diff --git a/includes/database/sqlite/database.inc b/includes/database/sqlite/database.inc
index e62ed5d1b..bf0c1625e 100644
--- a/includes/database/sqlite/database.inc
+++ b/includes/database/sqlite/database.inc
@@ -123,8 +123,10 @@ class DatabaseConnection_sqlite extends DatabaseConnection {
return $this->query($query . ' LIMIT ' . $from . ', ' . $count, $args, $options);
}
- public function queryTemporary($query, array $args, $tablename, array $options = array()) {
- return $this->query(preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE ' . $tablename . ' AS SELECT', $query), $args, $options);
+ public function queryTemporary($query, array $args, array $options = array()) {
+ $tablename = $this->generateTemporaryTableName();
+ $this->query(preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE {' . $tablename . '} AS SELECT', $query), $args, $options);
+ return $tablename;
}
public function driver() {