Browse Source

Merge pull request #10921 from df2/9562-add-char-datatype

Brings migrations up to parity
tags/2.0.8
Alexander Makarov 9 years ago
parent
commit
2134442ba3
  1. 4
      .gitignore
  2. BIN
      docs/internals/schema-builder-patterns.xlsx
  3. 5
      framework/CHANGELOG.md
  4. 3
      framework/UPGRADE.md
  5. 2
      framework/db/ColumnSchema.php
  6. 164
      framework/db/ColumnSchemaBuilder.php
  7. 2
      framework/db/QueryBuilder.php
  8. 3
      framework/db/Schema.php
  9. 12
      framework/db/SchemaBuilderTrait.php
  10. 63
      framework/db/cubrid/ColumnSchemaBuilder.php
  11. 3
      framework/db/cubrid/QueryBuilder.php
  12. 12
      framework/db/cubrid/Schema.php
  13. 28
      framework/db/mssql/ColumnSchemaBuilder.php
  14. 7
      framework/db/mssql/QueryBuilder.php
  15. 12
      framework/db/mssql/Schema.php
  16. 63
      framework/db/mysql/ColumnSchemaBuilder.php
  17. 4
      framework/db/mysql/QueryBuilder.php
  18. 11
      framework/db/mysql/Schema.php
  19. 44
      framework/db/oci/ColumnSchemaBuilder.php
  20. 4
      framework/db/oci/QueryBuilder.php
  21. 2
      framework/db/oci/Schema.php
  22. 28
      framework/db/pgsql/ColumnSchemaBuilder.php
  23. 3
      framework/db/pgsql/QueryBuilder.php
  24. 13
      framework/db/pgsql/Schema.php
  25. 46
      framework/db/sqlite/ColumnSchemaBuilder.php
  26. 4
      framework/db/sqlite/QueryBuilder.php
  27. 10
      framework/db/sqlite/Schema.php
  28. 6
      tests/data/mysql.sql
  29. 4
      tests/framework/db/ColumnSchemaBuilderTest.php
  30. 923
      tests/framework/db/QueryBuilderTest.php
  31. 26
      tests/framework/db/SchemaTest.php
  32. 10
      tests/framework/db/cubrid/ColumnSchemaBuilderTest.php
  33. 65
      tests/framework/db/cubrid/CubridQueryBuilderTest.php
  34. 65
      tests/framework/db/mssql/MssqlQueryBuilderTest.php
  35. 10
      tests/framework/db/mysql/ColumnSchemaBuilderTest.php
  36. 53
      tests/framework/db/mysql/MysqlQueryBuilderTest.php
  37. 15
      tests/framework/db/oci/ColumnSchemaBuilderTest.php
  38. 71
      tests/framework/db/oci/OracleQueryBuilderTest.php
  39. 95
      tests/framework/db/pgsql/PostgreSQLQueryBuilderTest.php
  40. 37
      tests/framework/db/sqlite/ColumnSchemaBuilderTest.php
  41. 71
      tests/framework/db/sqlite/SqliteQueryBuilderTest.php

4
.gitignore vendored

@ -9,6 +9,10 @@ nbproject
.project .project
.settings .settings
# sublime text project / workspace files
*.sublime-project
*.sublime-workspace
# windows thumbnail cache # windows thumbnail cache
Thumbs.db Thumbs.db

BIN
docs/internals/schema-builder-patterns.xlsx

Binary file not shown.

5
framework/CHANGELOG.md

@ -34,6 +34,11 @@ Yii Framework 2 Change Log
- Enh: Added `StringHelper::countWords()` that given a string returns number of words in it (samdark) - Enh: Added `StringHelper::countWords()` that given a string returns number of words in it (samdark)
- Bug #11040: Check parameter 'recursive' and disable recursive copying with option 'recursive' => false in method BaseFileHelper::copyDirectory (Ni-san) - Bug #11040: Check parameter 'recursive' and disable recursive copying with option 'recursive' => false in method BaseFileHelper::copyDirectory (Ni-san)
- Chg: HTMLPurifier dependency updated to `~4.6` (samdark) - Chg: HTMLPurifier dependency updated to `~4.6` (samdark)
- Enh #10889: Allows unsigned primary key column definitions (df2)
- Chg #10921: Inverts responsibility of database specific column schema builder classes (df2)
- Enh #9562: Adds `char` datatype to framework (df2)
- Enh #9340: Adds `after()` and `first()` column schema builder modifiers (df2)
- Enh #10921: `__toString()` of column schema builder now adapts to column types (df2)
- Chg #10726: Added `yii\rbac\ManagerInterface::canAddChild()` (dkhlystov, samdark) - Chg #10726: Added `yii\rbac\ManagerInterface::canAddChild()` (dkhlystov, samdark)
- Chg #11071: `yii\helpers\BaseArrayHelper::isIn()` and `isTraversable()` since now throw `\yii\base\InvalidParamException` instead of `\InvalidArgumentException` (nukkumatti) - Chg #11071: `yii\helpers\BaseArrayHelper::isIn()` and `isTraversable()` since now throw `\yii\base\InvalidParamException` instead of `\InvalidArgumentException` (nukkumatti)

3
framework/UPGRADE.md

@ -25,6 +25,9 @@ ______________________
- `yii\rbac\ManagerInterface::canAddChild()` method was added. If you have custom backend for RBAC you need to implement - `yii\rbac\ManagerInterface::canAddChild()` method was added. If you have custom backend for RBAC you need to implement
it. it.
* The signature of `yii\db\ColumnSchemaBuilder::__construct()` was changed. The method has got an extra optional parameter `$db`. In case you are instantiating this class yourself and using the `$config` parameter, you will need to move it to the right by one.
* String types in the MSSQL column schema map were upgraded to Unicode storage types. This will have no effect on existing columns, but any new columns you generate via the migrations engine will now store data as Unicode.
Upgrade from Yii 2.0.6 Upgrade from Yii 2.0.6
---------------------- ----------------------

2
framework/db/ColumnSchema.php

@ -27,7 +27,7 @@ class ColumnSchema extends Object
public $allowNull; public $allowNull;
/** /**
* @var string abstract type of this column. Possible abstract types include: * @var string abstract type of this column. Possible abstract types include:
* string, text, boolean, smallint, integer, bigint, float, decimal, datetime, * char, string, text, boolean, smallint, integer, bigint, float, decimal, datetime,
* timestamp, time, date, binary, and money. * timestamp, time, date, binary, and money.
*/ */
public $type; public $type;

164
framework/db/ColumnSchemaBuilder.php

@ -20,6 +20,15 @@ use yii\base\Object;
*/ */
class ColumnSchemaBuilder extends Object class ColumnSchemaBuilder extends Object
{ {
// Internally used constants representing categories that abstract column types fall under.
// See [[$categoryMap]] for mappings of abstract column types to category.
// @since 2.0.8
const CATEGORY_PK = 'pk';
const CATEGORY_STRING = 'string';
const CATEGORY_NUMERIC = 'numeric';
const CATEGORY_TIME = 'time';
const CATEGORY_OTHER = 'other';
/** /**
* @var string the column type definition such as INTEGER, VARCHAR, DATETIME, etc. * @var string the column type definition such as INTEGER, VARCHAR, DATETIME, etc.
*/ */
@ -51,19 +60,62 @@ class ColumnSchemaBuilder extends Object
* @since 2.0.7 * @since 2.0.7
*/ */
protected $isUnsigned = false; protected $isUnsigned = false;
/**
* @var string the column after which this column will be added.
* @since 2.0.8
*/
protected $after;
/**
* @var boolean whether this column is to be inserted at the beginning of the table.
* @since 2.0.8
*/
protected $isFirst;
/**
* @var array mapping of abstract column types (keys) to type categories (values).
* @since 2.0.8
*/
public $categoryMap = [
Schema::TYPE_PK => self::CATEGORY_PK,
Schema::TYPE_UPK => self::CATEGORY_PK,
Schema::TYPE_BIGPK => self::CATEGORY_PK,
Schema::TYPE_UBIGPK => self::CATEGORY_PK,
Schema::TYPE_CHAR => self::CATEGORY_STRING,
Schema::TYPE_STRING => self::CATEGORY_STRING,
Schema::TYPE_TEXT => self::CATEGORY_STRING,
Schema::TYPE_SMALLINT => self::CATEGORY_NUMERIC,
Schema::TYPE_INTEGER => self::CATEGORY_NUMERIC,
Schema::TYPE_BIGINT => self::CATEGORY_NUMERIC,
Schema::TYPE_FLOAT => self::CATEGORY_NUMERIC,
Schema::TYPE_DOUBLE => self::CATEGORY_NUMERIC,
Schema::TYPE_DECIMAL => self::CATEGORY_NUMERIC,
Schema::TYPE_DATETIME => self::CATEGORY_TIME,
Schema::TYPE_TIMESTAMP => self::CATEGORY_TIME,
Schema::TYPE_TIME => self::CATEGORY_TIME,
Schema::TYPE_DATE => self::CATEGORY_TIME,
Schema::TYPE_BINARY => self::CATEGORY_OTHER,
Schema::TYPE_BOOLEAN => self::CATEGORY_NUMERIC,
Schema::TYPE_MONEY => self::CATEGORY_NUMERIC,
];
/**
* @var \yii\db\Connection the current database connection. It is used mainly to escape strings
* safely when building the final column schema string.
* @since 2.0.8
*/
public $db;
/** /**
* Create a column schema builder instance giving the type and value precision. * Create a column schema builder instance giving the type and value precision.
* *
* @param string $type type of the column. See [[$type]]. * @param string $type type of the column. See [[$type]].
* @param integer|string|array $length length or precision of the column. See [[$length]]. * @param integer|string|array $length length or precision of the column. See [[$length]].
* @param \yii\db\Connection $db the current database connection. See [[$db]].
* @param array $config name-value pairs that will be used to initialize the object properties * @param array $config name-value pairs that will be used to initialize the object properties
*/ */
public function __construct($type, $length = null, $config = []) public function __construct($type, $length = null, $db = null, $config = [])
{ {
$this->type = $type; $this->type = $type;
$this->length = $length; $this->length = $length;
$this->db = $db;
parent::__construct($config); parent::__construct($config);
} }
@ -116,11 +168,44 @@ class ColumnSchemaBuilder extends Object
*/ */
public function unsigned() public function unsigned()
{ {
switch ($this->type) {
case Schema::TYPE_PK:
$this->type = Schema::TYPE_UPK;
break;
case Schema::TYPE_BIGPK:
$this->type = Schema::TYPE_UBIGPK;
break;
}
$this->isUnsigned = true; $this->isUnsigned = true;
return $this; return $this;
} }
/** /**
* Adds an `AFTER` constraint to the column.
* Note: MySQL, Oracle and Cubrid support only.
* @param string $after the column after which $this column will be added.
* @return $this
* @since 2.0.8
*/
public function after($after)
{
$this->after = $after;
return $this;
}
/**
* Adds an `FIRST` constraint to the column.
* Note: MySQL, Oracle and Cubrid support only.
* @return $this
* @since 2.0.8
*/
public function first()
{
$this->isFirst = true;
return $this;
}
/**
* Specify the default SQL expression for the column. * Specify the default SQL expression for the column.
* @param string $default the default value expression. * @param string $default the default value expression.
* @return $this * @return $this
@ -133,19 +218,19 @@ class ColumnSchemaBuilder extends Object
} }
/** /**
* Build full string for create the column's schema * Builds the full string for the column's schema
* @return string * @return string
*/ */
public function __toString() public function __toString()
{ {
return switch ($this->getTypeCategory()) {
$this->type . case self::CATEGORY_PK:
$this->buildLengthString() . $format = '{type}{check}';
$this->buildUnsignedString() . break;
$this->buildNotNullString() . default:
$this->buildUniqueString() . $format = '{type}{length}{notnull}{unique}{default}{check}';
$this->buildDefaultString() . }
$this->buildCheckString(); return $this->buildCompleteString($format);
} }
/** /**
@ -223,12 +308,65 @@ class ColumnSchemaBuilder extends Object
} }
/** /**
* Builds the unsigned string for column. * Builds the unsigned string for column. Defaults to unsupported.
* @return string a string containing UNSIGNED keyword. * @return string a string containing UNSIGNED keyword.
* @since 2.0.7 * @since 2.0.7
*/ */
protected function buildUnsignedString() protected function buildUnsignedString()
{ {
return $this->isUnsigned ? ' UNSIGNED' : ''; return '';
}
/**
* Builds the after constraint for the column. Defaults to unsupported.
* @return string a string containing the AFTER constraint.
* @since 2.0.8
*/
protected function buildAfterString()
{
return '';
}
/**
* Builds the first constraint for the column. Defaults to unsupported.
* @return string a string containing the FIRST constraint.
* @since 2.0.8
*/
protected function buildFirstString()
{
return '';
}
/**
* Returns the category of the column type.
* @return string a string containing the column type category name.
* @since 2.0.8
*/
protected function getTypeCategory()
{
return $this->categoryMap[$this->type];
}
/**
* Returns the complete column definition from input format
* @param string $format the format of the definition.
* @return string a string containing the complete column definition.
* @since 2.0.8
*/
protected function buildCompleteString($format)
{
$placeholderValues = [
'{type}' => $this->type,
'{length}' => $this->buildLengthString(),
'{unsigned}' => $this->buildUnsignedString(),
'{notnull}' => $this->buildNotNullString(),
'{unique}' => $this->buildUniqueString(),
'{default}' => $this->buildDefaultString(),
'{check}' => $this->buildCheckString(),
'{pos}' => ($this->isFirst) ?
$this->buildFirstString() :
$this->buildAfterString(),
];
return strtr($format, $placeholderValues);
} }
} }

2
framework/db/QueryBuilder.php

@ -576,6 +576,8 @@ class QueryBuilder extends \yii\base\Object
* *
* - `pk`: an auto-incremental primary key type, will be converted into "int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY" * - `pk`: an auto-incremental primary key type, will be converted into "int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY"
* - `bigpk`: an auto-incremental primary key type, will be converted into "bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY" * - `bigpk`: an auto-incremental primary key type, will be converted into "bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY"
* - `unsignedpk`: an unsigned auto-incremental primary key type, will be converted into "int(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY"
* - `char`: char type, will be converted into "char(1)"
* - `string`: string type, will be converted into "varchar(255)" * - `string`: string type, will be converted into "varchar(255)"
* - `text`: a long string type, will be converted into "text" * - `text`: a long string type, will be converted into "text"
* - `smallint`: a small integer type, will be converted into "smallint(6)" * - `smallint`: a small integer type, will be converted into "smallint(6)"

3
framework/db/Schema.php

@ -41,7 +41,10 @@ abstract class Schema extends Object
* The following are the supported abstract column data types. * The following are the supported abstract column data types.
*/ */
const TYPE_PK = 'pk'; const TYPE_PK = 'pk';
const TYPE_UPK = 'upk';
const TYPE_BIGPK = 'bigpk'; const TYPE_BIGPK = 'bigpk';
const TYPE_UBIGPK = 'ubigpk';
const TYPE_CHAR = 'char';
const TYPE_STRING = 'string'; const TYPE_STRING = 'string';
const TYPE_TEXT = 'text'; const TYPE_TEXT = 'text';
const TYPE_SMALLINT = 'smallint'; const TYPE_SMALLINT = 'smallint';

12
framework/db/SchemaBuilderTrait.php

@ -64,6 +64,18 @@ trait SchemaBuilderTrait
} }
/** /**
* Creates a char column.
* @param integer $length column size definition i.e. the maximum string length.
* This parameter will be ignored if not supported by the DBMS.
* @return ColumnSchemaBuilder the column instance which can be further customized.
* @since 2.0.8
*/
public function char($length = null)
{
return $this->getDb()->getSchema()->createColumnSchemaBuilder(Schema::TYPE_CHAR, $length);
}
/**
* Creates a string column. * Creates a string column.
* @param integer $length column size definition i.e. the maximum string length. * @param integer $length column size definition i.e. the maximum string length.
* This parameter will be ignored if not supported by the DBMS. * This parameter will be ignored if not supported by the DBMS.

63
framework/db/cubrid/ColumnSchemaBuilder.php

@ -0,0 +1,63 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\db\cubrid;
use yii\db\ColumnSchemaBuilder as AbstractColumnSchemaBuilder;
/**
* ColumnSchemaBuilder is the schema builder for Cubrid databases.
*
* @author Chris Harris <chris@buckshotsoftware.com>
* @since 2.0.8
*/
class ColumnSchemaBuilder extends AbstractColumnSchemaBuilder
{
/**
* @inheritdoc
*/
protected function buildUnsignedString()
{
return $this->isUnsigned ? ' UNSIGNED' : '';
}
/**
* @inheritdoc
*/
protected function buildAfterString()
{
return $this->after !== null ?
' AFTER (' . $this->db->quoteColumnName($this->after) . ')' :
'';
}
/**
* @inheritdoc
*/
protected function buildFirstString()
{
return $this->isFirst ? ' FIRST' : '';
}
/**
* @inheritdoc
*/
public function __toString()
{
switch ($this->getTypeCategory()) {
case self::CATEGORY_PK:
$format = '{type}{check}{pos}';
break;
case self::CATEGORY_NUMERIC:
$format = '{type}{length}{unsigned}{notnull}{unique}{default}{check}{pos}';
break;
default:
$format = '{type}{length}{notnull}{unique}{default}{check}{pos}';
}
return $this->buildCompleteString($format);
}
}

