Commit ff50f150 by Qiang Xue

proper quoting of sequence name.

parent bc5028eb
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
namespace yii\db\oci; namespace yii\db\oci;
use yii\base\InvalidCallException;
use yii\db\TableSchema; use yii\db\TableSchema;
use yii\db\ColumnSchema; use yii\db\ColumnSchema;
......
...@@ -99,12 +99,8 @@ class QueryBuilder extends \yii\db\QueryBuilder ...@@ -99,12 +99,8 @@ class QueryBuilder extends \yii\db\QueryBuilder
{ {
$table = $this->db->getTableSchema($tableName); $table = $this->db->getTableSchema($tableName);
if ($table !== null && $table->sequenceName !== null) { if ($table !== null && $table->sequenceName !== null) {
$sequence = '"' . $table->sequenceName . '"'; // c.f. http://www.postgresql.org/docs/8.1/static/functions-sequence.html
$sequence = $this->db->quoteTableName($table->sequenceName);
if (strpos($sequence, '.') !== false) {
$sequence = str_replace('.', '"."', $sequence);
}
$tableName = $this->db->quoteTableName($tableName); $tableName = $this->db->quoteTableName($tableName);
if ($value === null) { if ($value === null) {
$key = reset($table->primaryKey); $key = reset($table->primaryKey);
......
...@@ -405,7 +405,7 @@ SQL; ...@@ -405,7 +405,7 @@ SQL;
if ($column->isPrimaryKey) { if ($column->isPrimaryKey) {
$table->primaryKey[] = $column->name; $table->primaryKey[] = $column->name;
if ($table->sequenceName === null && preg_match("/nextval\\('\"?\\w+\"?\.?\"?\\w+\"?'(::regclass)?\\)/", $column->defaultValue) === 1) { if ($table->sequenceName === null && preg_match("/nextval\\('\"?\\w+\"?\.?\"?\\w+\"?'(::regclass)?\\)/", $column->defaultValue) === 1) {
$table->sequenceName = trim(preg_replace(['/nextval/', '/::/', '/regclass/', '/\'\)/', '/\(\'/'], '', $column->defaultValue), '"'); $table->sequenceName = preg_replace(['/nextval/', '/::/', '/regclass/', '/\'\)/', '/\(\'/'], '', $column->defaultValue);
} }
$column->defaultValue = null; $column->defaultValue = null;
} elseif ($column->defaultValue) { } elseif ($column->defaultValue) {
......
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