diff --git a/framework/db/mysql/Schema.php b/framework/db/mysql/Schema.php index 21cca273ab1..bcf11142e88 100644 --- a/framework/db/mysql/Schema.php +++ b/framework/db/mysql/Schema.php @@ -223,26 +223,33 @@ protected function loadTableChecks($tableName) return $checks; } + $tableRows = $this->normalizePdoRowKeyCase($tableRows, true); + foreach ($tableRows as $tableRow) { $sql = <<db->createCommand($sql, [':constraintName' => $tableRow['CONSTRAINT_NAME']])->queryAll(); + $checkRows = $this->db->createCommand( + $sql, + [':constraintName' => $tableRow['constraint_name']], + )->queryAll(); + + $checkRows = $this->normalizePdoRowKeyCase($checkRows, true); foreach ($checkRows as $checkRow) { $matches = []; $columnName = null; - if (preg_match('/\(`?([a-zA-Z0-9_]+)`?\s*[><=]/', $checkRow['CHECK_CLAUSE'], $matches)) { + if (preg_match('/\(`?([a-zA-Z0-9_]+)`?\s*[><=]/', $checkRow['check_clause'], $matches)) { $columnName = $matches[1]; } $check = new CheckConstraint( [ - 'name' => $checkRow['CONSTRAINT_NAME'], + 'name' => $checkRow['constraint_name'], 'columnNames' => $columnName, - 'expression' => $checkRow['CHECK_CLAUSE'], + 'expression' => $checkRow['check_clause'], ] ); $checks[] = $check; diff --git a/tests/framework/db/mysql/SchemaTest.php b/tests/framework/db/mysql/SchemaTest.php index 43a66a60b57..9c2ca835078 100644 --- a/tests/framework/db/mysql/SchemaTest.php +++ b/tests/framework/db/mysql/SchemaTest.php @@ -77,16 +77,12 @@ public function testGetSchemaNames() public function constraintsProvider() { $result = parent::constraintsProvider(); - $result['1: check'][2] = false; $result['2: primary key'][2]->name = null; - $result['2: check'][2] = false; // Work aroung bug in MySQL 5.1 - it creates only this table in lowercase. O_o $result['3: foreign key'][2][0]->foreignTableName = new AnyCaseValue('T_constraints_2'); - $result['3: check'][2] = false; - $result['4: check'][2] = false; return $result; }