3
framework/db/cubrid/QueryBuilder.php

@ -22,7 +22,10 @@ class QueryBuilder extends \yii\db\QueryBuilder
*/ */
public $typeMap = [ public $typeMap = [
Schema::TYPE_PK => 'int NOT NULL AUTO_INCREMENT PRIMARY KEY', Schema::TYPE_PK => 'int NOT NULL AUTO_INCREMENT PRIMARY KEY',
Schema::TYPE_UPK => 'int UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY',
Schema::TYPE_BIGPK => 'bigint NOT NULL AUTO_INCREMENT PRIMARY KEY', Schema::TYPE_BIGPK => 'bigint NOT NULL AUTO_INCREMENT PRIMARY KEY',
Schema::TYPE_UBIGPK => 'bigint UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY',
Schema::TYPE_CHAR => 'char(1)',
Schema::TYPE_STRING => 'varchar(255)', Schema::TYPE_STRING => 'varchar(255)',
Schema::TYPE_TEXT => 'varchar', Schema::TYPE_TEXT => 'varchar',
Schema::TYPE_SMALLINT => 'smallint', Schema::TYPE_SMALLINT => 'smallint',

12
framework/db/cubrid/Schema.php

@ -45,10 +45,10 @@ class Schema extends \yii\db\Schema
'timestamp' => self::TYPE_TIMESTAMP, 'timestamp' => self::TYPE_TIMESTAMP,
'datetime' => self::TYPE_DATETIME, 'datetime' => self::TYPE_DATETIME,
// String data types // String data types
'char' => self::TYPE_STRING, 'char' => self::TYPE_CHAR,
'varchar' => self::TYPE_STRING, 'varchar' => self::TYPE_STRING,
'char varying' => self::TYPE_STRING, 'char varying' => self::TYPE_STRING,
'nchar' => self::TYPE_STRING, 'nchar' => self::TYPE_CHAR,
'nchar varying' => self::TYPE_STRING, 'nchar varying' => self::TYPE_STRING,
'string' => self::TYPE_STRING, 'string' => self::TYPE_STRING,
// BLOB/CLOB data types // BLOB/CLOB data types
@ -299,4 +299,12 @@ class Schema extends \yii\db\Schema
} }
parent::setTransactionIsolationLevel($level); parent::setTransactionIsolationLevel($level);
} }
/**
* @inheritdoc
*/
public function createColumnSchemaBuilder($type, $length = null)
{
return new ColumnSchemaBuilder($type, $length, $this->db);
}
} }

28
framework/db/mssql/ColumnSchemaBuilder.php

@ -1,28 +0,0 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\db\mssql;
use yii\db\ColumnSchemaBuilder as AbstractColumnSchemaBuilder;
/**
* ColumnSchemaBuilder is the schema builder for MSSQL databases.
*
* @author Alexander Makarov <sam@rmcreative.ru>
* @since 2.0.7
*/
class ColumnSchemaBuilder extends AbstractColumnSchemaBuilder
{
/**
* @inheritdoc
*/
protected function buildUnsignedString()
{
return '';
}
}

7
framework/db/mssql/QueryBuilder.php

@ -23,9 +23,12 @@ class QueryBuilder extends \yii\db\QueryBuilder
*/ */
public $typeMap = [ public $typeMap = [
Schema::TYPE_PK => 'int IDENTITY PRIMARY KEY', Schema::TYPE_PK => 'int IDENTITY PRIMARY KEY',
Schema::TYPE_UPK => 'int IDENTITY PRIMARY KEY',
Schema::TYPE_BIGPK => 'bigint IDENTITY PRIMARY KEY', Schema::TYPE_BIGPK => 'bigint IDENTITY PRIMARY KEY',
Schema::TYPE_STRING => 'varchar(255)', Schema::TYPE_UBIGPK => 'bigint IDENTITY PRIMARY KEY',
Schema::TYPE_TEXT => 'text', Schema::TYPE_CHAR => 'nchar(1)',
Schema::TYPE_STRING => 'nvarchar(255)',
Schema::TYPE_TEXT => 'ntext',
Schema::TYPE_SMALLINT => 'smallint', Schema::TYPE_SMALLINT => 'smallint',
Schema::TYPE_INTEGER => 'int', Schema::TYPE_INTEGER => 'int',
Schema::TYPE_BIGINT => 'bigint', Schema::TYPE_BIGINT => 'bigint',

12
framework/db/mssql/Schema.php

@ -47,11 +47,11 @@ class Schema extends \yii\db\Schema
'datetime' => self::TYPE_DATETIME, 'datetime' => self::TYPE_DATETIME,
'time' => self::TYPE_TIME, 'time' => self::TYPE_TIME,
// character strings // character strings
'char' => self::TYPE_STRING, 'char' => self::TYPE_CHAR,
'varchar' => self::TYPE_STRING, 'varchar' => self::TYPE_STRING,
'text' => self::TYPE_TEXT, 'text' => self::TYPE_TEXT,
// unicode character strings // unicode character strings
'nchar' => self::TYPE_STRING, 'nchar' => self::TYPE_CHAR,
'nvarchar' => self::TYPE_STRING, 'nvarchar' => self::TYPE_STRING,
'ntext' => self::TYPE_TEXT, 'ntext' => self::TYPE_TEXT,
// binary strings // binary strings
@ -426,12 +426,4 @@ SQL;
} }
return $result; return $result;
} }
/**
* @inheritdoc
*/
public function createColumnSchemaBuilder($type, $length = null)
{
return new ColumnSchemaBuilder($type, $length);
}
} }

63
framework/db/mysql/ColumnSchemaBuilder.php

@ -0,0 +1,63 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\db\mysql;
use yii\db\ColumnSchemaBuilder as AbstractColumnSchemaBuilder;
/**
* ColumnSchemaBuilder is the schema builder for MySQL databases.
*
* @author Chris Harris <chris@buckshotsoftware.com>
* @since 2.0.8
*/
class ColumnSchemaBuilder extends AbstractColumnSchemaBuilder
{
/**
* @inheritdoc
*/
protected function buildUnsignedString()
{
return $this->isUnsigned ? ' UNSIGNED' : '';
}
/**
* @inheritdoc
*/
protected function buildAfterString()
{
return $this->after !== null ?
' AFTER (' . $this->db->quoteColumnName($this->after) . ')' :
'';
}
/**
* @inheritdoc
*/
protected function buildFirstString()
{
return $this->isFirst ? ' FIRST' : '';
}
/**
* @inheritdoc
*/
public function __toString()
{
switch ($this->getTypeCategory()) {
case self::CATEGORY_PK:
$format = '{type}{length}{check}{pos}';
break;
case self::CATEGORY_NUMERIC:
$format = '{type}{length}{unsigned}{notnull}{unique}{default}{check}{pos}';
break;
default:
$format = '{type}{length}{notnull}{unique}{default}{check}{pos}';
}
return $this->buildCompleteString($format);
}
}

4
framework/db/mysql/QueryBuilder.php

@ -24,7 +24,10 @@ class QueryBuilder extends \yii\db\QueryBuilder
*/ */
public $typeMap = [ public $typeMap = [
Schema::TYPE_PK => 'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY', Schema::TYPE_PK => 'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY',
Schema::TYPE_UPK => 'int(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY',
Schema::TYPE_BIGPK => 'bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY', Schema::TYPE_BIGPK => 'bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY',
Schema::TYPE_UBIGPK => 'bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY',
Schema::TYPE_CHAR => 'char(1)',
Schema::TYPE_STRING => 'varchar(255)', Schema::TYPE_STRING => 'varchar(255)',
Schema::TYPE_TEXT => 'text', Schema::TYPE_TEXT => 'text',
Schema::TYPE_SMALLINT => 'smallint(6)', Schema::TYPE_SMALLINT => 'smallint(6)',
@ -42,7 +45,6 @@ class QueryBuilder extends \yii\db\QueryBuilder
Schema::TYPE_MONEY => 'decimal(19,4)', Schema::TYPE_MONEY => 'decimal(19,4)',
]; ];
/** /**
* Builds a SQL statement for renaming a column. * Builds a SQL statement for renaming a column.
* @param string $table the table whose column is to be renamed. The name will be properly quoted by the method. * @param string $table the table whose column is to be renamed. The name will be properly quoted by the method.

11
framework/db/mysql/Schema.php

@ -43,7 +43,7 @@ class Schema extends \yii\db\Schema
'text' => self::TYPE_TEXT, 'text' => self::TYPE_TEXT,
'varchar' => self::TYPE_STRING, 'varchar' => self::TYPE_STRING,
'string' => self::TYPE_STRING, 'string' => self::TYPE_STRING,
'char' => self::TYPE_STRING, 'char' => self::TYPE_CHAR,
'datetime' => self::TYPE_DATETIME, 'datetime' => self::TYPE_DATETIME,
'year' => self::TYPE_DATE, 'year' => self::TYPE_DATE,
'date' => self::TYPE_DATE, 'date' => self::TYPE_DATE,
@ -52,7 +52,6 @@ class Schema extends \yii\db\Schema
'enum' => self::TYPE_STRING, 'enum' => self::TYPE_STRING,
]; ];
/** /**
* Quotes a table name for use in a query. * Quotes a table name for use in a query.
* A simple table name has no schema prefix. * A simple table name has no schema prefix.
@ -347,4 +346,12 @@ SQL;
return $this->db->createCommand($sql)->queryColumn(); return $this->db->createCommand($sql)->queryColumn();
} }
/**
* @inheritdoc
*/
public function createColumnSchemaBuilder($type, $length = null)
{
return new ColumnSchemaBuilder($type, $length, $this->db);
}
} }

44
framework/db/oci/ColumnSchemaBuilder.php

@ -20,14 +20,44 @@ class ColumnSchemaBuilder extends AbstractColumnSchemaBuilder
/** /**
* @inheritdoc * @inheritdoc
*/ */
protected function buildUnsignedString()
{
return $this->isUnsigned ? ' UNSIGNED' : '';
}
/**
* @inheritdoc
*/
protected function buildAfterString()
{
return $this->after !== null ?
' AFTER (' . $this->db->quoteColumnName($this->after) . ')' :
'';
}
/**
* @inheritdoc
*/
protected function buildFirstString()
{
return $this->isFirst ? ' FIRST' : '';
}
/**
* @inheritdoc
*/
public function __toString() public function __toString()
{ {
return switch ($this->getTypeCategory()) {
$this->type . case self::CATEGORY_PK:
$this->buildLengthString() . $format = '{type}{length}{check}{pos}';
$this->buildUnsignedString() . break;
$this->buildDefaultString() . case self::CATEGORY_NUMERIC:
$this->buildNotNullString() . $format = '{type}{length}{unsigned}{default}{notnull}{check}{pos}';
$this->buildCheckString(); break;
default:
$format = '{type}{length}{default}{notnull}{check}{pos}';
}
return $this->buildCompleteString($format);
} }
} }

4
framework/db/oci/QueryBuilder.php

@ -25,7 +25,10 @@ class QueryBuilder extends \yii\db\QueryBuilder
*/ */
public $typeMap = [ public $typeMap = [
Schema::TYPE_PK => 'NUMBER(10) NOT NULL PRIMARY KEY', Schema::TYPE_PK => 'NUMBER(10) NOT NULL PRIMARY KEY',
Schema::TYPE_UPK => 'NUMBER(10) UNSIGNED NOT NULL PRIMARY KEY',
Schema::TYPE_BIGPK => 'NUMBER(20) NOT NULL PRIMARY KEY', Schema::TYPE_BIGPK => 'NUMBER(20) NOT NULL PRIMARY KEY',
Schema::TYPE_UBIGPK => 'NUMBER(20) UNSIGNED NOT NULL PRIMARY KEY',
Schema::TYPE_CHAR => 'CHAR(1)',
Schema::TYPE_STRING => 'VARCHAR2(255)', Schema::TYPE_STRING => 'VARCHAR2(255)',
Schema::TYPE_TEXT => 'CLOB', Schema::TYPE_TEXT => 'CLOB',
Schema::TYPE_SMALLINT => 'NUMBER(5)', Schema::TYPE_SMALLINT => 'NUMBER(5)',
@ -43,7 +46,6 @@ class QueryBuilder extends \yii\db\QueryBuilder
Schema::TYPE_MONEY => 'NUMBER(19,4)', Schema::TYPE_MONEY => 'NUMBER(19,4)',
]; ];
/** /**
* @inheritdoc * @inheritdoc
*/ */

2
framework/db/oci/Schema.php

@ -73,7 +73,7 @@ class Schema extends \yii\db\Schema
*/ */
public function createColumnSchemaBuilder($type, $length = null) public function createColumnSchemaBuilder($type, $length = null)
{ {
return new ColumnSchemaBuilder($type, $length); return new ColumnSchemaBuilder($type, $length, $this->db);
} }
/** /**

28
framework/db/pgsql/ColumnSchemaBuilder.php

@ -1,28 +0,0 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\db\pgsql;
use yii\db\ColumnSchemaBuilder as AbstractColumnSchemaBuilder;
/**
* ColumnSchemaBuilder is the schema builder for PostgreSQL databases.
*
* @author Alexander Makarov <sam@rmcreative.ru>
* @since 2.0.7
*/
class ColumnSchemaBuilder extends AbstractColumnSchemaBuilder
{
/**
* @inheritdoc
*/
protected function buildUnsignedString()
{
return '';
}
}

3
framework/db/pgsql/QueryBuilder.php

@ -48,7 +48,10 @@ class QueryBuilder extends \yii\db\QueryBuilder
*/ */
public $typeMap = [ public $typeMap = [
Schema::TYPE_PK => 'serial NOT NULL PRIMARY KEY', Schema::TYPE_PK => 'serial NOT NULL PRIMARY KEY',
Schema::TYPE_UPK => 'serial NOT NULL PRIMARY KEY',
Schema::TYPE_BIGPK => 'bigserial NOT NULL PRIMARY KEY', Schema::TYPE_BIGPK => 'bigserial NOT NULL PRIMARY KEY',
Schema::TYPE_UBIGPK => 'bigserial NOT NULL PRIMARY KEY',
Schema::TYPE_CHAR => 'char(1)',
Schema::TYPE_STRING => 'varchar(255)', Schema::TYPE_STRING => 'varchar(255)',
Schema::TYPE_TEXT => 'text', Schema::TYPE_TEXT => 'text',
Schema::TYPE_SMALLINT => 'smallint', Schema::TYPE_SMALLINT => 'smallint',

13
framework/db/pgsql/Schema.php

@ -45,8 +45,9 @@ class Schema extends \yii\db\Schema
'polygon' => self::TYPE_STRING, 'polygon' => self::TYPE_STRING,
'path' => self::TYPE_STRING, 'path' => self::TYPE_STRING,
'character' => self::TYPE_STRING, 'character' => self::TYPE_CHAR,
'char' => self::TYPE_STRING, 'char' => self::TYPE_CHAR,
'bpchar' => self::TYPE_CHAR,
'character varying' => self::TYPE_STRING, 'character varying' => self::TYPE_STRING,
'varchar' => self::TYPE_STRING, 'varchar' => self::TYPE_STRING,
'text' => self::TYPE_TEXT, 'text' => self::TYPE_TEXT,
@ -478,12 +479,4 @@ SQL;
return !$command->pdoStatement->rowCount() ? false : $result; return !$command->pdoStatement->rowCount() ? false : $result;
} }
/**
* @inheritdoc
*/
public function createColumnSchemaBuilder($type, $length = null)
{
return new ColumnSchemaBuilder($type, $length);
}
} }

