Commit e67d0b3c by Qiang Xue

WIP

parent 2018503c
......@@ -272,11 +272,12 @@ class Command extends \yii\base\Component
foreach ($values as $name => $value) {
if (is_array($value)) {
$this->_pendingParams[$name] = $value;
$this->params[$name] = $value[0];
} else {
$type = $this->db->getSchema()->getPdoType($value);
$this->_pendingParams[$name] = [$value, $type];
$this->params[$name] = $value;
}
$this->params[$name] = $value;
}
return $this;
......
......@@ -643,8 +643,7 @@ class Connection extends Component
if (($pos = strpos($this->dsn, ':')) !== false) {
$this->_driverName = strtolower(substr($this->dsn, 0, $pos));
} else {
$this->open();
$this->_driverName = strtolower($this->pdo->getAttribute(PDO::ATTR_DRIVER_NAME));
$this->_driverName = strtolower($this->getReadPdo()->getAttribute(PDO::ATTR_DRIVER_NAME));
}
}
return $this->_driverName;
......
......@@ -369,9 +369,7 @@ abstract class Schema extends Object
return $str;
}
$pdo = $this->db->getReadPdo();
if (($value = $pdo->quote($str)) !== false) {
if (($value = $this->db->getReadPdo()->quote($str)) !== false) {
return $value;
} else {
// the driver doesn't support quote (e.g. oci)
......
......@@ -143,8 +143,9 @@ class Schema extends \yii\db\Schema
*/
protected function loadTableSchema($name)
{
$this->db->open();
$tableInfo = $this->db->pdo->cubrid_schema(\PDO::CUBRID_SCH_TABLE, $name);
$pdo = $this->db->getReadPdo();
$tableInfo = $pdo->cubrid_schema(\PDO::CUBRID_SCH_TABLE, $name);
if (!isset($tableInfo[0]['NAME'])) {
return null;
......@@ -161,7 +162,7 @@ class Schema extends \yii\db\Schema
$table->columns[$column->name] = $column;
}
$primaryKeys = $this->db->pdo->cubrid_schema(\PDO::CUBRID_SCH_PRIMARY_KEY, $table->name);
$primaryKeys = $pdo->cubrid_schema(\PDO::CUBRID_SCH_PRIMARY_KEY, $table->name);
foreach ($primaryKeys as $key) {
$column = $table->columns[$key['ATTR_NAME']];
$column->isPrimaryKey = true;
......@@ -171,7 +172,7 @@ class Schema extends \yii\db\Schema
}
}
$foreignKeys = $this->db->pdo->cubrid_schema(\PDO::CUBRID_SCH_IMPORTED_KEYS, $table->name);
$foreignKeys = $pdo->cubrid_schema(\PDO::CUBRID_SCH_IMPORTED_KEYS, $table->name);
foreach ($foreignKeys as $key) {
if (isset($table->foreignKeys[$key['FK_NAME']])) {
$table->foreignKeys[$key['FK_NAME']][$key['FKCOLUMN_NAME']] = $key['PKCOLUMN_NAME'];
......@@ -265,8 +266,8 @@ class Schema extends \yii\db\Schema
*/
protected function findTableNames($schema = '')
{
$this->db->open();
$tables = $this->db->pdo->cubrid_schema(\PDO::CUBRID_SCH_TABLE);
$pdo = $this->db->getReadPdo();
$tables =$pdo->cubrid_schema(\PDO::CUBRID_SCH_TABLE);
$tableNames = [];
foreach ($tables as $table) {
// do not list system tables
......
......@@ -239,8 +239,8 @@ class QueryBuilder extends \yii\db\QueryBuilder
*/
protected function isOldMssql()
{
$this->db->open();
$version = preg_split("/\./", $this->db->pdo->getAttribute(\PDO::ATTR_SERVER_VERSION));
$pdo = $this->db->getReadPdo();
$version = preg_split("/\./", $pdo->getAttribute(\PDO::ATTR_SERVER_VERSION));
return $version[0] < 11;
}
}
......@@ -132,7 +132,11 @@ EOD;
if ($value !== null) {
$value = (int) $value;
} else {
// use master connection to get the biggest PK value
$enableSlave = $this->db->enableSlave;
$this->db->enableSlave = false;
$value = (int) $this->db->createCommand("SELECT MAX(\"{$tableSchema->primaryKey}\") FROM \"{$tableSchema->name}\"")->queryScalar();
$this->db->enableSlave = $enableSlave;
$value++;
}
......
......@@ -195,7 +195,12 @@ EOD;
public function getLastInsertID($sequenceName = '')
{
if ($this->db->isActive) {
return $this->db->createCommand("SELECT {$sequenceName}.CURRVAL FROM DUAL")->queryScalar();
// get the last insert id from the master connection
$enableSlave = $this->db->enableSlave;
$this->db->enableSlave = false;
$id = $this->db->createCommand("SELECT {$sequenceName}.CURRVAL FROM DUAL")->queryScalar();
$this->db->enableSlave = $enableSlave;
return $id;
} else {
throw new InvalidCallException('DB Connection is not active.');
}
......
......@@ -136,8 +136,8 @@ class QueryBuilder extends \yii\db\QueryBuilder
$command .= "ALTER TABLE $tableName $enable TRIGGER ALL; ";
}
#enable to have ability to alter several tables
$this->db->pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);
// enable to have ability to alter several tables
$this->db->getWritePdo()->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);
return $command;
}
......
......@@ -120,7 +120,10 @@ class QueryBuilder extends \yii\db\QueryBuilder
if ($value === null) {
$key = reset($table->primaryKey);
$tableName = $db->quoteTableName($tableName);
$enableSlave = $this->db->enableSlave;
$this->db->enableSlave = false;
$value = $db->createCommand("SELECT MAX('$key') FROM $tableName")->queryScalar();
$this->db->enableSlave = $enableSlave;
} else {
$value = (int) $value - 1;
}
......
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