Skip to content

Commit

Permalink
BUG MySQLDatabase performs queries on wrong DB connection when using …
Browse files Browse the repository at this point in the history
…connection $name != 'default'
  • Loading branch information
Damian Mooyman committed Sep 2, 2014
1 parent 7bacaa8 commit 56d84d2
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions model/MySQLDatabase.php
Expand Up @@ -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)
Expand All @@ -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]";
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 56d84d2

Please sign in to comment.