46
framework/db/sqlite/ColumnSchemaBuilder.php

@ -0,0 +1,46 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\db\sqlite;
use yii\db\ColumnSchemaBuilder as AbstractColumnSchemaBuilder;
/**
* ColumnSchemaBuilder is the schema builder for Sqlite databases.
*
* @author Chris Harris <chris@buckshotsoftware.com>
* @since 2.0.8
*/
class ColumnSchemaBuilder extends AbstractColumnSchemaBuilder
{
/**
* @inheritdoc
*/
protected function buildUnsignedString()
{
return $this->isUnsigned ? ' UNSIGNED' : '';
}
/**
* @inheritdoc
*/
public function __toString()
{
switch ($this->getTypeCategory()) {
case self::CATEGORY_PK:
$format = '{type}{check}';
break;
case self::CATEGORY_NUMERIC:
$format = '{type}{length}{unsigned}{notnull}{unique}{check}{default}';
break;
default:
$format = '{type}{length}{notnull}{unique}{check}{default}';
}
return $this->buildCompleteString($format);
}
}

4
framework/db/sqlite/QueryBuilder.php

@ -27,7 +27,10 @@ class QueryBuilder extends \yii\db\QueryBuilder
*/ */
public $typeMap = [ public $typeMap = [
Schema::TYPE_PK => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL', Schema::TYPE_PK => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL',
Schema::TYPE_UPK => 'integer UNSIGNED PRIMARY KEY AUTOINCREMENT NOT NULL',
Schema::TYPE_BIGPK => 'bigint PRIMARY KEY AUTOINCREMENT NOT NULL', Schema::TYPE_BIGPK => 'bigint PRIMARY KEY AUTOINCREMENT NOT NULL',
Schema::TYPE_UBIGPK => 'bigint UNSIGNED PRIMARY KEY AUTOINCREMENT NOT NULL',
Schema::TYPE_CHAR => 'char(1)',
Schema::TYPE_STRING => 'varchar(255)', Schema::TYPE_STRING => 'varchar(255)',
Schema::TYPE_TEXT => 'text', Schema::TYPE_TEXT => 'text',
Schema::TYPE_SMALLINT => 'smallint', Schema::TYPE_SMALLINT => 'smallint',
@ -45,7 +48,6 @@ class QueryBuilder extends \yii\db\QueryBuilder
Schema::TYPE_MONEY => 'decimal(19,4)', Schema::TYPE_MONEY => 'decimal(19,4)',
]; ];
/** /**
* Generates a batch INSERT SQL statement. * Generates a batch INSERT SQL statement.
* For example, * For example,

10
framework/db/sqlite/Schema.php

@ -48,7 +48,7 @@ class Schema extends \yii\db\Schema
'text' => self::TYPE_TEXT, 'text' => self::TYPE_TEXT,
'varchar' => self::TYPE_STRING, 'varchar' => self::TYPE_STRING,
'string' => self::TYPE_STRING, 'string' => self::TYPE_STRING,
'char' => self::TYPE_STRING, 'char' => self::TYPE_CHAR,
'blob' => self::TYPE_BINARY, 'blob' => self::TYPE_BINARY,
'datetime' => self::TYPE_DATETIME, 'datetime' => self::TYPE_DATETIME,
'year' => self::TYPE_DATE, 'year' => self::TYPE_DATE,
@ -281,4 +281,12 @@ class Schema extends \yii\db\Schema
throw new NotSupportedException(get_class($this) . ' only supports transaction isolation levels READ UNCOMMITTED and SERIALIZABLE.'); throw new NotSupportedException(get_class($this) . ' only supports transaction isolation levels READ UNCOMMITTED and SERIALIZABLE.');
} }
} }
/**
* @inheritdoc
*/
public function createColumnSchemaBuilder($type, $length = null)
{
return new ColumnSchemaBuilder($type, $length);
}
} }

6
tests/data/mysql.sql

