Browse Source

Fix #19047, fix #19118: Fix deprecated preg_match() passing null parameters #2 in db\mysql\Schema.php

tags/2.0.45
Long TRAN 3 years ago committed by GitHub
parent
commit
6a36fa82c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      framework/CHANGELOG.md
  2. 1
      framework/db/mysql/Schema.php
  3. 31
      tests/framework/db/mysql/SchemaTest.php

1
framework/CHANGELOG.md

@ -12,6 +12,7 @@ Yii Framework 2 Change Log
- Bug #19187: Fix `yii\filters\PageCache` to store original headers names instead of normalized ones (bizley) - Bug #19187: Fix `yii\filters\PageCache` to store original headers names instead of normalized ones (bizley)
- Bug #19191: Change `\Exception` to `\Throwable` in `BadRequestHttpException` and `HttpException` (Dmitrijlin) - Bug #19191: Change `\Exception` to `\Throwable` in `BadRequestHttpException` and `HttpException` (Dmitrijlin)
- Bug #19204: Support numbers in Inflector::camel2words (longthanhtran) - Bug #19204: Support numbers in Inflector::camel2words (longthanhtran)
- Bug #19047: Fix deprecated preg_match() passing null parameters #2 in db\mysql\Schema.php (longthanhtran)
2.0.44 December 30, 2021 2.0.44 December 30, 2021

1
framework/db/mysql/Schema.php

@ -294,6 +294,7 @@ SQL;
* See details here: https://mariadb.com/kb/en/library/now/#description * See details here: https://mariadb.com/kb/en/library/now/#description
*/ */
if (($column->type === 'timestamp' || $column->type === 'datetime') if (($column->type === 'timestamp' || $column->type === 'datetime')
&& isset($info['default'])
&& preg_match('/^current_timestamp(?:\(([0-9]*)\))?$/i', $info['default'], $matches)) { && preg_match('/^current_timestamp(?:\(([0-9]*)\))?$/i', $info['default'], $matches)) {
$column->defaultValue = new Expression('CURRENT_TIMESTAMP' . (!empty($matches[1]) ? '(' . $matches[1] . ')' : '')); $column->defaultValue = new Expression('CURRENT_TIMESTAMP' . (!empty($matches[1]) ? '(' . $matches[1] . ')' : ''));
} elseif (isset($type) && $type === 'bit') { } elseif (isset($type) && $type === 'bit') {

31
tests/framework/db/mysql/SchemaTest.php

@ -8,6 +8,8 @@
namespace yiiunit\framework\db\mysql; namespace yiiunit\framework\db\mysql;
use yii\db\Expression; use yii\db\Expression;
use yii\db\mysql\ColumnSchema;
use yii\db\mysql\Schema;
use yiiunit\framework\db\AnyCaseValue; use yiiunit\framework\db\AnyCaseValue;
/** /**
@ -101,7 +103,7 @@ SQL;
* We do not have a real database MariaDB >= 10.2.3 for tests, so we emulate the information that database * 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 ...` * returns in response to the query `SHOW FULL COLUMNS FROM ...`
*/ */
$schema = new \yii\db\mysql\Schema(); $schema = new Schema();
$column = $this->invokeMethod($schema, 'loadColumnSchema', [[ $column = $this->invokeMethod($schema, 'loadColumnSchema', [[
'field' => 'emulated_MariaDB_field', 'field' => 'emulated_MariaDB_field',
'type' => 'timestamp', 'type' => 'timestamp',
@ -114,11 +116,36 @@ SQL;
'comment' => '', 'comment' => '',
]]); ]]);
$this->assertInstanceOf(\yii\db\mysql\ColumnSchema::className(), $column); $this->assertInstanceOf(ColumnSchema::className(), $column);
$this->assertInstanceOf(Expression::className(), $column->defaultValue); $this->assertInstanceOf(Expression::className(), $column->defaultValue);
$this->assertEquals('CURRENT_TIMESTAMP', $column->defaultValue); $this->assertEquals('CURRENT_TIMESTAMP', $column->defaultValue);
} }
/**
* When displayed in the INFORMATION_SCHEMA.COLUMNS table, a default CURRENT TIMESTAMP is provided
* as NULL.
*
* @see https://github.com/yiisoft/yii2/issues/19047
*/
public function testAlternativeDisplayOfDefaultCurrentTimestampAsNullInMariaDB()
{
$schema = new Schema();
$column = $this->invokeMethod($schema, 'loadColumnSchema', [[
'field' => 'emulated_MariaDB_field',
'type' => 'timestamp',
'collation' => NULL,
'null' => 'NO',
'key' => '',
'default' => NULL,
'extra' => '',
'privileges' => 'select,insert,update,references',
'comment' => '',
]]);
$this->assertInstanceOf(ColumnSchema::className(), $column);
$this->assertEquals(NULL, $column->defaultValue);
}
public function getExpectedColumns() public function getExpectedColumns()
{ {
$version = $this->getConnection()->getSchema()->getServerVersion(); $version = $this->getConnection()->getSchema()->getServerVersion();

Loading…
Cancel
Save