mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 06:15:19 +08:00
Better flexibility for abstract db types
Feature was requested in yiisoft/yii#765
This commit is contained in:
@ -464,6 +464,8 @@ class QueryBuilder extends \yii\base\Object
|
||||
* the first part will be converted, and the rest of the parts will be appended to the converted result.
|
||||
* For example, 'string NOT NULL' is converted to 'varchar(255) NOT NULL'.
|
||||
*
|
||||
// TODO documentation
|
||||
*
|
||||
* If a type cannot be found in [[typeMap]], it will be returned without any change.
|
||||
* @param string $type abstract column type
|
||||
* @return string physical column type.
|
||||
@ -472,6 +474,10 @@ class QueryBuilder extends \yii\base\Object
|
||||
{
|
||||
if (isset($this->typeMap[$type])) {
|
||||
return $this->typeMap[$type];
|
||||
} elseif ((preg_match('/^(\w+)\((.+?)\)(.*)$/', $type, $matches))) {
|
||||
if (isset($this->typeMap[$matches[1]])) {
|
||||
return preg_replace('/\(.+\)/', '(' . $matches[2] . ')', $this->typeMap[$matches[1]]) . $matches[3];
|
||||
}
|
||||
} elseif (preg_match('/^(\w+)\s+/', $type, $matches)) {
|
||||
if (isset($this->typeMap[$matches[1]])) {
|
||||
return preg_replace('/^\w+/', $this->typeMap[$matches[1]], $type);
|
||||
|
@ -29,7 +29,7 @@ class QueryBuilder extends \yii\db\QueryBuilder
|
||||
Schema::TYPE_INTEGER => 'int(11)',
|
||||
Schema::TYPE_BIGINT => 'bigint(20)',
|
||||
Schema::TYPE_FLOAT => 'float',
|
||||
Schema::TYPE_DECIMAL => 'decimal',
|
||||
Schema::TYPE_DECIMAL => 'decimal(10,0)',
|
||||
Schema::TYPE_DATETIME => 'datetime',
|
||||
Schema::TYPE_TIMESTAMP => 'timestamp',
|
||||
Schema::TYPE_TIME => 'time',
|
||||
|
Reference in New Issue
Block a user