@ -24,7 +24,7 @@ CREATE TABLE `constraints`
( (
`id` integer not null, `id` integer not null,
`field1` varchar(255) `field1` varchar(255)
); ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `profile` ( CREATE TABLE `profile` (
@ -100,7 +100,7 @@ CREATE TABLE `composite_fk` (
`item_id` int(11) NOT NULL, `item_id` int(11) NOT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
CONSTRAINT `FK_composite_fk_order_item` FOREIGN KEY (`order_id`,`item_id`) REFERENCES `order_item` (`order_id`,`item_id`) ON DELETE CASCADE CONSTRAINT `FK_composite_fk_order_item` FOREIGN KEY (`order_id`,`item_id`) REFERENCES `order_item` (`order_id`,`item_id`) ON DELETE CASCADE
); ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE null_values ( CREATE TABLE null_values (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
@ -109,7 +109,7 @@ CREATE TABLE null_values (
`var3` INT DEFAULT NULL, `var3` INT DEFAULT NULL,
`stringcol` VARCHAR (32) DEFAULT NULL, `stringcol` VARCHAR (32) DEFAULT NULL,
PRIMARY KEY (id) PRIMARY KEY (id)
); ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `type` ( CREATE TABLE `type` (
`int_col` integer NOT NULL, `int_col` integer NOT NULL,

4
tests/framework/db/ColumnSchemaBuilderTest.php

@ -33,10 +33,10 @@ class ColumnSchemaBuilderTest extends TestCase
public function unsignedProvider() public function unsignedProvider()
{ {
return [ return [
['integer UNSIGNED', Schema::TYPE_INTEGER, null, [ ['integer', Schema::TYPE_INTEGER, null, [
['unsigned'], ['unsigned'],
]], ]],
['integer(10) UNSIGNED', Schema::TYPE_INTEGER, 10, [ ['integer(10)', Schema::TYPE_INTEGER, 10, [
['unsigned'], ['unsigned'],
]], ]],
]; ];

923
tests/framework/db/QueryBuilderTest.php

@ -14,11 +14,7 @@ use yii\db\pgsql\QueryBuilder as PgsqlQueryBuilder;
use yii\db\cubrid\QueryBuilder as CubridQueryBuilder; use yii\db\cubrid\QueryBuilder as CubridQueryBuilder;
use yii\db\oci\QueryBuilder as OracleQueryBuilder; use yii\db\oci\QueryBuilder as OracleQueryBuilder;
/** abstract class QueryBuilderTest extends DatabaseTestCase
* @group db
* @group mysql
*/
class QueryBuilderTest extends DatabaseTestCase
{ {
use SchemaBuilderTrait; use SchemaBuilderTrait;
@ -82,70 +78,856 @@ class QueryBuilderTest extends DatabaseTestCase
*/ */
public function columnTypes() public function columnTypes()
{ {
return [ $items = [
[Schema::TYPE_PK, $this->primaryKey(), 'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY'], [
[Schema::TYPE_PK . '(8)', $this->primaryKey(8), 'int(8) NOT NULL AUTO_INCREMENT PRIMARY KEY'], Schema::TYPE_BIGINT . ' CHECK (value > 5)',
[Schema::TYPE_PK . ' CHECK (value > 5)', $this->primaryKey()->check('value > 5'), 'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY CHECK (value > 5)'], $this->bigInteger()->check('value > 5'),
[Schema::TYPE_PK . '(8) CHECK (value > 5)', $this->primaryKey(8)->check('value > 5'), 'int(8) NOT NULL AUTO_INCREMENT PRIMARY KEY CHECK (value > 5)'], [
[Schema::TYPE_STRING, $this->string(), 'varchar(255)'], 'mysql' => 'bigint(20) CHECK (value > 5)',
[Schema::TYPE_STRING . '(32)', $this->string(32), 'varchar(32)'], 'postgres' => 'bigint CHECK (value > 5)',
[Schema::TYPE_STRING . ' CHECK (value LIKE "test%")', $this->string()->check('value LIKE "test%"'), 'varchar(255) CHECK (value LIKE "test%")'], 'sqlite' => 'bigint CHECK (value > 5)',
[Schema::TYPE_STRING . '(32) CHECK (value LIKE "test%")', $this->string(32)->check('value LIKE "test%"'), 'varchar(32) CHECK (value LIKE "test%")'], 'oci' => 'NUMBER(20) CHECK (value > 5)',
[Schema::TYPE_STRING . ' NOT NULL', $this->string()->notNull(), 'varchar(255) NOT NULL'], 'sqlsrv' => 'bigint CHECK (value > 5)',
[Schema::TYPE_TEXT, $this->text(), 'text'], 'cubrid' => 'bigint CHECK (value > 5)',
[Schema::TYPE_TEXT . '(255)', $this->text(), 'text', Schema::TYPE_TEXT], ],
[Schema::TYPE_TEXT . ' CHECK (value LIKE "test%")', $this->text()->check('value LIKE "test%"'), 'text CHECK (value LIKE "test%")'], ],
[Schema::TYPE_TEXT . '(255) CHECK (value LIKE "test%")', $this->text()->check('value LIKE "test%"'), 'text CHECK (value LIKE "test%")', Schema::TYPE_TEXT . ' CHECK (value LIKE "test%")'], [
[Schema::TYPE_TEXT . ' NOT NULL', $this->text()->notNull(), 'text NOT NULL'], Schema::TYPE_BIGINT . ' NOT NULL',
[Schema::TYPE_TEXT . '(255) NOT NULL', $this->text()->notNull(), 'text NOT NULL', Schema::TYPE_TEXT . ' NOT NULL'], $this->bigInteger()->notNull(),
[Schema::TYPE_SMALLINT, $this->smallInteger(), 'smallint(6)'], [
[Schema::TYPE_SMALLINT . '(8)', $this->smallInteger(8), 'smallint(8)'], 'mysql' => 'bigint(20) NOT NULL',
[Schema::TYPE_INTEGER, $this->integer(), 'int(11)'], 'postgres' => 'bigint NOT NULL',
[Schema::TYPE_INTEGER . '(8)', $this->integer(8), 'int(8)'], 'sqlite' => 'bigint NOT NULL',
[Schema::TYPE_INTEGER . ' CHECK (value > 5)', $this->integer()->check('value > 5'), 'int(11) CHECK (value > 5)'], 'oci' => 'NUMBER(20) NOT NULL',
[Schema::TYPE_INTEGER . '(8) CHECK (value > 5)', $this->integer(8)->check('value > 5'), 'int(8) CHECK (value > 5)'], 'sqlsrv' => 'bigint NOT NULL',
[Schema::TYPE_INTEGER . ' NOT NULL', $this->integer()->notNull(), 'int(11) NOT NULL'], 'cubrid' => 'bigint NOT NULL',
[Schema::TYPE_BIGINT, $this->bigInteger(), 'bigint(20)'], ],
[Schema::TYPE_BIGINT . '(8)', $this->bigInteger(8), 'bigint(8)'], ],
[Schema::TYPE_BIGINT . ' CHECK (value > 5)', $this->bigInteger()->check('value > 5'), 'bigint(20) CHECK (value > 5)'], [
[Schema::TYPE_BIGINT . '(8) CHECK (value > 5)', $this->bigInteger(8)->check('value > 5'), 'bigint(8) CHECK (value > 5)'], Schema::TYPE_BIGINT . '(8) CHECK (value > 5)',
[Schema::TYPE_BIGINT . ' NOT NULL', $this->bigInteger()->notNull(), 'bigint(20) NOT NULL'], $this->bigInteger(8)->check('value > 5'),
[Schema::TYPE_FLOAT, $this->float(), 'float'], [
[Schema::TYPE_FLOAT . '(16)', $this->float(16), 'float'], 'mysql' => 'bigint(8) CHECK (value > 5)',
[Schema::TYPE_FLOAT . ' CHECK (value > 5.6)', $this->float()->check('value > 5.6'), 'float CHECK (value > 5.6)'], 'postgres' => 'bigint CHECK (value > 5)',
[Schema::TYPE_FLOAT . '(16) CHECK (value > 5.6)', $this->float(16)->check('value > 5.6'), 'float CHECK (value > 5.6)'], 'sqlite' => 'bigint CHECK (value > 5)',
[Schema::TYPE_FLOAT . ' NOT NULL', $this->float()->notNull(), 'float NOT NULL'], 'oci' => 'NUMBER(8) CHECK (value > 5)',
[Schema::TYPE_DOUBLE, $this->double(), 'double'], 'sqlsrv' => 'bigint CHECK (value > 5)',
[Schema::TYPE_DOUBLE . '(16)', $this->double(16), 'double'], 'cubrid' => 'bigint CHECK (value > 5)',
[Schema::TYPE_DOUBLE . ' CHECK (value > 5.6)', $this->double()->check('value > 5.6'), 'double CHECK (value > 5.6)'], ],
[Schema::TYPE_DOUBLE . '(16) CHECK (value > 5.6)', $this->double(16)->check('value > 5.6'), 'double CHECK (value > 5.6)'], ],
[Schema::TYPE_DOUBLE . ' NOT NULL', $this->double()->notNull(), 'double NOT NULL'], [
[Schema::TYPE_DECIMAL, $this->decimal(), 'decimal(10,0)'], Schema::TYPE_BIGINT . '(8)',
[Schema::TYPE_DECIMAL . '(12,4)', $this->decimal(12, 4), 'decimal(12,4)'], $this->bigInteger(8),
[Schema::TYPE_DECIMAL . ' CHECK (value > 5.6)', $this->decimal()->check('value > 5.6'), 'decimal(10,0) CHECK (value > 5.6)'], [
[Schema::TYPE_DECIMAL . '(12,4) CHECK (value > 5.6)', $this->decimal(12, 4)->check('value > 5.6'), 'decimal(12,4) CHECK (value > 5.6)'], 'mysql' => 'bigint(8)',
[Schema::TYPE_DECIMAL . ' NOT NULL', $this->decimal()->notNull(), 'decimal(10,0) NOT NULL'], 'postgres' => 'bigint',
[Schema::TYPE_DATETIME, $this->dateTime(), 'datetime'], 'sqlite' => 'bigint',
[Schema::TYPE_DATETIME . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')", $this->dateTime()->check("value BETWEEN '2011-01-01' AND '2013-01-01'"), "datetime CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')"], 'oci' => 'NUMBER(8)',
[Schema::TYPE_DATETIME . ' NOT NULL', $this->dateTime()->notNull(), 'datetime NOT NULL'], 'sqlsrv' => 'bigint',
[Schema::TYPE_TIMESTAMP, $this->timestamp(), 'timestamp'], 'cubrid' => 'bigint',
[Schema::TYPE_TIMESTAMP . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')", $this->timestamp()->check("value BETWEEN '2011-01-01' AND '2013-01-01'"), "timestamp CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')"], ],
[Schema::TYPE_TIMESTAMP . ' NOT NULL', $this->timestamp()->notNull(), 'timestamp NOT NULL'], ],
[Schema::TYPE_TIME, $this->time(), 'time'], [
[Schema::TYPE_TIME . " CHECK (value BETWEEN '12:00:00' AND '13:01:01')", $this->time()->check("value BETWEEN '12:00:00' AND '13:01:01'"), "time CHECK (value BETWEEN '12:00:00' AND '13:01:01')"], Schema::TYPE_BIGINT,
[Schema::TYPE_TIME . ' NOT NULL', $this->time()->notNull(), 'time NOT NULL'], $this->bigInteger(),
[Schema::TYPE_DATE, $this->date(), 'date'], [
[Schema::TYPE_DATE . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')", $this->date()->check("value BETWEEN '2011-01-01' AND '2013-01-01'"), "date CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')"], 'mysql' => 'bigint(20)',
[Schema::TYPE_DATE . ' NOT NULL', $this->date()->notNull(), 'date NOT NULL'], 'postgres' => 'bigint',
[Schema::TYPE_BINARY, $this->binary(), 'blob'], 'sqlite' => 'bigint',
[Schema::TYPE_BOOLEAN, $this->boolean(), 'tinyint(1)'], 'oci' => 'NUMBER(20)',
[Schema::TYPE_BOOLEAN . ' NOT NULL DEFAULT 1', $this->boolean()->notNull()->defaultValue(1), 'tinyint(1) NOT NULL DEFAULT 1'], 'sqlsrv' => 'bigint',
[Schema::TYPE_MONEY, $this->money(), 'decimal(19,4)'], 'cubrid' => 'bigint',
[Schema::TYPE_MONEY . '(16,2)', $this->money(16, 2), 'decimal(16,2)'], ],
[Schema::TYPE_MONEY . ' CHECK (value > 0.0)', $this->money()->check('value > 0.0'), 'decimal(19,4) CHECK (value > 0.0)'], ],
[Schema::TYPE_MONEY . '(16,2) CHECK (value > 0.0)', $this->money(16, 2)->check('value > 0.0'), 'decimal(16,2) CHECK (value > 0.0)'], [
[Schema::TYPE_MONEY . ' NOT NULL', $this->money()->notNull(), 'decimal(19,4) NOT NULL'], Schema::TYPE_BIGPK,
$this->bigPrimaryKey(),
[
'mysql' => 'bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY',
'postgres' => 'bigserial NOT NULL PRIMARY KEY',
'sqlite' => 'bigint PRIMARY KEY AUTOINCREMENT NOT NULL',
],
],
[
Schema::TYPE_BINARY,
$this->binary(),
[
'mysql' => 'blob',
'postgres' => 'bytea',
'sqlite' => 'blob',
'oci' => 'BLOB',
'sqlsrv' => 'blob',
'cubrid' => 'blob',
],
],
[
Schema::TYPE_BOOLEAN . ' NOT NULL DEFAULT 1',
$this->boolean()->notNull()->defaultValue(1),
[
'mysql' => 'tinyint(1) NOT NULL DEFAULT 1',
'sqlite' => 'boolean NOT NULL DEFAULT 1',
'sqlsrv' => 'tinyint(1) NOT NULL DEFAULT 1',
'cubrid' => 'smallint NOT NULL DEFAULT 1',
],
],
[
Schema::TYPE_BOOLEAN,
$this->boolean(),
[
'mysql' => 'tinyint(1)',
'postgres' => 'boolean',
'sqlite' => 'boolean',
'oci' => 'NUMBER(1)',
'sqlsrv' => 'tinyint(1)',
'cubrid' => 'smallint',
],
],
[
Schema::TYPE_CHAR . ' CHECK (value LIKE "test%")',
$this->char()->check('value LIKE "test%"'),
[
'mysql' => 'char(1) CHECK (value LIKE "test%")',
'sqlite' => 'char(1) CHECK (value LIKE "test%")',
'oci' => 'CHAR(1) CHECK (value LIKE "test%")',
'cubrid' => 'char(1) CHECK (value LIKE "test%")',
],
],
[
Schema::TYPE_CHAR . ' NOT NULL',
$this->char()->notNull(),
[
'mysql' => 'char(1) NOT NULL',
'postgres' => 'char(1) NOT NULL',
'sqlite' => 'char(1) NOT NULL',
'oci' => 'CHAR(1) NOT NULL',
'cubrid' => 'char(1) NOT NULL',
],
],
[
Schema::TYPE_CHAR . '(6) CHECK (value LIKE "test%")',
$this->char(6)->check('value LIKE "test%"'),
[
'mysql' => 'char(6) CHECK (value LIKE "test%")',
'sqlite' => 'char(6) CHECK (value LIKE "test%")',
'oci' => 'CHAR(6) CHECK (value LIKE "test%")',
'cubrid' => 'char(6) CHECK (value LIKE "test%")',
],
],
[
Schema::TYPE_CHAR . '(6)',
$this->char(6),
[
'mysql' => 'char(6)',
'postgres' => 'char(6)',
'sqlite' => 'char(6)',
'oci' => 'CHAR(6)',
'cubrid' => 'char(6)',
],
],
[
Schema::TYPE_CHAR,
$this->char(),
[
'mysql' => 'char(1)',
'postgres' => 'char(1)',
'sqlite' => 'char(1)',
'oci' => 'CHAR(1)',
'cubrid' => 'char(1)',
],
],
//[
// Schema::TYPE_DATE . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')",
// $this->date()->check("value BETWEEN '2011-01-01' AND '2013-01-01'"),
// [
// 'mysql' => ,
// 'postgres' => ,
// 'sqlite' => ,
// 'sqlsrv' => ,
// 'cubrid' => ,
// ],
//],
[
Schema::TYPE_DATE . ' NOT NULL',
$this->date()->notNull(),
[
'mysql' => 'date NOT NULL',
'postgres' => 'date NOT NULL',
'sqlite' => 'date NOT NULL',
'oci' => 'DATE NOT NULL',
'sqlsrv' => 'date NOT NULL',
'cubrid' => 'date NOT NULL',
],
],
[
Schema::TYPE_DATE,
$this->date(),
[
'mysql' => 'date',
'postgres' => 'date',
'sqlite' => 'date',
'oci' => 'DATE',
'sqlsrv' => 'date',
'cubrid' => 'date',
],
],
//[
// Schema::TYPE_DATETIME . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')",
// $this->dateTime()->check("value BETWEEN '2011-01-01' AND '2013-01-01'"),
// [
// 'mysql' => ,
// 'postgres' => ,
// 'sqlite' => ,
// 'sqlsrv' => ,
// 'cubrid' => ,
// ],
//],
[
Schema::TYPE_DATETIME . ' NOT NULL',
$this->dateTime()->notNull(),
[
'mysql' => 'datetime NOT NULL',
'postgres' => 'timestamp(0) NOT NULL',
'sqlite' => 'datetime NOT NULL',
'oci' => 'TIMESTAMP NOT NULL',
'sqlsrv' => 'datetime NOT NULL',
'cubrid' => 'datetime NOT NULL',
],
],
[
Schema::TYPE_DATETIME,
$this->dateTime(),
[
'mysql' => 'datetime',
'postgres' => 'timestamp(0)',
'sqlite' => 'datetime',
'oci' => 'TIMESTAMP',
'sqlsrv' => 'datetime',
'cubrid' => 'datetime',
],
],
[
Schema::TYPE_DECIMAL . ' CHECK (value > 5.6)',
$this->decimal()->check('value > 5.6'),
[
'mysql' => 'decimal(10,0) CHECK (value > 5.6)',
'postgres' => 'numeric(10,0) CHECK (value > 5.6)',
'sqlite' => 'decimal(10,0) CHECK (value > 5.6)',
'oci' => 'NUMBER CHECK (value > 5.6)',
'sqlsrv' => 'decimal CHECK (value > 5.6)',
'cubrid' => 'decimal(10,0) CHECK (value > 5.6)',
],
],
[
Schema::TYPE_DECIMAL . ' NOT NULL',
$this->decimal()->notNull(),
[
'mysql' => 'decimal(10,0) NOT NULL',
'postgres' => 'numeric(10,0) NOT NULL',
'sqlite' => 'decimal(10,0) NOT NULL',
'oci' => 'NUMBER NOT NULL',
'sqlsrv' => 'decimal NOT NULL',
'cubrid' => 'decimal(10,0) NOT NULL',
],
],
[
Schema::TYPE_DECIMAL . '(12,4) CHECK (value > 5.6)',
$this->decimal(12, 4)->check('value > 5.6'),
[
'mysql' => 'decimal(12,4) CHECK (value > 5.6)',
'postgres' => 'numeric(12,4) CHECK (value > 5.6)',
'sqlite' => 'decimal(12,4) CHECK (value > 5.6)',
'oci' => 'NUMBER CHECK (value > 5.6)',
'sqlsrv' => 'decimal CHECK (value > 5.6)',
'cubrid' => 'decimal(12,4) CHECK (value > 5.6)',
],
],
[
Schema::TYPE_DECIMAL . '(12,4)',
$this->decimal(12, 4),
[
'mysql' => 'decimal(12,4)',
'postgres' => 'numeric(12,4)',
'sqlite' => 'decimal(12,4)',
'oci' => 'NUMBER',
'sqlsrv' => 'decimal',
'cubrid' => 'decimal(12,4)',
],
],
[
Schema::TYPE_DECIMAL,
$this->decimal(),
[
'mysql' => 'decimal(10,0)',
'postgres' => 'numeric(10,0)',
'sqlite' => 'decimal(10,0)',
'oci' => 'NUMBER',
'sqlsrv' => 'decimal',
'cubrid' => 'decimal(10,0)',
],
],
[
Schema::TYPE_DOUBLE . ' CHECK (value > 5.6)',
$this->double()->check('value > 5.6'),
[
'mysql' => 'double CHECK (value > 5.6)',
'postgres' => 'double precision CHECK (value > 5.6)',
'sqlite' => 'double CHECK (value > 5.6)',
'oci' => 'NUMBER CHECK (value > 5.6)',
'sqlsrv' => 'float CHECK (value > 5.6)',
'cubrid' => 'double(15) CHECK (value > 5.6)',
],
],
[
Schema::TYPE_DOUBLE . ' NOT NULL',
$this->double()->notNull(),
[
'mysql' => 'double NOT NULL',
'postgres' => 'double precision NOT NULL',
'sqlite' => 'double NOT NULL',
'oci' => 'NUMBER NOT NULL',
'sqlsrv' => 'float NOT NULL',
'cubrid' => 'double(15) NOT NULL',
],
],
[
Schema::TYPE_DOUBLE . '(16) CHECK (value > 5.6)',
$this->double(16)->check('value > 5.6'),
[
'mysql' => 'double CHECK (value > 5.6)',
'postgres' => 'double precision CHECK (value > 5.6)',
'sqlite' => 'double CHECK (value > 5.6)',
'oci' => 'NUMBER CHECK (value > 5.6)',
'sqlsrv' => 'float CHECK (value > 5.6)',
'cubrid' => 'double(16) CHECK (value > 5.6)',
],
],
[
Schema::TYPE_DOUBLE . '(16)',
$this->double(16),
[
'mysql' => 'double',
'sqlite' => 'double',
'oci' => 'NUMBER',
'sqlsrv' => 'float',
'cubrid' => 'double(16)',
],
],
[
Schema::TYPE_DOUBLE,
$this->double(),
[
'mysql' => 'double',
'postgres' => 'double precision',
'sqlite' => 'double',
'oci' => 'NUMBER',
'sqlsrv' => 'float',
'cubrid' => 'double(15)',
],
],
[
Schema::TYPE_FLOAT . ' CHECK (value > 5.6)',
$this->float()->check('value > 5.6'),
[
'mysql' => 'float CHECK (value > 5.6)',
'postgres' => 'double precision CHECK (value > 5.6)',
'sqlite' => 'float CHECK (value > 5.6)',
'oci' => 'NUMBER CHECK (value > 5.6)',
'sqlsrv' => 'float CHECK (value > 5.6)',
'cubrid' => 'float(7) CHECK (value > 5.6)',
],
],
[
Schema::TYPE_FLOAT . ' NOT NULL',
$this->float()->notNull(),
[
'mysql' => 'float NOT NULL',
'postgres' => 'double precision NOT NULL',
'sqlite' => 'float NOT NULL',
'oci' => 'NUMBER NOT NULL',
'sqlsrv' => 'float NOT NULL',
'cubrid' => 'float(7) NOT NULL',
],
],
[
Schema::TYPE_FLOAT . '(16) CHECK (value > 5.6)',
$this->float(16)->check('value > 5.6'),
[
'mysql' => 'float CHECK (value > 5.6)',
'postgres' => 'double precision CHECK (value > 5.6)',
'sqlite' => 'float CHECK (value > 5.6)',
'oci' => 'NUMBER CHECK (value > 5.6)',
'sqlsrv' => 'float CHECK (value > 5.6)',
'cubrid' => 'float(16) CHECK (value > 5.6)',
],
],
[
Schema::TYPE_FLOAT . '(16)',
$this->float(16),
[
'mysql' => 'float',
'sqlite' => 'float',
'oci' => 'NUMBER',
'sqlsrv' => 'float',
'cubrid' => 'float(16)',
],
],
[
Schema::TYPE_FLOAT,
$this->float(),
[
'mysql' => 'float',
'postgres' => 'double precision',
'sqlite' => 'float',
'oci' => 'NUMBER',
'sqlsrv' => 'float',
'cubrid' => 'float(7)',
],
],
[
Schema::TYPE_INTEGER . ' CHECK (value > 5)',
$this->integer()->check('value > 5'),
[
'mysql' => 'int(11) CHECK (value > 5)',
'postgres' => 'integer CHECK (value > 5)',
'sqlite' => 'integer CHECK (value > 5)',
'oci' => 'NUMBER(10) CHECK (value > 5)',
'sqlsrv' => 'int CHECK (value > 5)',
'cubrid' => 'int CHECK (value > 5)',
],
],
[
Schema::TYPE_INTEGER . ' NOT NULL',
$this->integer()->notNull(),
[
'mysql' => 'int(11) NOT NULL',
'postgres' => 'integer NOT NULL',
'sqlite' => 'integer NOT NULL',
'oci' => 'NUMBER(10) NOT NULL',
'sqlsrv' => 'int NOT NULL',
'cubrid' => 'int NOT NULL',
],
],
[
Schema::TYPE_INTEGER . '(8) CHECK (value > 5)',
$this->integer(8)->check('value > 5'),
[
'mysql' => 'int(8) CHECK (value > 5)',
'postgres' => 'integer CHECK (value > 5)',
'sqlite' => 'integer CHECK (value > 5)',
'oci' => 'NUMBER(8) CHECK (value > 5)',
'sqlsrv' => 'int CHECK (value > 5)',
'cubrid' => 'int CHECK (value > 5)',
],
],
[
Schema::TYPE_INTEGER . '(8)',
$this->integer(8),
[
'mysql' => 'int(8)',
'postgres' => 'integer',
'sqlite' => 'integer',
'oci' => 'NUMBER(8)',
'sqlsrv' => 'int',
'cubrid' => 'int',
],
],
[
Schema::TYPE_INTEGER,
$this->integer(),
[
'mysql' => 'int(11)',
'postgres' => 'integer',
'sqlite' => 'integer',
'oci' => 'NUMBER(10)',
'sqlsrv' => 'int',
'cubrid' => 'int',
],
],
[
Schema::TYPE_MONEY . ' CHECK (value > 0.0)',
$this->money()->check('value > 0.0'),
[
'mysql' => 'decimal(19,4) CHECK (value > 0.0)',
'postgres' => 'numeric(19,4) CHECK (value > 0.0)',
'sqlite' => 'decimal(19,4) CHECK (value > 0.0)',
'oci' => 'NUMBER(19,4) CHECK (value > 0.0)',
'sqlsrv' => 'decimal(19,4) CHECK (value > 0.0)',
'cubrid' => 'decimal(19,4) CHECK (value > 0.0)',
],
],
[
Schema::TYPE_MONEY . ' NOT NULL',
$this->money()->notNull(),
[
'mysql' => 'decimal(19,4) NOT NULL',
'postgres' => 'numeric(19,4) NOT NULL',
'sqlite' => 'decimal(19,4) NOT NULL',
'oci' => 'NUMBER(19,4) NOT NULL',
'sqlsrv' => 'decimal(19,4) NOT NULL',
'cubrid' => 'decimal(19,4) NOT NULL',
],
],
[
Schema::TYPE_MONEY . '(16,2) CHECK (value > 0.0)',
$this->money(16, 2)->check('value > 0.0'),
[
'mysql' => 'decimal(16,2) CHECK (value > 0.0)',
'postgres' => 'numeric(16,2) CHECK (value > 0.0)',
'sqlite' => 'decimal(16,2) CHECK (value > 0.0)',
'oci' => 'NUMBER(16,2) CHECK (value > 0.0)',
'sqlsrv' => 'decimal(16,2) CHECK (value > 0.0)',
'cubrid' => 'decimal(16,2) CHECK (value > 0.0)',
],
],
[
Schema::TYPE_MONEY . '(16,2)',
$this->money(16, 2),
[
'mysql' => 'decimal(16,2)',
'postgres' => 'numeric(16,2)',
'sqlite' => 'decimal(16,2)',
'oci' => 'NUMBER(16,2)',
'sqlsrv' => 'decimal(16,2)',
'cubrid' => 'decimal(16,2)',
],
],
[
Schema::TYPE_MONEY,
$this->money(),
[
'mysql' => 'decimal(19,4)',
'postgres' => 'numeric(19,4)',
'sqlite' => 'decimal(19,4)',
'oci' => 'NUMBER(19,4)',
'sqlsrv' => 'decimal(19,4)',
'cubrid' => 'decimal(19,4)',
],
],
[
Schema::TYPE_PK . ' CHECK (value > 5)',
$this->primaryKey()->check('value > 5'),
[
'mysql' => 'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY CHECK (value > 5)',
'postgres' => 'serial NOT NULL PRIMARY KEY CHECK (value > 5)',
'sqlite' => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL CHECK (value > 5)',
'oci' => 'NUMBER(10) NOT NULL PRIMARY KEY CHECK (value > 5)',
'sqlsrv' => 'int IDENTITY PRIMARY KEY CHECK (value > 5)',
'cubrid' => 'int NOT NULL AUTO_INCREMENT PRIMARY KEY CHECK (value > 5)',
],
],
[
Schema::TYPE_PK . '(8) CHECK (value > 5)',
$this->primaryKey(8)->check('value > 5'),
[
'mysql' => 'int(8) NOT NULL AUTO_INCREMENT PRIMARY KEY CHECK (value > 5)',
'oci' => 'NUMBER(8) NOT NULL PRIMARY KEY CHECK (value > 5)',
],
],
[
Schema::TYPE_PK . '(8)',
$this->primaryKey(8),
[
'mysql' => 'int(8) NOT NULL AUTO_INCREMENT PRIMARY KEY',
'oci' => 'NUMBER(8) NOT NULL PRIMARY KEY',
],
],
[
Schema::TYPE_PK,
$this->primaryKey(),
[
'mysql' => 'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY',
'postgres' => 'serial NOT NULL PRIMARY KEY',
'sqlite' => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL',
'oci' => 'NUMBER(10) NOT NULL PRIMARY KEY',
'sqlsrv' => 'int IDENTITY PRIMARY KEY',
'cubrid' => 'int NOT NULL AUTO_INCREMENT PRIMARY KEY',
],
],
[
Schema::TYPE_SMALLINT . '(8)',
$this->smallInteger(8),
[
'mysql' => 'smallint(8)',
'postgres' => 'smallint',
'sqlite' => 'smallint',
'oci' => 'NUMBER(8)',
'sqlsrv' => 'smallint',
'cubrid' => 'smallint',
],
],
[
Schema::TYPE_SMALLINT,
$this->smallInteger(),
[
'mysql' => 'smallint(6)',
'postgres' => 'smallint',
'sqlite' => 'smallint',
'oci' => 'NUMBER(5)',
'sqlsrv' => 'smallint',
'cubrid' => 'smallint',
],
],
[
Schema::TYPE_STRING . ' CHECK (value LIKE "test%")',
$this->string()->check('value LIKE "test%"'),
[
'mysql' => 'varchar(255) CHECK (value LIKE "test%")',
'sqlite' => 'varchar(255) CHECK (value LIKE "test%")',
'sqlsrv' => 'varchar(255) CHECK (value LIKE "test%")',
'cubrid' => 'varchar(255) CHECK (value LIKE "test%")',
],
],
[
Schema::TYPE_STRING . ' CHECK (value LIKE \'test%\')',
$this->string()->check('value LIKE \'test%\''),
[
'postgres' => 'varchar(255) CHECK (value LIKE \'test%\')',
'oci' => 'VARCHAR2(255) CHECK (value LIKE \'test%\')',
],
],
[
Schema::TYPE_STRING . ' NOT NULL',
$this->string()->notNull(),
[
'mysql' => 'varchar(255) NOT NULL',
'postgres' => 'varchar(255) NOT NULL',
'sqlite' => 'varchar(255) NOT NULL',
'oci' => 'VARCHAR2(255) NOT NULL',
'sqlsrv' => 'varchar(255) NOT NULL',
'cubrid' => 'varchar(255) NOT NULL',
],
],
[
Schema::TYPE_STRING . '(32) CHECK (value LIKE "test%")',
$this->string(32)->check('value LIKE "test%"'),
[
'mysql' => 'varchar(32) CHECK (value LIKE "test%")',
'sqlite' => 'varchar(32) CHECK (value LIKE "test%")',
'sqlsrv' => 'varchar(32) CHECK (value LIKE "test%")',
'cubrid' => 'varchar(32) CHECK (value LIKE "test%")',
],
],
[
Schema::TYPE_STRING . '(32) CHECK (value LIKE \'test%\')',
$this->string(32)->check('value LIKE \'test%\''),
[
'postgres' => 'varchar(32) CHECK (value LIKE \'test%\')',
'oci' => 'VARCHAR2(32) CHECK (value LIKE \'test%\')',
],
],
[
Schema::TYPE_STRING . '(32)',
$this->string(32),
[
'mysql' => 'varchar(32)',
'postgres' => 'varchar(32)',
'sqlite' => 'varchar(32)',
'oci' => 'VARCHAR2(32)',
'sqlsrv' => 'varchar(32)',
'cubrid' => 'varchar(32)',
],
],
[
Schema::TYPE_STRING,
$this->string(),
[
'mysql' => 'varchar(255)',
'postgres' => 'varchar(255)',
'sqlite' => 'varchar(255)',
'oci' => 'VARCHAR2(255)',
'sqlsrv' => 'varchar(255)',
'cubrid' => 'varchar(255)',
],
],
[
Schema::TYPE_TEXT . ' CHECK (value LIKE "test%")',
$this->text()->check('value LIKE "test%"'),
[
'mysql' => 'text CHECK (value LIKE "test%")',
'sqlite' => 'text CHECK (value LIKE "test%")',
'sqlsrv' => 'text CHECK (value LIKE "test%")',
'cubrid' => 'varchar CHECK (value LIKE "test%")',
],
],
[
Schema::TYPE_TEXT . ' CHECK (value LIKE \'test%\')',
$this->text()->check('value LIKE \'test%\''),
[
'postgres' => 'text CHECK (value LIKE \'test%\')',
'oci' => 'CLOB CHECK (value LIKE \'test%\')',
],
],
[
Schema::TYPE_TEXT . ' NOT NULL',
$this->text()->notNull(),
[
'mysql' => 'text NOT NULL',
'postgres' => 'text NOT NULL',
'sqlite' => 'text NOT NULL',
'oci' => 'CLOB NOT NULL',
'sqlsrv' => 'text NOT NULL',
'cubrid' => 'varchar NOT NULL',
],
],
[
Schema::TYPE_TEXT . '(255) CHECK (value LIKE "test%")',
$this->text(255)->check('value LIKE "test%"'),
[
'mysql' => 'text CHECK (value LIKE "test%")',
'sqlite' => 'text CHECK (value LIKE "test%")',
'sqlsrv' => 'text CHECK (value LIKE "test%")',
'cubrid' => 'varchar CHECK (value LIKE "test%")',
],
Schema::TYPE_TEXT . ' CHECK (value LIKE "test%")',
],
[
Schema::TYPE_TEXT . '(255) CHECK (value LIKE \'test%\')',
$this->text(255)->check('value LIKE \'test%\''),
[
'postgres' => 'text CHECK (value LIKE \'test%\')',
'oci' => 'CLOB CHECK (value LIKE \'test%\')',
],
Schema::TYPE_TEXT . ' CHECK (value LIKE \'test%\')',
],
[
Schema::TYPE_TEXT . '(255) NOT NULL',
$this->text(255)->notNull(),
[
'mysql' => 'text NOT NULL',
'postgres' => 'text NOT NULL',
'sqlite' => 'text NOT NULL',
'oci' => 'CLOB NOT NULL',
'sqlsrv' => 'text NOT NULL',
'cubrid' => 'varchar NOT NULL',
],
Schema::TYPE_TEXT . ' NOT NULL',
],
[
Schema::TYPE_TEXT . '(255)',
$this->text(255),
[
'mysql' => 'text',
'postgres' => 'text',
'sqlite' => 'text',
'oci' => 'CLOB',
'sqlsrv' => 'text',
'cubrid' => 'varchar',
],
Schema::TYPE_TEXT,
],
[
Schema::TYPE_TEXT,
$this->text(),
[
'mysql' => 'text',
'postgres' => 'text',
'sqlite' => 'text',
'oci' => 'CLOB',
'sqlsrv' => 'text',
'cubrid' => 'varchar',
],
],
//[
// Schema::TYPE_TIME . " CHECK (value BETWEEN '12:00:00' AND '13:01:01')",
// $this->time()->check("value BETWEEN '12:00:00' AND '13:01:01'"),
// [
// 'mysql' => ,
// 'postgres' => ,
// 'sqlite' => ,
// 'sqlsrv' => ,
// 'cubrid' => ,
// ],
//],
[
Schema::TYPE_TIME . ' NOT NULL',
$this->time()->notNull(),
[
'mysql' => 'time NOT NULL',
'postgres' => 'time(0) NOT NULL',
'sqlite' => 'time NOT NULL',
'oci' => 'TIMESTAMP NOT NULL',
'sqlsrv' => 'time NOT NULL',
'cubrid' => 'time NOT NULL',
],
],
[
Schema::TYPE_TIME,
$this->time(),
[
'mysql' => 'time',
'postgres' => 'time(0)',
'sqlite' => 'time',
'oci' => 'TIMESTAMP',
'sqlsrv' => 'time',
'cubrid' => 'time',
],
],
//[
// Schema::TYPE_TIMESTAMP . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')",
// $this->timestamp()->check("value BETWEEN '2011-01-01' AND '2013-01-01'"),
// [
// 'mysql' => ,
// 'postgres' => ,
// 'sqlite' => ,
// 'sqlsrv' => ,
// 'cubrid' => ,
// ],
//],
[
Schema::TYPE_TIMESTAMP . ' NOT NULL',
$this->timestamp()->notNull(),
[
'mysql' => 'timestamp NOT NULL',
'postgres' => 'timestamp(0) NOT NULL',
'sqlite' => 'timestamp NOT NULL',
'oci' => 'TIMESTAMP NOT NULL',
'sqlsrv' => 'timestamp NOT NULL',
'cubrid' => 'timestamp NOT NULL',
],
],
[
Schema::TYPE_TIMESTAMP,
$this->timestamp(),
[
'mysql' => 'timestamp',
'postgres' => 'timestamp(0)',
'sqlite' => 'timestamp',
'oci' => 'TIMESTAMP',
'sqlsrv' => 'timestamp',
'cubrid' => 'timestamp',
],
],
[
Schema::TYPE_UPK,
$this->primaryKey()->unsigned(),
[
'mysql' => 'int(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY',
'postgres' => 'serial NOT NULL PRIMARY KEY',
'sqlite' => 'integer UNSIGNED PRIMARY KEY AUTOINCREMENT NOT NULL',
],
],
[
Schema::TYPE_UBIGPK,
$this->bigPrimaryKey()->unsigned(),
[
'mysql' => 'bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY',
'postgres' => 'bigserial NOT NULL PRIMARY KEY',
'sqlite' => 'bigint UNSIGNED PRIMARY KEY AUTOINCREMENT NOT NULL',
],
],
]; ];
foreach ($items as $i => $item) {
if (array_key_exists($this->driverName, $item[2])) {
$item[2] = $item[2][$this->driverName];
$items[$i] = $item;
}
else {
unset($items[$i]);
}
}
return array_values($items);
} }
public function testGetColumnType() public function testGetColumnType()
@ -172,7 +954,10 @@ class QueryBuilderTest extends DatabaseTestCase
$i = 0; $i = 0;
foreach ($this->columnTypes() as $item) { foreach ($this->columnTypes() as $item) {
list ($column, $builder, $expected) = $item; list ($column, $builder, $expected) = $item;
if (strncmp($column, 'pk', 2) !== 0) { if (!(strncmp($column, Schema::TYPE_PK, 2) === 0 ||
strncmp($column, Schema::TYPE_UPK, 3) === 0 ||
strncmp($column, Schema::TYPE_BIGPK, 5) === 0 ||
strncmp($column, Schema::TYPE_UBIGPK, 6) === 0)) {
$columns['col' . ++$i] = str_replace('CHECK (value', 'CHECK ([[col' . $i . ']]', $column); $columns['col' . ++$i] = str_replace('CHECK (value', 'CHECK ([[col' . $i . ']]', $column);
} }
} }

26
tests/framework/db/SchemaTest.php

@ -184,7 +184,7 @@ class SchemaTest extends DatabaseTestCase
'defaultValue' => 1, 'defaultValue' => 1,
], ],
'char_col' => [ 'char_col' => [
'type' => 'string', 'type' => 'char',
'dbType' => 'char(100)', 'dbType' => 'char(100)',
'phpType' => 'string', 'phpType' => 'string',
'allowNull' => false, 'allowNull' => false,
@ -356,20 +356,20 @@ class SchemaTest extends DatabaseTestCase
foreach($table->columns as $name => $column) { foreach($table->columns as $name => $column) {
$expected = $columns[$name]; $expected = $columns[$name];
$this->assertSame($expected['dbType'], $column->dbType, "dbType of colum $name does not match. type is $column->type, dbType is $column->dbType."); $this->assertSame($expected['dbType'], $column->dbType, "dbType of column $name does not match. type is $column->type, dbType is $column->dbType.");
$this->assertSame($expected['phpType'], $column->phpType, "phpType of colum $name does not match. type is $column->type, dbType is $column->dbType."); $this->assertSame($expected['phpType'], $column->phpType, "phpType of column $name does not match. type is $column->type, dbType is $column->dbType.");
$this->assertSame($expected['type'], $column->type, "type of colum $name does not match."); $this->assertSame($expected['type'], $column->type, "type of column $name does not match.");
$this->assertSame($expected['allowNull'], $column->allowNull, "allowNull of colum $name does not match."); $this->assertSame($expected['allowNull'], $column->allowNull, "allowNull of column $name does not match.");
$this->assertSame($expected['autoIncrement'], $column->autoIncrement, "autoIncrement of colum $name does not match."); $this->assertSame($expected['autoIncrement'], $column->autoIncrement, "autoIncrement of column $name does not match.");
$this->assertSame($expected['enumValues'], $column->enumValues, "enumValues of colum $name does not match."); $this->assertSame($expected['enumValues'], $column->enumValues, "enumValues of column $name does not match.");
$this->assertSame($expected['size'], $column->size, "size of colum $name does not match."); $this->assertSame($expected['size'], $column->size, "size of column $name does not match.");
$this->assertSame($expected['precision'], $column->precision, "precision of colum $name does not match."); $this->assertSame($expected['precision'], $column->precision, "precision of column $name does not match.");
$this->assertSame($expected['scale'], $column->scale, "scale of colum $name does not match."); $this->assertSame($expected['scale'], $column->scale, "scale of column $name does not match.");
if (is_object($expected['defaultValue'])) { if (is_object($expected['defaultValue'])) {
$this->assertTrue(is_object($column->defaultValue), "defaultValue of colum $name is expected to be an object but it is not."); $this->assertTrue(is_object($column->defaultValue), "defaultValue of column $name is expected to be an object but it is not.");
$this->assertEquals((string) $expected['defaultValue'], (string) $column->defaultValue, "defaultValue of colum $name does not match."); $this->assertEquals((string) $expected['defaultValue'], (string) $column->defaultValue, "defaultValue of column $name does not match.");
} else { } else {
$this->assertSame($expected['defaultValue'], $column->defaultValue, "defaultValue of colum $name does not match."); $this->assertSame($expected['defaultValue'], $column->defaultValue, "defaultValue of column $name does not match.");
} }
} }
} }

10
tests/framework/db/pgsql/ColumnSchemaBuilderTest.php → tests/framework/db/cubrid/ColumnSchemaBuilderTest.php

@ -1,12 +1,12 @@
<?php <?php
namespace yiiunit\framework\db\pgsql; namespace yiiunit\framework\db\cubrid;
use yii\db\pgsql\ColumnSchemaBuilder; use yii\db\cubrid\ColumnSchemaBuilder;
use yii\db\Schema; use yii\db\Schema;
use \yiiunit\framework\db\ColumnSchemaBuilderTest as BaseColumnSchemaBuilderTest; use \yiiunit\framework\db\ColumnSchemaBuilderTest as BaseColumnSchemaBuilderTest;
/** /**
* ColumnSchemaBuilderTest tests ColumnSchemaBuilder for PostgreSQL * ColumnSchemaBuilderTest tests ColumnSchemaBuilder for Cubrid
*/ */
class ColumnSchemaBuilderTest extends BaseColumnSchemaBuilderTest class ColumnSchemaBuilderTest extends BaseColumnSchemaBuilderTest
{ {
@ -26,10 +26,10 @@ class ColumnSchemaBuilderTest extends BaseColumnSchemaBuilderTest
public function unsignedProvider() public function unsignedProvider()
{ {
return [ return [
['integer', Schema::TYPE_INTEGER, null, [ ['integer UNSIGNED', Schema::TYPE_INTEGER, null, [
['unsigned'], ['unsigned'],
]], ]],
['integer(10)', Schema::TYPE_INTEGER, 10, [ ['integer(10) UNSIGNED', Schema::TYPE_INTEGER, 10, [
['unsigned'], ['unsigned'],
]], ]],
]; ];

65
tests/framework/db/cubrid/CubridQueryBuilderTest.php

@ -19,69 +19,6 @@ class CubridQueryBuilderTest extends QueryBuilderTest
*/ */
public function columnTypes() public function columnTypes()
{ {
return [ return array_merge(parent::columnTypes(), []);
[Schema::TYPE_PK, $this->primaryKey(), 'int NOT NULL AUTO_INCREMENT PRIMARY KEY'],
[Schema::TYPE_PK . '(8)', $this->primaryKey(8), 'int NOT NULL AUTO_INCREMENT PRIMARY KEY'],
[Schema::TYPE_PK . ' CHECK (value > 5)', $this->primaryKey()->check('value > 5'), 'int NOT NULL AUTO_INCREMENT PRIMARY KEY CHECK (value > 5)'],
[Schema::TYPE_PK . '(8) CHECK (value > 5)', $this->primaryKey(8)->check('value > 5'), 'int NOT NULL AUTO_INCREMENT PRIMARY KEY CHECK (value > 5)'],
[Schema::TYPE_STRING, $this->string(), 'varchar(255)'],
[Schema::TYPE_STRING . '(32)', $this->string(32), 'varchar(32)'],
[Schema::TYPE_STRING . ' CHECK (value LIKE "test%")', $this->string()->check('value LIKE "test%"'), 'varchar(255) CHECK (value LIKE "test%")'],
[Schema::TYPE_STRING . '(32) CHECK (value LIKE "test%")', $this->string(32)->check('value LIKE "test%"'), 'varchar(32) CHECK (value LIKE "test%")'],
[Schema::TYPE_STRING . ' NOT NULL', $this->string()->notNull(), 'varchar(255) NOT NULL'],
[Schema::TYPE_TEXT, $this->text(), 'varchar'],
[Schema::TYPE_TEXT . '(255)', $this->text(), 'varchar', Schema::TYPE_TEXT],
[Schema::TYPE_TEXT . ' CHECK (value LIKE "test%")', $this->text()->check('value LIKE "test%"'), 'varchar CHECK (value LIKE "test%")'],
[Schema::TYPE_TEXT . '(255) CHECK (value LIKE "test%")', $this->text()->check('value LIKE "test%"'), 'varchar CHECK (value LIKE "test%")', Schema::TYPE_TEXT . ' CHECK (value LIKE "test%")'],
[Schema::TYPE_TEXT . ' NOT NULL', $this->text()->notNull(), 'varchar NOT NULL'],
[Schema::TYPE_TEXT . '(255) NOT NULL', $this->text()->notNull(), 'varchar NOT NULL', Schema::TYPE_TEXT . ' NOT NULL'],
[Schema::TYPE_SMALLINT, $this->smallInteger(), 'smallint'],
[Schema::TYPE_SMALLINT . '(8)', $this->smallInteger(8), 'smallint'],
[Schema::TYPE_INTEGER, $this->integer(), 'int'],
[Schema::TYPE_INTEGER . '(8)', $this->integer(8), 'int'],
[Schema::TYPE_INTEGER . ' CHECK (value > 5)', $this->integer()->check('value > 5'), 'int CHECK (value > 5)'],
[Schema::TYPE_INTEGER . '(8) CHECK (value > 5)', $this->integer(8)->check('value > 5'), 'int CHECK (value > 5)'],
[Schema::TYPE_INTEGER . ' NOT NULL', $this->integer()->notNull(), 'int NOT NULL'],
[Schema::TYPE_BIGINT, $this->bigInteger(), 'bigint'],
[Schema::TYPE_BIGINT . '(8)', $this->bigInteger(8), 'bigint'],
[Schema::TYPE_BIGINT . ' CHECK (value > 5)', $this->bigInteger()->check('value > 5'), 'bigint CHECK (value > 5)'],
[Schema::TYPE_BIGINT . '(8) CHECK (value > 5)', $this->bigInteger(8)->check('value > 5'), 'bigint CHECK (value > 5)'],
[Schema::TYPE_BIGINT . ' NOT NULL', $this->bigInteger()->notNull(), 'bigint NOT NULL'],
[Schema::TYPE_FLOAT, $this->float(), 'float(7)'],
[Schema::TYPE_FLOAT . '(16)', $this->float(16), 'float(16)'],
[Schema::TYPE_FLOAT . ' CHECK (value > 5.6)', $this->float()->check('value > 5.6'), 'float(7) CHECK (value > 5.6)'],
[Schema::TYPE_FLOAT . '(16) CHECK (value > 5.6)', $this->float(16)->check('value > 5.6'), 'float(16) CHECK (value > 5.6)'],
[Schema::TYPE_FLOAT . ' NOT NULL', $this->float()->notNull(), 'float(7) NOT NULL'],
[Schema::TYPE_DOUBLE, $this->double(), 'double(15)'],
[Schema::TYPE_DOUBLE . '(16)', $this->double(16), 'double(16)'],
[Schema::TYPE_DOUBLE . ' CHECK (value > 5.6)', $this->double()->check('value > 5.6'), 'double(15) CHECK (value > 5.6)'],
[Schema::TYPE_DOUBLE . '(16) CHECK (value > 5.6)', $this->double(16)->check('value > 5.6'), 'double(16) CHECK (value > 5.6)'],
[Schema::TYPE_DOUBLE . ' NOT NULL', $this->double()->notNull(), 'double(15) NOT NULL'],
[Schema::TYPE_DECIMAL, $this->decimal(), 'decimal(10,0)'],
[Schema::TYPE_DECIMAL . '(12,4)', $this->decimal(12, 4), 'decimal(12,4)'],
[Schema::TYPE_DECIMAL . ' CHECK (value > 5.6)', $this->decimal()->check('value > 5.6'), 'decimal(10,0) CHECK (value > 5.6)'],
[Schema::TYPE_DECIMAL . '(12,4) CHECK (value > 5.6)', $this->decimal(12, 4)->check('value > 5.6'), 'decimal(12,4) CHECK (value > 5.6)'],
[Schema::TYPE_DECIMAL . ' NOT NULL', $this->decimal()->notNull(), 'decimal(10,0) NOT NULL'],
[Schema::TYPE_DATETIME, $this->dateTime(), 'datetime'],
[Schema::TYPE_DATETIME . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')", $this->dateTime()->check("value BETWEEN '2011-01-01' AND '2013-01-01'"), "datetime CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')"],
[Schema::TYPE_DATETIME . ' NOT NULL', $this->dateTime()->notNull(), 'datetime NOT NULL'],
[Schema::TYPE_TIMESTAMP, $this->timestamp(), 'timestamp'],
[Schema::TYPE_TIMESTAMP . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')", $this->timestamp()->check("value BETWEEN '2011-01-01' AND '2013-01-01'"), "timestamp CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')"],
[Schema::TYPE_TIMESTAMP . ' NOT NULL', $this->timestamp()->notNull(), 'timestamp NOT NULL'],
[Schema::TYPE_TIME, $this->time(), 'time'],
[Schema::TYPE_TIME . " CHECK (value BETWEEN '12:00:00' AND '13:01:01')", $this->time()->check("value BETWEEN '12:00:00' AND '13:01:01'"), "time CHECK (value BETWEEN '12:00:00' AND '13:01:01')"],
[Schema::TYPE_TIME . ' NOT NULL', $this->time()->notNull(), 'time NOT NULL'],
[Schema::TYPE_DATE, $this->date(), 'date'],
[Schema::TYPE_DATE . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')", $this->date()->check("value BETWEEN '2011-01-01' AND '2013-01-01'"), "date CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')"],
[Schema::TYPE_DATE . ' NOT NULL', $this->date()->notNull(), 'date NOT NULL'],
[Schema::TYPE_BINARY, $this->binary(), 'blob'],
[Schema::TYPE_BOOLEAN, $this->boolean(), 'smallint'],
[Schema::TYPE_BOOLEAN . ' NOT NULL DEFAULT 1', $this->boolean()->notNull()->defaultValue(1), 'smallint NOT NULL DEFAULT 1'],
[Schema::TYPE_MONEY, $this->money(), 'decimal(19,4)'],
[Schema::TYPE_MONEY . '(16,2)', $this->money(16, 2), 'decimal(16,2)'],
[Schema::TYPE_MONEY . ' CHECK (value > 0.0)', $this->money()->check('value > 0.0'), 'decimal(19,4) CHECK (value > 0.0)'],
[Schema::TYPE_MONEY . '(16,2) CHECK (value > 0.0)', $this->money(16, 2)->check('value > 0.0'), 'decimal(16,2) CHECK (value > 0.0)'],
[Schema::TYPE_MONEY . ' NOT NULL', $this->money()->notNull(), 'decimal(19,4) NOT NULL'],
];
} }
} }

65
tests/framework/db/mssql/MssqlQueryBuilderTest.php

@ -62,69 +62,6 @@ class MssqlQueryBuilderTest extends QueryBuilderTest
*/ */
public function columnTypes() public function columnTypes()
{ {
return [ return array_merge(parent::columnTypes(), []);
[Schema::TYPE_PK, $this->primaryKey(), 'int IDENTITY PRIMARY KEY'],
[Schema::TYPE_PK . '(8)', $this->primaryKey(8), 'int IDENTITY PRIMARY KEY'],
[Schema::TYPE_PK . ' CHECK (value > 5)', $this->primaryKey()->check('value > 5'), 'int IDENTITY PRIMARY KEY CHECK (value > 5)'],
[Schema::TYPE_PK . '(8) CHECK (value > 5)', $this->primaryKey(8)->check('value > 5'), 'int IDENTITY PRIMARY KEY CHECK (value > 5)'],
[Schema::TYPE_STRING, $this->string(), 'varchar(255)'],
[Schema::TYPE_STRING . '(32)', $this->string(32), 'varchar(32)'],
//[Schema::TYPE_STRING . ' CHECK (value LIKE "test%")', $this->string()->check('value LIKE "test%"'), 'varchar(255) CHECK (value LIKE "test%")'],
//[Schema::TYPE_STRING . '(32) CHECK (value LIKE "test%")', $this->string(32)->check('value LIKE "test%"'), 'varchar(32) CHECK (value LIKE "test%")'],
[Schema::TYPE_STRING . ' NOT NULL', $this->string()->notNull(), 'varchar(255) NOT NULL'],
[Schema::TYPE_TEXT, $this->text(), 'text'],
[Schema::TYPE_TEXT . '(255)', $this->text(), 'text', Schema::TYPE_TEXT],
//[Schema::TYPE_TEXT . ' CHECK (value LIKE "test%")', $this->text()->check('value LIKE "test%"'), 'text CHECK (value LIKE "test%")'],
//[Schema::TYPE_TEXT . '(255) CHECK (value LIKE "test%")', $this->text()->check('value LIKE "test%"'), 'text CHECK (value LIKE "test%")', Schema::TYPE_TEXT . ' CHECK (value LIKE "test%")'],
[Schema::TYPE_TEXT . ' NOT NULL', $this->text()->notNull(), 'text NOT NULL'],
[Schema::TYPE_TEXT . '(255) NOT NULL', $this->text()->notNull(), 'text NOT NULL', Schema::TYPE_TEXT . ' NOT NULL'],
[Schema::TYPE_SMALLINT, $this->smallInteger(), 'smallint'],
[Schema::TYPE_SMALLINT . '(8)', $this->smallInteger(8), 'smallint'],
[Schema::TYPE_INTEGER, $this->integer(), 'int'],
[Schema::TYPE_INTEGER . '(8)', $this->integer(8), 'int'],
[Schema::TYPE_INTEGER . ' CHECK (value > 5)', $this->integer()->check('value > 5'), 'int CHECK (value > 5)'],
[Schema::TYPE_INTEGER . '(8) CHECK (value > 5)', $this->integer(8)->check('value > 5'), 'int CHECK (value > 5)'],
[Schema::TYPE_INTEGER . ' NOT NULL', $this->integer()->notNull(), 'int NOT NULL'],
[Schema::TYPE_BIGINT, $this->bigInteger(), 'bigint'],
[Schema::TYPE_BIGINT . '(8)', $this->bigInteger(8), 'bigint'],
[Schema::TYPE_BIGINT . ' CHECK (value > 5)', $this->bigInteger()->check('value > 5'), 'bigint CHECK (value > 5)'],
[Schema::TYPE_BIGINT . '(8) CHECK (value > 5)', $this->bigInteger(8)->check('value > 5'), 'bigint CHECK (value > 5)'],
[Schema::TYPE_BIGINT . ' NOT NULL', $this->bigInteger()->notNull(), 'bigint NOT NULL'],
[Schema::TYPE_FLOAT, $this->float(), 'float'],
[Schema::TYPE_FLOAT . '(16)', $this->float(16), 'float'],
[Schema::TYPE_FLOAT . ' CHECK (value > 5.6)', $this->float()->check('value > 5.6'), 'float CHECK (value > 5.6)'],
[Schema::TYPE_FLOAT . '(16) CHECK (value > 5.6)', $this->float(16)->check('value > 5.6'), 'float CHECK (value > 5.6)'],
[Schema::TYPE_FLOAT . ' NOT NULL', $this->float()->notNull(), 'float NOT NULL'],
[Schema::TYPE_DOUBLE, $this->double(), 'float'],
[Schema::TYPE_DOUBLE . '(16)', $this->double(16), 'float'],
[Schema::TYPE_DOUBLE . ' CHECK (value > 5.6)', $this->double()->check('value > 5.6'), 'float CHECK (value > 5.6)'],
[Schema::TYPE_DOUBLE . '(16) CHECK (value > 5.6)', $this->double(16)->check('value > 5.6'), 'float CHECK (value > 5.6)'],
[Schema::TYPE_DOUBLE . ' NOT NULL', $this->double()->notNull(), 'float NOT NULL'],
[Schema::TYPE_DECIMAL, $this->decimal(), 'decimal'],
[Schema::TYPE_DECIMAL . '(12,4)', $this->decimal(12, 4), 'decimal'],
[Schema::TYPE_DECIMAL . ' CHECK (value > 5.6)', $this->decimal()->check('value > 5.6'), 'decimal CHECK (value > 5.6)'],
[Schema::TYPE_DECIMAL . '(12,4) CHECK (value > 5.6)', $this->decimal(12, 4)->check('value > 5.6'), 'decimal CHECK (value > 5.6)'],
[Schema::TYPE_DECIMAL . ' NOT NULL', $this->decimal()->notNull(), 'decimal NOT NULL'],
[Schema::TYPE_DATETIME, $this->dateTime(), 'datetime'],
[Schema::TYPE_DATETIME . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')", $this->dateTime()->check("value BETWEEN '2011-01-01' AND '2013-01-01'"), "datetime CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')"],
[Schema::TYPE_DATETIME . ' NOT NULL', $this->dateTime()->notNull(), 'datetime NOT NULL'],
[Schema::TYPE_TIMESTAMP, $this->timestamp(), 'timestamp'],
[Schema::TYPE_TIMESTAMP . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')", $this->timestamp()->check("value BETWEEN '2011-01-01' AND '2013-01-01'"), "timestamp CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')"],
[Schema::TYPE_TIMESTAMP . ' NOT NULL', $this->timestamp()->notNull(), 'timestamp NOT NULL'],
[Schema::TYPE_TIME, $this->time(), 'time'],
[Schema::TYPE_TIME . " CHECK (value BETWEEN '12:00:00' AND '13:01:01')", $this->time()->check("value BETWEEN '12:00:00' AND '13:01:01'"), "time CHECK (value BETWEEN '12:00:00' AND '13:01:01')"],
[Schema::TYPE_TIME . ' NOT NULL', $this->time()->notNull(), 'time NOT NULL'],
[Schema::TYPE_DATE, $this->date(), 'date'],
[Schema::TYPE_DATE . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')", $this->date()->check("value BETWEEN '2011-01-01' AND '2013-01-01'"), "date CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')"],
[Schema::TYPE_DATE . ' NOT NULL', $this->date()->notNull(), 'date NOT NULL'],
[Schema::TYPE_BINARY, $this->binary(), 'blob'],
[Schema::TYPE_BOOLEAN, $this->boolean(), 'tinyint(1)'],
[Schema::TYPE_BOOLEAN . ' NOT NULL DEFAULT 1', $this->boolean()->notNull()->defaultValue(1), 'tinyint(1) NOT NULL DEFAULT 1'],
[Schema::TYPE_MONEY, $this->money(), 'decimal(19,4)'],
[Schema::TYPE_MONEY . '(16,2)', $this->money(16, 2), 'decimal(16,2)'],
[Schema::TYPE_MONEY . ' CHECK (value > 0.0)', $this->money()->check('value > 0.0'), 'decimal(19,4) CHECK (value > 0.0)'],
[Schema::TYPE_MONEY . '(16,2) CHECK (value > 0.0)', $this->money(16, 2)->check('value > 0.0'), 'decimal(16,2) CHECK (value > 0.0)'],
[Schema::TYPE_MONEY . ' NOT NULL', $this->money()->notNull(), 'decimal(19,4) NOT NULL'],
];
} }
} }

10
tests/framework/db/mssql/ColumnSchemaBuilderTest.php → tests/framework/db/mysql/ColumnSchemaBuilderTest.php

@ -1,12 +1,12 @@
<?php <?php
namespace yiiunit\framework\db\mssql; namespace yiiunit\framework\db\mysql;
use yii\db\mssql\ColumnSchemaBuilder; use yii\db\mysql\ColumnSchemaBuilder;
use yii\db\Schema; use yii\db\Schema;
use \yiiunit\framework\db\ColumnSchemaBuilderTest as BaseColumnSchemaBuilderTest; use \yiiunit\framework\db\ColumnSchemaBuilderTest as BaseColumnSchemaBuilderTest;
/** /**
* ColumnSchemaBuilderTest tests ColumnSchemaBuilder for MSSQL * ColumnSchemaBuilderTest tests ColumnSchemaBuilder for MySQL
*/ */
class ColumnSchemaBuilderTest extends BaseColumnSchemaBuilderTest class ColumnSchemaBuilderTest extends BaseColumnSchemaBuilderTest
{ {
@ -26,10 +26,10 @@ class ColumnSchemaBuilderTest extends BaseColumnSchemaBuilderTest
public function unsignedProvider() public function unsignedProvider()
{ {
return [ return [
['integer', Schema::TYPE_INTEGER, null, [ ['integer UNSIGNED', Schema::TYPE_INTEGER, null, [
['unsigned'], ['unsigned'],
]], ]],
['integer(10)', Schema::TYPE_INTEGER, 10, [ ['integer(10) UNSIGNED', Schema::TYPE_INTEGER, 10, [
['unsigned'], ['unsigned'],
]], ]],
]; ];

53
tests/framework/db/mysql/MysqlQueryBuilderTest.php

@ -0,0 +1,53 @@
<?php
namespace yiiunit\framework\db\mysql;
use yii\db\Schema;
use yiiunit\framework\db\QueryBuilderTest;
/**
* @group db
* @group mysql
*/
class MysqlQueryBuilderTest extends QueryBuilderTest
{
/**
* this is not used as a dataprovider for testGetColumnType to speed up the test
* when used as dataprovider every single line will cause a reconnect with the database which is not needed here
*/
public function columnTypes()
{
return array_merge(parent::columnTypes(), [
[
Schema::TYPE_PK . ' AFTER (`col_before`)',
$this->primaryKey()->after('col_before'),
'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY AFTER (`col_before`)'
],
[
Schema::TYPE_PK . ' FIRST',
$this->primaryKey()->first(),
'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST'
],
[
Schema::TYPE_PK . ' FIRST',
$this->primaryKey()->first()->after('col_before'),
'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST'
],
[
Schema::TYPE_PK . '(8) AFTER (`col_before`)',
$this->primaryKey(8)->after('col_before'),
'int(8) NOT NULL AUTO_INCREMENT PRIMARY KEY AFTER (`col_before`)'
],
[
Schema::TYPE_PK . '(8) FIRST',
$this->primaryKey(8)->first(),
'int(8) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST'
],
[
Schema::TYPE_PK . '(8) FIRST',
$this->primaryKey(8)->first()->after('col_before'),
'int(8) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST'
],
]);
}
}

15
tests/framework/db/oci/ColumnSchemaBuilderTest.php

@ -19,4 +19,19 @@ class ColumnSchemaBuilderTest extends BaseColumnSchemaBuilderTest
{ {
return new ColumnSchemaBuilder($type, $length); return new ColumnSchemaBuilder($type, $length);
} }
/**
* @return array
*/
public function unsignedProvider()
{
return [
['integer UNSIGNED', Schema::TYPE_INTEGER, null, [
['unsigned'],
]],
['integer(10) UNSIGNED', Schema::TYPE_INTEGER, 10, [
['unsigned'],
]],
];
}
} }

71
tests/framework/db/oci/OracleQueryBuilderTest.php

@ -19,69 +19,12 @@ class OracleQueryBuilderTest extends QueryBuilderTest
*/ */
public function columnTypes() public function columnTypes()
{ {
return [ return array_merge(parent::columnTypes(), [
[Schema::TYPE_PK, $this->primaryKey(), 'NUMBER(10) NOT NULL PRIMARY KEY'], [
[Schema::TYPE_PK . '(8)', $this->primaryKey(8), 'NUMBER(8) NOT NULL PRIMARY KEY'], Schema::TYPE_BOOLEAN . ' DEFAULT 1 NOT NULL',
[Schema::TYPE_PK . ' CHECK (value > 5)', $this->primaryKey()->check('value > 5'), 'NUMBER(10) NOT NULL PRIMARY KEY CHECK (value > 5)'], $this->boolean()->notNull()->defaultValue(1),
[Schema::TYPE_PK . '(8) CHECK (value > 5)', $this->primaryKey(8)->check('value > 5'), 'NUMBER(8) NOT NULL PRIMARY KEY CHECK (value > 5)'], 'NUMBER(1) DEFAULT 1 NOT NULL'
[Schema::TYPE_STRING, $this->string(), 'VARCHAR2(255)'], ],
[Schema::TYPE_STRING . '(32)', $this->string(32), 'VARCHAR2(32)'], ]);
[Schema::TYPE_STRING . ' CHECK (value LIKE \'test%\')', $this->string()->check('value LIKE \'test%\''), 'VARCHAR2(255) CHECK (value LIKE \'test%\')'],
[Schema::TYPE_STRING . '(32) CHECK (value LIKE \'test%\')', $this->string(32)->check('value LIKE \'test%\''), 'VARCHAR2(32) CHECK (value LIKE \'test%\')'],
[Schema::TYPE_STRING . ' NOT NULL', $this->string()->notNull(), 'VARCHAR2(255) NOT NULL'],
[Schema::TYPE_TEXT, $this->text(), 'CLOB'],
[Schema::TYPE_TEXT . '(255)', $this->text(), 'CLOB',Schema::TYPE_TEXT],
[Schema::TYPE_TEXT . ' CHECK (value LIKE \'test%\')', $this->text()->check('value LIKE \'test%\''), 'CLOB CHECK (value LIKE \'test%\')'],
[Schema::TYPE_TEXT . '(255) CHECK (value LIKE \'test%\')', $this->text()->check('value LIKE \'test%\''), 'CLOB CHECK (value LIKE \'test%\')', Schema::TYPE_TEXT . ' CHECK (value LIKE \'test%\')'],
[Schema::TYPE_TEXT . ' NOT NULL', $this->text()->notNull(), 'CLOB NOT NULL'],
[Schema::TYPE_TEXT . '(255) NOT NULL', $this->text()->notNull(), 'CLOB NOT NULL', Schema::TYPE_TEXT . ' NOT NULL'],
[Schema::TYPE_SMALLINT, $this->smallInteger(), 'NUMBER(5)'],
[Schema::TYPE_SMALLINT . '(8)', $this->smallInteger(8), 'NUMBER(8)'],
[Schema::TYPE_INTEGER, $this->integer(), 'NUMBER(10)'],
[Schema::TYPE_INTEGER . '(8)', $this->integer(8), 'NUMBER(8)'],
[Schema::TYPE_INTEGER . ' CHECK (value > 5)', $this->integer()->check('value > 5'), 'NUMBER(10) CHECK (value > 5)'],
[Schema::TYPE_INTEGER . '(8) CHECK (value > 5)', $this->integer(8)->check('value > 5'), 'NUMBER(8) CHECK (value > 5)'],
[Schema::TYPE_INTEGER . ' NOT NULL', $this->integer()->notNull(), 'NUMBER(10) NOT NULL'],
[Schema::TYPE_BIGINT, $this->bigInteger(), 'NUMBER(20)'],
[Schema::TYPE_BIGINT . '(8)', $this->bigInteger(8), 'NUMBER(8)'],
[Schema::TYPE_BIGINT . ' CHECK (value > 5)', $this->bigInteger()->check('value > 5'), 'NUMBER(20) CHECK (value > 5)'],
[Schema::TYPE_BIGINT . '(8) CHECK (value > 5)', $this->bigInteger(8)->check('value > 5'), 'NUMBER(8) CHECK (value > 5)'],
[Schema::TYPE_BIGINT . ' NOT NULL', $this->bigInteger()->notNull(), 'NUMBER(20) NOT NULL'],
[Schema::TYPE_FLOAT, $this->float(), 'NUMBER'],
[Schema::TYPE_FLOAT . '(16)', $this->float(16), 'NUMBER'],
[Schema::TYPE_FLOAT . ' CHECK (value > 5.6)', $this->float()->check('value > 5.6'), 'NUMBER CHECK (value > 5.6)'],
[Schema::TYPE_FLOAT . '(16) CHECK (value > 5.6)', $this->float(16)->check('value > 5.6'), 'NUMBER CHECK (value > 5.6)'],
[Schema::TYPE_FLOAT . ' NOT NULL', $this->float()->notNull(), 'NUMBER NOT NULL'],
[Schema::TYPE_DOUBLE, $this->double(), 'NUMBER'],
[Schema::TYPE_DOUBLE . '(16)', $this->double(16), 'NUMBER'],
[Schema::TYPE_DOUBLE . ' CHECK (value > 5.6)', $this->double()->check('value > 5.6'), 'NUMBER CHECK (value > 5.6)'],
[Schema::TYPE_DOUBLE . '(16) CHECK (value > 5.6)', $this->double(16)->check('value > 5.6'), 'NUMBER CHECK (value > 5.6)'],
[Schema::TYPE_DOUBLE . ' NOT NULL', $this->double()->notNull(), 'NUMBER NOT NULL'],
[Schema::TYPE_DECIMAL, $this->decimal(), 'NUMBER'],
[Schema::TYPE_DECIMAL . '(12,4)', $this->decimal(12, 4), 'NUMBER'],
[Schema::TYPE_DECIMAL . ' CHECK (value > 5.6)', $this->decimal()->check('value > 5.6'), 'NUMBER CHECK (value > 5.6)'],
[Schema::TYPE_DECIMAL . '(12,4) CHECK (value > 5.6)', $this->decimal(12, 4)->check('value > 5.6'), 'NUMBER CHECK (value > 5.6)'],
[Schema::TYPE_DECIMAL . ' NOT NULL', $this->decimal()->notNull(), 'NUMBER NOT NULL'],
[Schema::TYPE_DATETIME, $this->dateTime(), 'TIMESTAMP'],
//[Schema::TYPE_DATETIME . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')", "TIMESTAMP CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')"],
[Schema::TYPE_DATETIME . ' NOT NULL', $this->dateTime()->notNull(), 'TIMESTAMP NOT NULL'],
[Schema::TYPE_TIMESTAMP, $this->timestamp(), 'TIMESTAMP'],
//[Schema::TYPE_TIMESTAMP . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')", "TIMESTAMP CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')"],
[Schema::TYPE_TIMESTAMP . ' NOT NULL', $this->timestamp()->notNull(), 'TIMESTAMP NOT NULL'],
[Schema::TYPE_TIME, $this->time(), 'TIMESTAMP'],
//[Schema::TYPE_TIME . " CHECK (value BETWEEN '12:00:00' AND '13:01:01')", "TIMESTAMP CHECK (value BETWEEN '12:00:00' AND '13:01:01')"],
[Schema::TYPE_TIME . ' NOT NULL', $this->time()->notNull(), 'TIMESTAMP NOT NULL'],
[Schema::TYPE_DATE, $this->date(), 'DATE'],
//[Schema::TYPE_DATE . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')", "DATE CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')"],
[Schema::TYPE_DATE . ' NOT NULL', $this->date()->notNull(), 'DATE NOT NULL'],
[Schema::TYPE_BINARY, $this->binary(), 'BLOB'],
[Schema::TYPE_BOOLEAN, $this->boolean(), 'NUMBER(1)'],
[Schema::TYPE_BOOLEAN . ' DEFAULT 1 NOT NULL', $this->boolean()->notNull()->defaultValue(1), 'NUMBER(1) DEFAULT 1 NOT NULL'],
[Schema::TYPE_MONEY, $this->money(), 'NUMBER(19,4)'],
[Schema::TYPE_MONEY . '(16,2)', $this->money(16, 2), 'NUMBER(16,2)'],
[Schema::TYPE_MONEY . ' CHECK (value > 0.0)', $this->money()->check('value > 0.0'), 'NUMBER(19,4) CHECK (value > 0.0)'],
[Schema::TYPE_MONEY . '(16,2) CHECK (value > 0.0)', $this->money(16, 2)->check('value > 0.0'), 'NUMBER(16,2) CHECK (value > 0.0)'],
[Schema::TYPE_MONEY . ' NOT NULL', $this->money()->notNull(), 'NUMBER(19,4) NOT NULL'],
];
} }
} }

95
tests/framework/db/pgsql/PostgreSQLQueryBuilderTest.php

@ -15,69 +15,38 @@ class PostgreSQLQueryBuilderTest extends QueryBuilderTest
public function columnTypes() public function columnTypes()
{ {
return [ return array_merge(parent::columnTypes(), [
[Schema::TYPE_PK, $this->primaryKey(), 'serial NOT NULL PRIMARY KEY'], [
[Schema::TYPE_PK . '(8)', $this->primaryKey(8), 'serial NOT NULL PRIMARY KEY'], Schema::TYPE_BOOLEAN . ' NOT NULL DEFAULT TRUE',
[Schema::TYPE_PK . ' CHECK (value > 5)', $this->primaryKey()->check('value > 5'), 'serial NOT NULL PRIMARY KEY CHECK (value > 5)'], $this->boolean()->notNull()->defaultValue(true),
[Schema::TYPE_PK . '(8) CHECK (value > 5)', $this->primaryKey(8)->check('value > 5'), 'serial NOT NULL PRIMARY KEY CHECK (value > 5)'], 'boolean NOT NULL DEFAULT TRUE'
[Schema::TYPE_STRING, $this->string(), 'varchar(255)'], ],
[Schema::TYPE_STRING . '(32)', $this->string(32), 'varchar(32)'], [
[Schema::TYPE_STRING . ' CHECK (value LIKE \'test%\')', $this->string()->check('value LIKE \'test%\''), 'varchar(255) CHECK (value LIKE \'test%\')'], Schema::TYPE_CHAR . ' CHECK (value LIKE \'test%\')',
[Schema::TYPE_STRING . '(32) CHECK (value LIKE \'test%\')', $this->string(32)->check('value LIKE \'test%\''), 'varchar(32) CHECK (value LIKE \'test%\')'], $this->char()->check('value LIKE \'test%\''),
[Schema::TYPE_STRING . ' NOT NULL', $this->string()->notNull(), 'varchar(255) NOT NULL'], 'char(1) CHECK (value LIKE \'test%\')'
[Schema::TYPE_TEXT, $this->text(), 'text'], ],
[Schema::TYPE_TEXT . '(255)', $this->text(), 'text', Schema::TYPE_TEXT], [
[Schema::TYPE_TEXT . ' CHECK (value LIKE \'test%\')', $this->text()->check('value LIKE \'test%\''), 'text CHECK (value LIKE \'test%\')'], Schema::TYPE_CHAR . '(6) CHECK (value LIKE \'test%\')',
[Schema::TYPE_TEXT . '(255) CHECK (value LIKE \'test%\')', $this->text()->check('value LIKE \'test%\''), 'text CHECK (value LIKE \'test%\')', Schema::TYPE_TEXT . ' CHECK (value LIKE \'test%\')'], $this->char(6)->check('value LIKE \'test%\''),
[Schema::TYPE_TEXT . ' NOT NULL', $this->text()->notNull(), 'text NOT NULL'], 'char(6) CHECK (value LIKE \'test%\')'
[Schema::TYPE_TEXT . '(255) NOT NULL', $this->text()->notNull(), 'text NOT NULL', Schema::TYPE_TEXT . ' NOT NULL'], ],
[Schema::TYPE_SMALLINT, $this->smallInteger(), 'smallint'], [
[Schema::TYPE_SMALLINT . '(8)', $this->smallInteger(8), 'smallint'], Schema::TYPE_CHAR . '(6)',
[Schema::TYPE_INTEGER, $this->integer(), 'integer'], $this->char(6)->unsigned(),
[Schema::TYPE_INTEGER . '(8)', $this->integer(8), 'integer'], 'char(6)'
[Schema::TYPE_INTEGER . ' CHECK (value > 5)', $this->integer()->check('value > 5'), 'integer CHECK (value > 5)'], ],
[Schema::TYPE_INTEGER . '(8) CHECK (value > 5)', $this->integer(8)->check('value > 5'), 'integer CHECK (value > 5)'], [
[Schema::TYPE_INTEGER . ' NOT NULL', $this->integer()->notNull(), 'integer NOT NULL'], Schema::TYPE_INTEGER . '(8)',
[Schema::TYPE_BIGINT, $this->bigInteger(), 'bigint'], $this->integer(8)->unsigned(),
[Schema::TYPE_BIGINT . '(8)', $this->bigInteger(8), 'bigint'], 'integer'
[Schema::TYPE_BIGINT . ' CHECK (value > 5)', $this->bigInteger()->check('value > 5'), 'bigint CHECK (value > 5)'], ],
[Schema::TYPE_BIGINT . '(8) CHECK (value > 5)', $this->bigInteger(8)->check('value > 5'), 'bigint CHECK (value > 5)'], [
[Schema::TYPE_BIGINT . ' NOT NULL', $this->bigInteger()->notNull(), 'bigint NOT NULL'], Schema::TYPE_TIMESTAMP . '(4)',
[Schema::TYPE_FLOAT, $this->float(), 'double precision'], $this->timestamp(4),
[Schema::TYPE_FLOAT . ' CHECK (value > 5.6)', $this->float()->check('value > 5.6'), 'double precision CHECK (value > 5.6)'], 'timestamp(4)'
[Schema::TYPE_FLOAT . '(16) CHECK (value > 5.6)', $this->float(16)->check('value > 5.6'), 'double precision CHECK (value > 5.6)'], ],
[Schema::TYPE_FLOAT . ' NOT NULL', $this->float()->notNull(), 'double precision NOT NULL'], ]);
[Schema::TYPE_DOUBLE, $this->double(), 'double precision'],
[Schema::TYPE_DOUBLE . ' CHECK (value > 5.6)', $this->double()->check('value > 5.6'), 'double precision CHECK (value > 5.6)'],
[Schema::TYPE_DOUBLE . '(16) CHECK (value > 5.6)', $this->double(16)->check('value > 5.6'), 'double precision CHECK (value > 5.6)'],
[Schema::TYPE_DOUBLE . ' NOT NULL', $this->double()->notNull(), 'double precision NOT NULL'],
[Schema::TYPE_DECIMAL, $this->decimal(), 'numeric(10,0)'],
[Schema::TYPE_DECIMAL . '(12,4)', $this->decimal(12, 4), 'numeric(12,4)'],
[Schema::TYPE_DECIMAL . ' CHECK (value > 5.6)', $this->decimal()->check('value > 5.6'), 'numeric(10,0) CHECK (value > 5.6)'],
[Schema::TYPE_DECIMAL . '(12,4) CHECK (value > 5.6)', $this->decimal(12, 4)->check('value > 5.6'), 'numeric(12,4) CHECK (value > 5.6)'],
[Schema::TYPE_DECIMAL . ' NOT NULL', $this->decimal()->notNull(), 'numeric(10,0) NOT NULL'],
[Schema::TYPE_DATETIME, $this->dateTime(), 'timestamp(0)'],
[Schema::TYPE_DATETIME . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')", $this->dateTime()->check("value BETWEEN '2011-01-01' AND '2013-01-01'"), "timestamp(0) CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')"],
[Schema::TYPE_DATETIME . ' NOT NULL', $this->dateTime()->notNull(), 'timestamp(0) NOT NULL'],
[Schema::TYPE_TIMESTAMP, $this->timestamp(), 'timestamp(0)'],
[Schema::TYPE_TIMESTAMP . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')", $this->timestamp()->check("value BETWEEN '2011-01-01' AND '2013-01-01'"), "timestamp(0) CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')"],
[Schema::TYPE_TIMESTAMP . ' NOT NULL', $this->timestamp()->notNull(), 'timestamp(0) NOT NULL'],
[Schema::TYPE_TIMESTAMP . '(4)', $this->timestamp(4), 'timestamp(4)'],
[Schema::TYPE_TIME, $this->time(), 'time(0)'],
[Schema::TYPE_TIME . " CHECK (value BETWEEN '12:00:00' AND '13:01:01')", $this->time()->check("value BETWEEN '12:00:00' AND '13:01:01'"), "time(0) CHECK (value BETWEEN '12:00:00' AND '13:01:01')"],
[Schema::TYPE_TIME . ' NOT NULL', $this->time()->notNull(), 'time(0) NOT NULL'],
[Schema::TYPE_DATE, $this->date(), 'date'],
[Schema::TYPE_DATE . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')", $this->date()->check("value BETWEEN '2011-01-01' AND '2013-01-01'"), "date CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')"],
[Schema::TYPE_DATE . ' NOT NULL', $this->date()->notNull(), 'date NOT NULL'],
[Schema::TYPE_BINARY, $this->binary(), 'bytea'],
[Schema::TYPE_BOOLEAN, $this->boolean(), 'boolean'],
[Schema::TYPE_BOOLEAN . ' NOT NULL DEFAULT TRUE', $this->boolean()->notNull()->defaultValue(true), 'boolean NOT NULL DEFAULT TRUE'],
[Schema::TYPE_MONEY, $this->money(), 'numeric(19,4)'],
[Schema::TYPE_MONEY . '(16,2)', $this->money(16, 2), 'numeric(16,2)'],
[Schema::TYPE_MONEY . ' CHECK (value > 0.0)', $this->money()->check('value > 0.0'), 'numeric(19,4) CHECK (value > 0.0)'],
[Schema::TYPE_MONEY . '(16,2) CHECK (value > 0.0)', $this->money(16, 2)->check('value > 0.0'), 'numeric(16,2) CHECK (value > 0.0)'],
[Schema::TYPE_MONEY . ' NOT NULL', $this->money()->notNull(), 'numeric(19,4) NOT NULL'],
];
} }
public function conditionProvider() public function conditionProvider()

37
tests/framework/db/sqlite/ColumnSchemaBuilderTest.php

@ -0,0 +1,37 @@
<?php
namespace yiiunit\framework\db\sqlite;
use yii\db\sqlite\ColumnSchemaBuilder;
use yii\db\Schema;
use \yiiunit\framework\db\ColumnSchemaBuilderTest as BaseColumnSchemaBuilderTest;
/**
* ColumnSchemaBuilderTest tests ColumnSchemaBuilder for SQLite
*/
class ColumnSchemaBuilderTest extends BaseColumnSchemaBuilderTest
{
/**
* @param string $type
* @param integer $length
* @return ColumnSchemaBuilder
*/
public function getColumnSchemaBuilder($type, $length = null)
{
return new ColumnSchemaBuilder($type, $length);
}
/**
* @return array
*/
public function unsignedProvider()
{
return [
['integer UNSIGNED', Schema::TYPE_INTEGER, null, [
['unsigned'],
]],
['integer(10) UNSIGNED', Schema::TYPE_INTEGER, 10, [
['unsigned'],
]],
];
}
}

71
tests/framework/db/sqlite/SqliteQueryBuilderTest.php

@ -16,70 +16,13 @@ class SqliteQueryBuilderTest extends QueryBuilderTest
public function columnTypes() public function columnTypes()
{ {
return [ return array_merge(parent::columnTypes(), [
[Schema::TYPE_PK, $this->primaryKey(), 'integer PRIMARY KEY AUTOINCREMENT NOT NULL'], [
[Schema::TYPE_PK . '(8)', $this->primaryKey(8), 'integer PRIMARY KEY AUTOINCREMENT NOT NULL'], Schema::TYPE_PK,
[Schema::TYPE_PK . ' CHECK (value > 5)', $this->primaryKey()->check('value > 5'), 'integer PRIMARY KEY AUTOINCREMENT NOT NULL CHECK (value > 5)'], $this->primaryKey()->first()->after('col_before'),
[Schema::TYPE_PK . '(8) CHECK (value > 5)', $this->primaryKey(8)->check('value > 5'), 'integer PRIMARY KEY AUTOINCREMENT NOT NULL CHECK (value > 5)'], 'integer PRIMARY KEY AUTOINCREMENT NOT NULL'
[Schema::TYPE_STRING, $this->string(), 'varchar(255)'], ],
[Schema::TYPE_STRING . '(32)', $this->string(32), 'varchar(32)'], ]);
[Schema::TYPE_STRING . ' CHECK (value LIKE "test%")', $this->string()->check('value LIKE "test%"'), 'varchar(255) CHECK (value LIKE "test%")'],
[Schema::TYPE_STRING . '(32) CHECK (value LIKE "test%")', $this->string(32)->check('value LIKE "test%"'), 'varchar(32) CHECK (value LIKE "test%")'],
[Schema::TYPE_STRING . ' NOT NULL', $this->string()->notNull(), 'varchar(255) NOT NULL'],
[Schema::TYPE_TEXT, $this->text(), 'text'],
[Schema::TYPE_TEXT . '(255)', $this->text(), 'text', Schema::TYPE_TEXT],
[Schema::TYPE_TEXT . ' CHECK (value LIKE "test%")', $this->text()->check('value LIKE "test%"'), 'text CHECK (value LIKE "test%")'],
[Schema::TYPE_TEXT . '(255) CHECK (value LIKE "test%")', $this->text()->check('value LIKE "test%"'), 'text CHECK (value LIKE "test%")', Schema::TYPE_TEXT . ' CHECK (value LIKE "test%")'],
[Schema::TYPE_TEXT . ' NOT NULL', $this->text()->notNull(), 'text NOT NULL'],
[Schema::TYPE_TEXT . '(255) NOT NULL', $this->text()->notNull(), 'text NOT NULL', Schema::TYPE_TEXT . ' NOT NULL'],
[Schema::TYPE_SMALLINT, $this->smallInteger(), 'smallint'],
[Schema::TYPE_SMALLINT . '(8)', $this->smallInteger(8), 'smallint'],
[Schema::TYPE_INTEGER, $this->integer(), 'integer'],
[Schema::TYPE_INTEGER . '(8)', $this->integer(8), 'integer'],
[Schema::TYPE_INTEGER . ' CHECK (value > 5)', $this->integer()->check('value > 5'), 'integer CHECK (value > 5)'],
[Schema::TYPE_INTEGER . '(8) CHECK (value > 5)', $this->integer(8)->check('value > 5'), 'integer CHECK (value > 5)'],
[Schema::TYPE_INTEGER . ' NOT NULL', $this->integer()->notNull(), 'integer NOT NULL'],
[Schema::TYPE_BIGINT, $this->bigInteger(), 'bigint'],
[Schema::TYPE_BIGINT . '(8)', $this->bigInteger(8), 'bigint'],
[Schema::TYPE_BIGINT . ' CHECK (value > 5)', $this->bigInteger()->check('value > 5'), 'bigint CHECK (value > 5)'],
[Schema::TYPE_BIGINT . '(8) CHECK (value > 5)', $this->bigInteger(8)->check('value > 5'), 'bigint CHECK (value > 5)'],
[Schema::TYPE_BIGINT . ' NOT NULL', $this->bigInteger()->notNull(), 'bigint NOT NULL'],
[Schema::TYPE_FLOAT, $this->float(), 'float'],
[Schema::TYPE_FLOAT . '(16)', $this->float(16), 'float'],
[Schema::TYPE_FLOAT . ' CHECK (value > 5.6)', $this->float()->check('value > 5.6'), 'float CHECK (value > 5.6)'],
[Schema::TYPE_FLOAT . '(16) CHECK (value > 5.6)', $this->float(16)->check('value > 5.6'), 'float CHECK (value > 5.6)'],
[Schema::TYPE_FLOAT . ' NOT NULL', $this->float()->notNull(), 'float NOT NULL'],
[Schema::TYPE_DOUBLE, $this->double(), 'double'],
[Schema::TYPE_DOUBLE . '(16)', $this->double(16), 'double'],
[Schema::TYPE_DOUBLE . ' CHECK (value > 5.6)', $this->double()->check('value > 5.6'), 'double CHECK (value > 5.6)'],
[Schema::TYPE_DOUBLE . '(16) CHECK (value > 5.6)', $this->double(16)->check('value > 5.6'), 'double CHECK (value > 5.6)'],
[Schema::TYPE_DOUBLE . ' NOT NULL', $this->double()->notNull(), 'double NOT NULL'],
[Schema::TYPE_DECIMAL, $this->decimal(), 'decimal(10,0)'],
[Schema::TYPE_DECIMAL . '(12,4)', $this->decimal(12, 4), 'decimal(12,4)'],
[Schema::TYPE_DECIMAL . ' CHECK (value > 5.6)', $this->decimal()->check('value > 5.6'), 'decimal(10,0) CHECK (value > 5.6)'],
[Schema::TYPE_DECIMAL . '(12,4) CHECK (value > 5.6)', $this->decimal(12, 4)->check('value > 5.6'), 'decimal(12,4) CHECK (value > 5.6)'],
[Schema::TYPE_DECIMAL . ' NOT NULL', $this->decimal()->notNull(), 'decimal(10,0) NOT NULL'],
[Schema::TYPE_DATETIME, $this->dateTime(), 'datetime'],
[Schema::TYPE_DATETIME . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')", $this->dateTime()->check("value BETWEEN '2011-01-01' AND '2013-01-01'"), "datetime CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')"],
[Schema::TYPE_DATETIME . ' NOT NULL', $this->dateTime()->notNull(), 'datetime NOT NULL'],
[Schema::TYPE_TIMESTAMP, $this->timestamp(), 'timestamp'],
[Schema::TYPE_TIMESTAMP . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')", $this->timestamp()->check("value BETWEEN '2011-01-01' AND '2013-01-01'"), "timestamp CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')"],
[Schema::TYPE_TIMESTAMP . ' NOT NULL', $this->timestamp()->notNull(), 'timestamp NOT NULL'],
[Schema::TYPE_TIME, $this->time(), 'time'],
[Schema::TYPE_TIME . " CHECK (value BETWEEN '12:00:00' AND '13:01:01')", $this->time()->check("value BETWEEN '12:00:00' AND '13:01:01'"), "time CHECK (value BETWEEN '12:00:00' AND '13:01:01')"],
[Schema::TYPE_TIME . ' NOT NULL', $this->time()->notNull(), 'time NOT NULL'],
[Schema::TYPE_DATE, $this->date(), 'date'],
[Schema::TYPE_DATE . " CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')", $this->date()->check("value BETWEEN '2011-01-01' AND '2013-01-01'"), "date CHECK (value BETWEEN '2011-01-01' AND '2013-01-01')"],
[Schema::TYPE_DATE . ' NOT NULL', $this->date()->notNull(), 'date NOT NULL'],
[Schema::TYPE_BINARY, $this->binary(), 'blob'],
[Schema::TYPE_BOOLEAN, $this->boolean(), 'boolean'],
[Schema::TYPE_BOOLEAN . ' NOT NULL DEFAULT 1', $this->boolean()->notNull()->defaultValue(1), 'boolean NOT NULL DEFAULT 1'],
[Schema::TYPE_MONEY, $this->money(), 'decimal(19,4)'],
[Schema::TYPE_MONEY . '(16,2)', $this->money(16, 2), 'decimal(16,2)'],
[Schema::TYPE_MONEY . ' CHECK (value > 0.0)', $this->money()->check('value > 0.0'), 'decimal(19,4) CHECK (value > 0.0)'],
[Schema::TYPE_MONEY . '(16,2) CHECK (value > 0.0)', $this->money(16, 2)->check('value > 0.0'), 'decimal(16,2) CHECK (value > 0.0)'],
[Schema::TYPE_MONEY . ' NOT NULL', $this->money()->notNull(), 'decimal(19,4) NOT NULL'],
];
} }
public function testAddDropPrimaryKey() public function testAddDropPrimaryKey()

Loading…
Cancel
Save