Commit 25bf486b by Carsten Brandt

save some function calls on AR insert

parent 0a709b10
......@@ -282,7 +282,7 @@ class ActiveRecord extends BaseActiveRecord
*/
public static function getTableSchema()
{
$schema = static::getDb()->getTableSchema(static::tableName());
$schema = static::getDb()->getSchema()->getTableSchema(static::tableName());
if ($schema !== null) {
return $schema;
} else {
......
......@@ -131,7 +131,8 @@ class QueryBuilder extends \yii\base\Object
*/
public function insert($table, $columns, &$params)
{
if (($tableSchema = $this->db->getTableSchema($table)) !== null) {
$schema = $this->db->getSchema();
if (($tableSchema = $schema->getTableSchema($table)) !== null) {
$columnSchemas = $tableSchema->columns;
} else {
$columnSchemas = [];
......@@ -139,7 +140,7 @@ class QueryBuilder extends \yii\base\Object
$names = [];
$placeholders = [];
foreach ($columns as $name => $value) {
$names[] = $this->db->quoteColumnName($name);
$names[] = $schema->quoteColumnName($name);
if ($value instanceof Expression) {
$placeholders[] = $value->expression;
foreach ($value->params as $n => $v) {
......@@ -152,7 +153,7 @@ class QueryBuilder extends \yii\base\Object
}
}
return 'INSERT INTO ' . $this->db->quoteTableName($table)
return 'INSERT INTO ' . $schema->quoteTableName($table)
. ' (' . implode(', ', $names) . ') VALUES ('
. implode(', ', $placeholders) . ')';
}
......@@ -178,7 +179,8 @@ class QueryBuilder extends \yii\base\Object
*/
public function batchInsert($table, $columns, $rows)
{
if (($tableSchema = $this->db->getTableSchema($table)) !== null) {
$schema = $this->db->getSchema();
if (($tableSchema = $schema->getTableSchema($table)) !== null) {
$columnSchemas = $tableSchema->columns;
} else {
$columnSchemas = [];
......@@ -192,7 +194,7 @@ class QueryBuilder extends \yii\base\Object
$value = $columnSchemas[$columns[$i]]->dbTypecast($value);
}
if (is_string($value)) {
$value = $this->db->quoteValue($value);
$value = $schema->quoteValue($value);
} elseif ($value === false) {
$value = 0;
} elseif ($value === null) {
......@@ -204,10 +206,10 @@ class QueryBuilder extends \yii\base\Object
}
foreach ($columns as $i => $name) {
$columns[$i] = $this->db->quoteColumnName($name);
$columns[$i] = $schema->quoteColumnName($name);
}
return 'INSERT INTO ' . $this->db->quoteTableName($table)
return 'INSERT INTO ' . $schema->quoteTableName($table)
. ' (' . implode(', ', $columns) . ') VALUES ' . implode(', ', $values);
}
......
......@@ -128,8 +128,8 @@ class QueryBuilder extends \yii\db\QueryBuilder
public function checkIntegrity($check = true, $schema = '', $table = '')
{
$enable = $check ? 'ENABLE' : 'DISABLE';
$schema = $schema ? $schema : $this->db->schema->defaultSchema;
$tableNames = $table ? [$table] : $this->db->schema->getTableNames($schema);
$schema = $schema ? $schema : $this->db->getSchema()->defaultSchema;
$tableNames = $table ? [$table] : $this->db->getSchema()->getTableNames($schema);
$command = '';
foreach ($tableNames as $tableName) {
......@@ -165,7 +165,8 @@ class QueryBuilder extends \yii\db\QueryBuilder
*/
public function batchInsert($table, $columns, $rows)
{
if (($tableSchema = $this->db->getTableSchema($table)) !== null) {
$schema = $this->db->getSchema();
if (($tableSchema = $schema->getTableSchema($table)) !== null) {
$columnSchemas = $tableSchema->columns;
} else {
$columnSchemas = [];
......@@ -179,7 +180,7 @@ class QueryBuilder extends \yii\db\QueryBuilder
$value = $columnSchemas[$columns[$i]]->dbTypecast($value);
}
if (is_string($value)) {
$value = $this->db->quoteValue($value);
$value = $schema->quoteValue($value);
} elseif ($value === true) {
$value = 'TRUE';
} elseif ($value === false) {
......@@ -193,10 +194,10 @@ class QueryBuilder extends \yii\db\QueryBuilder
}
foreach ($columns as $i => $name) {
$columns[$i] = $this->db->quoteColumnName($name);
$columns[$i] = $schema->quoteColumnName($name);
}
return 'INSERT INTO ' . $this->db->quoteTableName($table)
return 'INSERT INTO ' . $schema->quoteTableName($table)
. ' (' . implode(', ', $columns) . ') VALUES ' . implode(', ', $values);
}
}
......@@ -70,7 +70,8 @@ class QueryBuilder extends \yii\db\QueryBuilder
return parent::batchInsert($table, $columns, $rows);
}
if (($tableSchema = $this->db->getTableSchema($table)) !== null) {
$schema = $this->db->getSchema();
if (($tableSchema = $schema->getTableSchema($table)) !== null) {
$columnSchemas = $tableSchema->columns;
} else {
$columnSchemas = [];
......@@ -84,7 +85,7 @@ class QueryBuilder extends \yii\db\QueryBuilder
$value = $columnSchemas[$columns[$i]]->dbTypecast($value);
}
if (is_string($value)) {
$value = $this->db->quoteValue($value);
$value = $schema->quoteValue($value);
} elseif ($value === false) {
$value = 0;
} elseif ($value === null) {
......@@ -96,10 +97,10 @@ class QueryBuilder extends \yii\db\QueryBuilder
}
foreach ($columns as $i => $name) {
$columns[$i] = $this->db->quoteColumnName($name);
$columns[$i] = $schema->quoteColumnName($name);
}
return 'INSERT INTO ' . $this->db->quoteTableName($table)
return 'INSERT INTO ' . $schema->quoteTableName($table)
. ' (' . implode(', ', $columns) . ') SELECT ' . implode(' UNION SELECT ', $values);
}
......
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