mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge pull request #3465 from tractorcow/pulls/3.1/fix-query
BUG MySQLDatabase performs queries on wrong DB connection when using connection $name != default
This commit is contained in:
commit
55de41b0d5
@ -396,7 +396,7 @@ class MySQLDatabase extends SS_Database {
|
|||||||
private static $_cache_collation_info = array();
|
private static $_cache_collation_info = array();
|
||||||
|
|
||||||
public function fieldList($table) {
|
public function fieldList($table) {
|
||||||
$fields = DB::query("SHOW FULL FIELDS IN \"$table\"");
|
$fields = $this->query("SHOW FULL FIELDS IN \"$table\"");
|
||||||
foreach($fields as $field) {
|
foreach($fields as $field) {
|
||||||
|
|
||||||
// ensure that '' is converted to \' in field specification (mostly for the benefit of ENUM values)
|
// ensure that '' is converted to \' in field specification (mostly for the benefit of ENUM values)
|
||||||
@ -409,7 +409,7 @@ class MySQLDatabase extends SS_Database {
|
|||||||
// Cache collation info to cut down on database traffic
|
// Cache collation info to cut down on database traffic
|
||||||
if(!isset(self::$_cache_collation_info[$field['Collation']])) {
|
if(!isset(self::$_cache_collation_info[$field['Collation']])) {
|
||||||
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']];
|
$collInfo = self::$_cache_collation_info[$field['Collation']];
|
||||||
$fieldSpec .= " character set $collInfo[Charset] collate $field[Collation]";
|
$fieldSpec .= " character set $collInfo[Charset] collate $field[Collation]";
|
||||||
@ -537,7 +537,7 @@ class MySQLDatabase extends SS_Database {
|
|||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function indexList($table) {
|
public function indexList($table) {
|
||||||
$indexes = DB::query("SHOW INDEXES IN \"$table\"");
|
$indexes = $this->query("SHOW INDEXES IN \"$table\"");
|
||||||
$groupedIndexes = array();
|
$groupedIndexes = array();
|
||||||
$indexList = array();
|
$indexList = array();
|
||||||
|
|
||||||
@ -817,7 +817,7 @@ class MySQLDatabase extends SS_Database {
|
|||||||
*/
|
*/
|
||||||
public function enumValuesForField($tableName, $fieldName) {
|
public function enumValuesForField($tableName, $fieldName) {
|
||||||
// Get the enum of all page types from the SiteTree table
|
// 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);
|
preg_match_all("/'[^,]+'/", $classnameinfo["Type"], $matches);
|
||||||
|
|
||||||
$classes = array();
|
$classes = array();
|
||||||
@ -927,7 +927,7 @@ class MySQLDatabase extends SS_Database {
|
|||||||
$fullQuery = implode(" UNION ", $querySQLs) . " ORDER BY $sortBy LIMIT $limit";
|
$fullQuery = implode(" UNION ", $querySQLs) . " ORDER BY $sortBy LIMIT $limit";
|
||||||
|
|
||||||
// Get records
|
// Get records
|
||||||
$records = DB::query($fullQuery);
|
$records = $this->query($fullQuery);
|
||||||
|
|
||||||
$objects = array();
|
$objects = array();
|
||||||
|
|
||||||
@ -1194,7 +1194,7 @@ class MySQLDatabase extends SS_Database {
|
|||||||
|
|
||||||
public function canLock($name) {
|
public function canLock($name) {
|
||||||
$id = $this->getLockIdentifier($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) {
|
public function getLock($name, $timeout = 5) {
|
||||||
@ -1203,12 +1203,12 @@ class MySQLDatabase extends SS_Database {
|
|||||||
// MySQL auto-releases existing locks on subsequent GET_LOCK() calls,
|
// MySQL auto-releases existing locks on subsequent GET_LOCK() calls,
|
||||||
// in contrast to PostgreSQL and SQL Server who stack the locks.
|
// 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) {
|
public function releaseLock($name) {
|
||||||
$id = $this->getLockIdentifier($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) {
|
protected function getLockIdentifier($name) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user