Commit 6b52b035 by Qiang Xue

Fixes #6049: `yii\db\Connection::getSchema()` for Oracle should return false…

Fixes #6049: `yii\db\Connection::getSchema()` for Oracle should return false when the table does not exist. Oracle does not support `ON UPDATE` clause.
parent 3d25f76e
......@@ -26,6 +26,7 @@ Yii Framework 2 Change Log
- Bug #5925: `ArrayHelper::htmlEncode()` does not work properly when the value being encoded is a nested array (tebazil)
- Bug #5997: The same message may be exported twice to log targets (klimov-paul)
- Bug #6018: When setting the `encode` option via `yii\widgets\ActiveRecord::errorOptions`, it works the other way around (stanishevsky, qiangxue)
- Bug #6049: `yii\db\Connection::getSchema()` for Oracle should return false when the table does not exist. Oracle does not support `ON UPDATE` clause. (wenbin1989)
- Bug: Gii console command help information does not contain global options (qiangxue)
- Bug: `yii\web\UrlRule` was unable to create URLs for rules containing unicode characters (samdark)
- Enh #4181: Added `yii\bootstrap\Modal::$headerOptions` and `yii\bootstrap\Modal::$footerOptions` (tuxoff, samdark)
......
......@@ -9,6 +9,7 @@ namespace yii\db\oci;
use yii\base\InvalidParamException;
use yii\db\Connection;
use yii\db\Exception;
/**
* QueryBuilder is the query builder for Oracle databases.
......@@ -152,46 +153,10 @@ EOD;
if ($delete !== null) {
$sql .= ' ON DELETE ' . $delete;
}
return $sql;
}
/**
* @inheritdoc
*/
public function batchInsert($table, $columns, $rows)
{
$schema = $this->db->getSchema();
if (($tableSchema = $schema->getTableSchema($table)) !== null) {
$columnSchemas = $tableSchema->columns;
} else {
$columnSchemas = [];
}
$values = [];
foreach ($rows as $row) {
$vs = [];
foreach ($row as $i => $value) {
if (!is_array($value) && isset($columns[$i]) && isset($columnSchemas[$columns[$i]])) {
$value = $columnSchemas[$columns[$i]]->dbTypecast($value);
}
if (is_string($value)) {
$value = $schema->quoteValue($value);
} elseif ($value === false) {
$value = 0;
} elseif ($value === null) {
$value = 'NULL';
}
$vs[] = $value;
}
$values[] = 'SELECT ' . implode(', ', $vs) . ' FROM DUAL';
if ($update !== null) {
throw new Exception('Oracle does not support ON UPDATE clause.');
}
foreach ($columns as $i => $name) {
$columns[$i] = $schema->quoteColumnName($name);
}
return 'INSERT INTO ' . $schema->quoteTableName($table)
. ' (' . implode(', ', $columns) . ') ' . implode(' UNION ', $values);
return $sql;
}
}
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