Commit 43333d9c by Qiang Xue

Implemented master balancing.

parent 91e0c5ae
......@@ -324,7 +324,7 @@ class Schema extends Object
public function quoteValue($str)
{
if (is_string($str)) {
return $this->db->getReadPdo()->quote($str);
return $this->db->getSlavePdo()->quote($str);
} else {
return $str;
}
......
......@@ -161,9 +161,9 @@ class Command extends \yii\base\Component
$sql = $this->getSql();
if ($forRead || $forRead === null && $this->db->getSchema()->isReadQuery($sql)) {
$pdo = $this->db->getReadPdo();
$pdo = $this->db->getSlavePdo();
} else {
$pdo = $this->db->getWritePdo();
$pdo = $this->db->getMasterPdo();
}
try {
......
......@@ -369,7 +369,7 @@ abstract class Schema extends Object
return $str;
}
if (($value = $this->db->getReadPdo()->quote($str)) !== false) {
if (($value = $this->db->getSlavePdo()->quote($str)) !== false) {
return $value;
} else {
// the driver doesn't support quote (e.g. oci)
......
......@@ -116,7 +116,7 @@ class Schema extends \yii\db\Schema
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
$version = $pdo->getAttribute(\PDO::ATTR_CLIENT_VERSION);
......@@ -143,7 +143,7 @@ class Schema extends \yii\db\Schema
*/
protected function loadTableSchema($name)
{
$pdo = $this->db->getReadPdo();
$pdo = $this->db->getSlavePdo();
$tableInfo = $pdo->cubrid_schema(\PDO::CUBRID_SCH_TABLE, $name);
......@@ -266,7 +266,7 @@ class Schema extends \yii\db\Schema
*/
protected function findTableNames($schema = '')
{
$pdo = $this->db->getReadPdo();
$pdo = $this->db->getSlavePdo();
$tables =$pdo->cubrid_schema(\PDO::CUBRID_SCH_TABLE);
$tableNames = [];
foreach ($tables as $table) {
......
......@@ -239,7 +239,7 @@ class QueryBuilder extends \yii\db\QueryBuilder
*/
protected function isOldMssql()
{
$pdo = $this->db->getReadPdo();
$pdo = $this->db->getSlavePdo();
$version = preg_split("/\./", $pdo->getAttribute(\PDO::ATTR_SERVER_VERSION));
return $version[0] < 11;
}
......
......@@ -137,7 +137,7 @@ class QueryBuilder extends \yii\db\QueryBuilder
}
// 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;
}
......
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