Browse Source

Fixed sqlite column type detection bug.

tags/2.0.0-beta
Qiang Xue 11 years ago
parent
commit
26c7f6d62f
  1. 2
      framework/yii/db/pgsql/Schema.php
  2. 2
      framework/yii/db/sqlite/Schema.php
  3. 10
      tests/unit/framework/db/sqlite/SqliteActiveRecordTest.php

2
framework/yii/db/pgsql/Schema.php

@ -303,7 +303,7 @@ SQL;
$column->dbType = $info['data_type']; $column->dbType = $info['data_type'];
$column->defaultValue = $info['column_default']; $column->defaultValue = $info['column_default'];
$column->enumValues = explode(',', str_replace(["''"], ["'"], $info['enum_values'])); $column->enumValues = explode(',', str_replace(["''"], ["'"], $info['enum_values']));
$column->unsigned = false; // has no meanining in PG $column->unsigned = false; // has no meaning in PG
$column->isPrimaryKey = $info['is_pkey']; $column->isPrimaryKey = $info['is_pkey'];
$column->name = $info['column_name']; $column->name = $info['column_name'];
$column->precision = $info['numeric_precision']; $column->precision = $info['numeric_precision'];

2
framework/yii/db/sqlite/Schema.php

@ -153,7 +153,7 @@ class Schema extends \yii\db\Schema
$column->type = self::TYPE_STRING; $column->type = self::TYPE_STRING;
if (preg_match('/^(\w+)(?:\(([^\)]+)\))?/', $column->dbType, $matches)) { if (preg_match('/^(\w+)(?:\(([^\)]+)\))?/', $column->dbType, $matches)) {
$type = $matches[1]; $type = strtolower($matches[1]);
if (isset($this->typeMap[$type])) { if (isset($this->typeMap[$type])) {
$column->type = $this->typeMap[$type]; $column->type = $this->typeMap[$type];
} }

10
tests/unit/framework/db/sqlite/SqliteActiveRecordTest.php

@ -36,10 +36,10 @@ class SqliteActiveRecordTest extends ActiveRecordTest
$this->assertTrue(0 == $customer->status); $this->assertTrue(0 == $customer->status);
// select with boolean values does not seem to work in sqlite // select with boolean values does not seem to work in sqlite
// $customers = Customer::find()->where(['status' => true])->all(); $customers = Customer::find()->where(['status' => true])->all();
// $this->assertEquals(2, count($customers)); $this->assertEquals(2, count($customers));
//
// $customers = Customer::find()->where(['status' => false])->all(); $customers = Customer::find()->where(['status' => false])->all();
// $this->assertEquals(1, count($customers)); $this->assertEquals(1, count($customers));
} }
} }

Loading…
Cancel
Save