Commit 43333d9c by Qiang Xue

Implemented master balancing.

parent 91e0c5ae
...@@ -324,7 +324,7 @@ class Schema extends Object ...@@ -324,7 +324,7 @@ class Schema extends Object
public function quoteValue($str) public function quoteValue($str)
{ {
if (is_string($str)) { if (is_string($str)) {
return $this->db->getReadPdo()->quote($str); return $this->db->getSlavePdo()->quote($str);
} else { } else {
return $str; return $str;
} }
......
...@@ -161,9 +161,9 @@ class Command extends \yii\base\Component ...@@ -161,9 +161,9 @@ class Command extends \yii\base\Component
$sql = $this->getSql(); $sql = $this->getSql();
if ($forRead || $forRead === null && $this->db->getSchema()->isReadQuery($sql)) { if ($forRead || $forRead === null && $this->db->getSchema()->isReadQuery($sql)) {
$pdo = $this->db->getReadPdo(); $pdo = $this->db->getSlavePdo();
} else { } else {
$pdo = $this->db->getWritePdo(); $pdo = $this->db->getMasterPdo();
} }
try { try {
......
...@@ -369,7 +369,7 @@ abstract class Schema extends Object ...@@ -369,7 +369,7 @@ abstract class Schema extends Object
return $str; return $str;
} }
if (($value = $this->db->getReadPdo()->quote($str)) !== false) { if (($value = $this->db->getSlavePdo()->quote($str)) !== false) {
return $value; return $value;
} else { } else {
// the driver doesn't support quote (e.g. oci) // the driver doesn't support quote (e.g. oci)
......
...@@ -116,7 +116,7 @@ class Schema extends \yii\db\Schema ...@@ -116,7 +116,7 @@ class Schema extends \yii\db\Schema
return $str; return $str;
} }
$pdo = $this->db->getReadPdo(); $pdo = $this->db->getSlavePdo();
// workaround for broken PDO::quote() implementation in CUBRID 9.1.0 http://jira.cubrid.org/browse/APIS-658 // workaround for broken PDO::quote() implementation in CUBRID 9.1.0 http://jira.cubrid.org/browse/APIS-658
$version = $pdo->getAttribute(\PDO::ATTR_CLIENT_VERSION); $version = $pdo->getAttribute(\PDO::ATTR_CLIENT_VERSION);
...@@ -143,7 +143,7 @@ class Schema extends \yii\db\Schema ...@@ -143,7 +143,7 @@ class Schema extends \yii\db\Schema
*/ */
protected function loadTableSchema($name) protected function loadTableSchema($name)
{ {
$pdo = $this->db->getReadPdo(); $pdo = $this->db->getSlavePdo();
$tableInfo = $pdo->cubrid_schema(\PDO::CUBRID_SCH_TABLE, $name); $tableInfo = $pdo->cubrid_schema(\PDO::CUBRID_SCH_TABLE, $name);
...@@ -266,7 +266,7 @@ class Schema extends \yii\db\Schema ...@@ -266,7 +266,7 @@ class Schema extends \yii\db\Schema
*/ */
protected function findTableNames($schema = '') protected function findTableNames($schema = '')
{ {
$pdo = $this->db->getReadPdo(); $pdo = $this->db->getSlavePdo();
$tables =$pdo->cubrid_schema(\PDO::CUBRID_SCH_TABLE); $tables =$pdo->cubrid_schema(\PDO::CUBRID_SCH_TABLE);
$tableNames = []; $tableNames = [];
foreach ($tables as $table) { foreach ($tables as $table) {
......
...@@ -239,7 +239,7 @@ class QueryBuilder extends \yii\db\QueryBuilder ...@@ -239,7 +239,7 @@ class QueryBuilder extends \yii\db\QueryBuilder
*/ */
protected function isOldMssql() protected function isOldMssql()
{ {
$pdo = $this->db->getReadPdo(); $pdo = $this->db->getSlavePdo();
$version = preg_split("/\./", $pdo->getAttribute(\PDO::ATTR_SERVER_VERSION)); $version = preg_split("/\./", $pdo->getAttribute(\PDO::ATTR_SERVER_VERSION));
return $version[0] < 11; return $version[0] < 11;
} }
......
...@@ -137,7 +137,7 @@ class QueryBuilder extends \yii\db\QueryBuilder ...@@ -137,7 +137,7 @@ class QueryBuilder extends \yii\db\QueryBuilder
} }
// enable to have ability to alter several tables // enable to have ability to alter several tables
$this->db->getWritePdo()->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true); $this->db->getMasterPdo()->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);
return $command; return $command;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment