diff --git a/CHANGELOG-silecs.md b/CHANGELOG-silecs.md index 59f16952a7..476c2d7668 100644 --- a/CHANGELOG-silecs.md +++ b/CHANGELOG-silecs.md @@ -12,3 +12,4 @@ Miscellanous ------------ - CTreeView used an undocumented jQuery parameter which was removed in modern versions. +- With MariaDB 10.3+, Yii misunderstood `TEXT DEFAULT ''` with a default value of "''". diff --git a/framework/db/schema/mysql/CMysqlColumnSchema.php b/framework/db/schema/mysql/CMysqlColumnSchema.php index 85abba686e..5254a7cea3 100644 --- a/framework/db/schema/mysql/CMysqlColumnSchema.php +++ b/framework/db/schema/mysql/CMysqlColumnSchema.php @@ -44,6 +44,8 @@ protected function extractDefault($defaultValue) { if(strncmp($this->dbType,'bit',3)===0) $this->defaultValue=bindec(trim($defaultValue,'b\'')); + elseif(substr_compare($this->dbType,'text',-4)===0) + $this->defaultValue=trim($defaultValue,"''"); elseif(($this->dbType==='timestamp' || $this->dbType==='datetime') && ($defaultValue==='CURRENT_TIMESTAMP' || $defaultValue==='current_timestamp()')) $this->defaultValue=null; else diff --git a/tests/framework/db/data/mysql.sql b/tests/framework/db/data/mysql.sql index 8a85621290..9e139f9be8 100644 --- a/tests/framework/db/data/mysql.sql +++ b/tests/framework/db/data/mysql.sql @@ -35,7 +35,7 @@ CREATE TABLE posts title VARCHAR(128) NOT NULL, create_time TIMESTAMP NOT NULL, author_id INTEGER NOT NULL, - content TEXT, + content TEXT DEFAULT '', CONSTRAINT FK_post_author FOREIGN KEY (author_id) REFERENCES users (id) ON DELETE CASCADE ON UPDATE RESTRICT ) ENGINE=InnoDB; @@ -149,4 +149,4 @@ CREATE TABLE types bool_col2 BOOLEAN DEFAULT 1, bit_col1 BIT, bit_col2 BIT(32) DEFAULT b'101010' -) ENGINE=InnoDB; \ No newline at end of file +) ENGINE=InnoDB; diff --git a/tests/framework/db/schema/CMysqlTest.php b/tests/framework/db/schema/CMysqlTest.php index 6f1240a938..f6cab636eb 100644 --- a/tests/framework/db/schema/CMysqlTest.php +++ b/tests/framework/db/schema/CMysqlTest.php @@ -94,7 +94,7 @@ public function testColumn() ( 'name'=>array('id', 'title', 'create_time', 'author_id', 'content'), 'rawName'=>array('`id`', '`title`', '`create_time`', '`author_id`', '`content`'), - 'defaultValue'=>array(null, null, null, null, null), + 'defaultValue'=>array(null, null, null, null, ''), 'size'=>array(11, 128, null, 11, null), 'precision'=>array(11, 128, null, 11, null), 'scale'=>array(null, null, null, null, null), @@ -314,4 +314,4 @@ public function testColumnComments() $this->assertEquals('Hashed password',$usersColumns['password']->comment); $this->assertEquals('',$usersColumns['email']->comment); } -} \ No newline at end of file +}