From 56d84d22a166b841420d7917ecbe68691b9d8535 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Wed, 3 Sep 2014 11:43:24 +1200 Subject: [PATCH] BUG MySQLDatabase performs queries on wrong DB connection when using connection $name != 'default' --- model/MySQLDatabase.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/model/MySQLDatabase.php b/model/MySQLDatabase.php index 8e4ce338222..b15ec04bc63 100644 --- a/model/MySQLDatabase.php +++ b/model/MySQLDatabase.php @@ -396,7 +396,7 @@ public function renameField($tableName, $oldName, $newName) { private static $_cache_collation_info = array(); public function fieldList($table) { - $fields = DB::query("SHOW FULL FIELDS IN \"$table\""); + $fields = $this->query("SHOW FULL FIELDS IN \"$table\""); foreach($fields as $field) { // ensure that '' is converted to \' in field specification (mostly for the benefit of ENUM values) @@ -409,7 +409,7 @@ public function fieldList($table) { // Cache collation info to cut down on database traffic if(!isset(self::$_cache_collation_info[$field['Collation']])) { self::$_cache_collation_info[$field['Collation']] - = DB::query("SHOW COLLATION LIKE '$field[Collation]'")->record(); + = $this->query("SHOW COLLATION LIKE '$field[Collation]'")->record(); } $collInfo = self::$_cache_collation_info[$field['Collation']]; $fieldSpec .= " character set $collInfo[Charset] collate $field[Collation]"; @@ -537,7 +537,7 @@ public function alterIndex($tableName, $indexName, $indexSpec) { * @return array */ public function indexList($table) { - $indexes = DB::query("SHOW INDEXES IN \"$table\""); + $indexes = $this->query("SHOW INDEXES IN \"$table\""); $groupedIndexes = array(); $indexList = array(); @@ -817,7 +817,7 @@ public function hasTable($table) { */ public function enumValuesForField($tableName, $fieldName) { // Get the enum of all page types from the SiteTree table - $classnameinfo = DB::query("DESCRIBE \"$tableName\" \"$fieldName\"")->first(); + $classnameinfo = $this->query("DESCRIBE \"$tableName\" \"$fieldName\"")->first(); preg_match_all("/'[^,]+'/", $classnameinfo["Type"], $matches); $classes = array(); @@ -927,7 +927,7 @@ public function searchEngine($classesToSearch, $keywords, $start, $pageLength, $ $fullQuery = implode(" UNION ", $querySQLs) . " ORDER BY $sortBy LIMIT $limit"; // Get records - $records = DB::query($fullQuery); + $records = $this->query($fullQuery); $objects = array(); @@ -1194,7 +1194,7 @@ public function supportsLocks() { public function canLock($name) { $id = $this->getLockIdentifier($name); - return (bool)DB::query(sprintf("SELECT IS_FREE_LOCK('%s')", $id))->value(); + return (bool)$this->query(sprintf("SELECT IS_FREE_LOCK('%s')", $id))->value(); } public function getLock($name, $timeout = 5) { @@ -1203,12 +1203,12 @@ public function getLock($name, $timeout = 5) { // MySQL auto-releases existing locks on subsequent GET_LOCK() calls, // in contrast to PostgreSQL and SQL Server who stack the locks. - return (bool)DB::query(sprintf("SELECT GET_LOCK('%s', %d)", $id, $timeout))->value(); + return (bool)$this->query(sprintf("SELECT GET_LOCK('%s', %d)", $id, $timeout))->value(); } public function releaseLock($name) { $id = $this->getLockIdentifier($name); - return (bool)DB::query(sprintf("SELECT RELEASE_LOCK('%s')", $id))->value(); + return (bool)$this->query(sprintf("SELECT RELEASE_LOCK('%s')", $id))->value(); } protected function getLockIdentifier($name) {