Commit 1391253a by Carsten Brandt

fixed postgres default value parsing

parent 651e6a3f
......@@ -7,6 +7,7 @@
namespace yii\db\pgsql;
use yii\db\Expression;
use yii\db\TableSchema;
use yii\db\ColumnSchema;
......@@ -408,10 +409,16 @@ SQL;
}
$column->defaultValue = null;
} elseif ($column->defaultValue) {
if (stripos($column->dbType, 'bit') === 0 || stripos($column->dbType, 'varbit') === 0) {
if ($column->type === 'timestamp' && $column->defaultValue === 'now()') {
$column->defaultValue = new Expression($column->defaultValue);
} elseif (stripos($column->dbType, 'bit') === 0 || stripos($column->dbType, 'varbit') === 0) {
$column->defaultValue = bindec(trim($column->defaultValue, 'B\''));
} elseif (preg_match("/^'(.*?)'::/", $column->defaultValue, $matches) || preg_match("/^(.*?)::/", $column->defaultValue, $matches)) {
} elseif (preg_match("/^'(.*?)'::/", $column->defaultValue, $matches)) {
$column->defaultValue = $matches[1];
} elseif (preg_match("/^(.*?)::/", $column->defaultValue, $matches)) {
$column->defaultValue = $column->typecast($matches[1]);
} else {
$column->defaultValue = $column->typecast($column->defaultValue);
}
}
}
......@@ -438,7 +445,7 @@ SQL;
$column->name = $info['column_name'];
$column->precision = $info['numeric_precision'];
$column->scale = $info['numeric_scale'];
$column->size = $info['size'];
$column->size = $info['size'] === null ? null : (int)$info['size'];
if (isset($this->typeMap[$column->dbType])) {
$column->type = $this->typeMap[$column->dbType];
} else {
......
......@@ -2,6 +2,7 @@
namespace yiiunit\framework\db\pgsql;
use yii\db\Expression;
use yii\db\pgsql\Schema;
use yiiunit\framework\db\SchemaTest;
......@@ -17,17 +18,43 @@ class PostgreSQLSchemaTest extends SchemaTest
{
$columns = parent::getExpectedColumns();
unset($columns['enum_col']);
$columns['int_col']['dbType'] = 'integer';
$columns['int_col']['dbType'] = 'int4';
$columns['int_col']['size'] = null;
$columns['int_col']['precision'] = null;
$columns['int_col2']['dbType'] = 'integer';
$columns['int_col']['precision'] = 32;
$columns['int_col']['scale'] = 0;
$columns['int_col2']['dbType'] = 'int4';
$columns['int_col2']['size'] = null;
$columns['int_col2']['precision'] = null;
$columns['bool_col']['type'] = 'boolean';
$columns['bool_col']['phpType'] = 'boolean';
$columns['bool_col2']['type'] = 'boolean';
$columns['bool_col2']['phpType'] = 'boolean';
$columns['bool_col2']['defaultValue'] = true;
$columns['int_col2']['precision'] = 32;
$columns['int_col2']['scale'] = 0;
$columns['char_col']['dbType'] = 'bpchar';
$columns['char_col']['precision'] = null;
$columns['char_col2']['dbType'] = 'varchar';
$columns['char_col2']['precision'] = null;
$columns['float_col']['dbType'] = 'float8';
$columns['float_col']['precision'] = 53;
$columns['float_col']['scale'] = null;
$columns['float_col']['size'] = null;
$columns['float_col2']['dbType'] = 'float8';
$columns['float_col2']['precision'] = 53;
$columns['float_col2']['scale'] = null;
$columns['float_col2']['size'] = null;
$columns['blob_col']['dbType'] = 'bytea';
$columns['blob_col']['phpType'] = 'resource';
$columns['blob_col']['type'] = 'binary';
$columns['numeric_col']['dbType'] = 'numeric';
$columns['numeric_col']['size'] = null;
$columns['bool_col']['dbType'] = 'int2';
$columns['bool_col']['size'] = null;
$columns['bool_col']['precision'] = 16;
$columns['bool_col']['scale'] = 0;
$columns['bool_col2']['dbType'] = 'int2';
$columns['bool_col2']['size'] = null;
$columns['bool_col2']['precision'] = 16;
$columns['bool_col2']['scale'] = 0;
$columns['ts_default']['defaultValue'] = new Expression('now()');
$columns['bit_col']['dbType'] = 'bit';
$columns['bit_col']['size'] = 1; // TODO should be 8???
$columns['bit_col']['precision'] = null;
return $columns;
}
}
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