mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-03 05:48:11 +08:00
Fixes #15167: Fixed loading of default value current_timestamp() for MariaDB >= 10.2.3
This commit is contained in:
committed by
Alexander Makarov
parent
c59df914c1
commit
7ccadb4a79
@ -4,6 +4,7 @@ Yii Framework 2 Change Log
|
|||||||
2.0.16 under development
|
2.0.16 under development
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
|
- Bug #15167: Fixed loading of default value `current_timestamp()` for MariaDB >= 10.2.3 (rugabarbo, bloodrain777, Skinka)
|
||||||
- Bug #16253: Fixed empty checkboxlist validation (GHopperMSK)
|
- Bug #16253: Fixed empty checkboxlist validation (GHopperMSK)
|
||||||
- Bug #15286: Fixed incorrect formatting of time with timezone information (rugabarbo)
|
- Bug #15286: Fixed incorrect formatting of time with timezone information (rugabarbo)
|
||||||
- Bug #17021: Fix to do not remove existing message category files in a subfolder (albertborsos)
|
- Bug #17021: Fix to do not remove existing message category files in a subfolder (albertborsos)
|
||||||
|
|||||||
@ -287,7 +287,14 @@ SQL;
|
|||||||
$column->phpType = $this->getColumnPhpType($column);
|
$column->phpType = $this->getColumnPhpType($column);
|
||||||
|
|
||||||
if (!$column->isPrimaryKey) {
|
if (!$column->isPrimaryKey) {
|
||||||
if (($column->type === 'timestamp' || $column->type ==='datetime') && $info['default'] === 'CURRENT_TIMESTAMP') {
|
/**
|
||||||
|
* When displayed in the INFORMATION_SCHEMA.COLUMNS table, a default CURRENT TIMESTAMP is displayed
|
||||||
|
* as CURRENT_TIMESTAMP up until MariaDB 10.2.2, and as current_timestamp() from MariaDB 10.2.3.
|
||||||
|
*
|
||||||
|
* See details here: https://mariadb.com/kb/en/library/now/#description
|
||||||
|
*/
|
||||||
|
if (($column->type === 'timestamp' || $column->type === 'datetime') &&
|
||||||
|
($info['default'] === 'CURRENT_TIMESTAMP' || $info['default'] === 'current_timestamp()')) {
|
||||||
$column->defaultValue = new Expression('CURRENT_TIMESTAMP');
|
$column->defaultValue = new Expression('CURRENT_TIMESTAMP');
|
||||||
} elseif (isset($type) && $type === 'bit') {
|
} elseif (isset($type) && $type === 'bit') {
|
||||||
$column->defaultValue = bindec(trim($info['default'], 'b\''));
|
$column->defaultValue = bindec(trim($info['default'], 'b\''));
|
||||||
|
|||||||
@ -61,4 +61,35 @@ SQL;
|
|||||||
$result['4: check'][2] = false;
|
$result['4: check'][2] = false;
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When displayed in the INFORMATION_SCHEMA.COLUMNS table, a default CURRENT TIMESTAMP is displayed
|
||||||
|
* as CURRENT_TIMESTAMP up until MariaDB 10.2.2, and as current_timestamp() from MariaDB 10.2.3.
|
||||||
|
*
|
||||||
|
* @see https://mariadb.com/kb/en/library/now/#description
|
||||||
|
* @see https://github.com/yiisoft/yii2/issues/15167
|
||||||
|
*/
|
||||||
|
public function testAlternativeDisplayOfDefaultCurrentTimestampInMariaDB()
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* We do not have a real database MariaDB >= 10.2.3 for tests, so we emulate the information that database
|
||||||
|
* returns in response to the query `SHOW FULL COLUMNS FROM ...`
|
||||||
|
*/
|
||||||
|
$schema = new \yii\db\mysql\Schema();
|
||||||
|
$column = $this->invokeMethod($schema, 'loadColumnSchema', [[
|
||||||
|
'field' => 'emulated_MariaDB_field',
|
||||||
|
'type' => 'timestamp',
|
||||||
|
'collation' => NULL,
|
||||||
|
'null' => 'NO',
|
||||||
|
'key' => '',
|
||||||
|
'default' => 'current_timestamp()',
|
||||||
|
'extra' => '',
|
||||||
|
'privileges' => 'select,insert,update,references',
|
||||||
|
'comment' => '',
|
||||||
|
]]);
|
||||||
|
|
||||||
|
$this->assertInstanceOf(\yii\db\mysql\ColumnSchema::className(), $column);
|
||||||
|
$this->assertInstanceOf(Expression::className(), $column->defaultValue);
|
||||||
|
$this->assertEquals('CURRENT_TIMESTAMP', $column->defaultValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user