mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-03 05:48:11 +08:00
Minor improvents.
This commit is contained in:
@ -213,7 +213,11 @@ SQL;
|
||||
$checks = [];
|
||||
|
||||
$sql = <<<SQL
|
||||
SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE TABLE_NAME = :tableName
|
||||
SELECT cc.CONSTRAINT_NAME as constraint_name, cc.CHECK_CLAUSE as check_clause
|
||||
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc
|
||||
JOIN INFORMATION_SCHEMA.CHECK_CONSTRAINTS cc
|
||||
ON tc.CONSTRAINT_NAME = cc.CONSTRAINT_NAME
|
||||
WHERE tc.TABLE_NAME = :tableName AND tc.CONSTRAINT_TYPE = 'CHECK';
|
||||
SQL;
|
||||
|
||||
$resolvedName = $this->resolveTableName($tableName);
|
||||
@ -226,34 +230,21 @@ SQL;
|
||||
$tableRows = $this->normalizePdoRowKeyCase($tableRows, true);
|
||||
|
||||
foreach ($tableRows as $tableRow) {
|
||||
$sql = <<<SQL
|
||||
SELECT * FROM INFORMATION_SCHEMA.CHECK_CONSTRAINTS WHERE CONSTRAINT_NAME = :constraintName
|
||||
SQL;
|
||||
$matches = [];
|
||||
$columnName = null;
|
||||
|
||||
$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)) {
|
||||
$columnName = $matches[1];
|
||||
}
|
||||
|
||||
$check = new CheckConstraint(
|
||||
[
|
||||
'name' => $checkRow['constraint_name'],
|
||||
'columnNames' => $columnName,
|
||||
'expression' => $checkRow['check_clause'],
|
||||
]
|
||||
);
|
||||
$checks[] = $check;
|
||||
if (preg_match('/\(`?([a-zA-Z0-9_]+)`?\s*[><=]/', $tableRow['check_clause'], $matches)) {
|
||||
$columnName = $matches[1];
|
||||
}
|
||||
|
||||
$check = new CheckConstraint(
|
||||
[
|
||||
'name' => $tableRow['constraint_name'],
|
||||
'columnNames' => [$columnName],
|
||||
'expression' => $tableRow['check_clause'],
|
||||
]
|
||||
);
|
||||
$checks[] = $check;
|
||||
}
|
||||
|
||||
return $checks;
|
||||
|
||||
@ -773,6 +773,13 @@ abstract class SchemaTest extends DatabaseTestCase
|
||||
$this->expectException('yii\base\NotSupportedException');
|
||||
}
|
||||
|
||||
if (
|
||||
version_compare($this->getConnection(false)->getServerVersion(), '8.0.16', '<') &&
|
||||
$type === 'checks'
|
||||
) {
|
||||
$this->expectException('yii\base\NotSupportedException');
|
||||
}
|
||||
|
||||
$constraints = $this->getConnection(false)->getSchema()->{'getTable' . ucfirst($type)}($tableName);
|
||||
$this->assertMetadataEquals($expected, $constraints);
|
||||
}
|
||||
@ -789,6 +796,13 @@ abstract class SchemaTest extends DatabaseTestCase
|
||||
$this->expectException('yii\base\NotSupportedException');
|
||||
}
|
||||
|
||||
if (
|
||||
version_compare($this->getConnection(false)->getServerVersion(), '8.0.16', '<') &&
|
||||
$type === 'checks'
|
||||
) {
|
||||
$this->expectException('yii\base\NotSupportedException');
|
||||
}
|
||||
|
||||
$connection = $this->getConnection(false);
|
||||
$connection->getSlavePdo(true)->setAttribute(PDO::ATTR_CASE, PDO::CASE_UPPER);
|
||||
$constraints = $connection->getSchema()->{'getTable' . ucfirst($type)}($tableName, true);
|
||||
@ -807,6 +821,13 @@ abstract class SchemaTest extends DatabaseTestCase
|
||||
$this->expectException('yii\base\NotSupportedException');
|
||||
}
|
||||
|
||||
if (
|
||||
version_compare($this->getConnection(false)->getServerVersion(), '8.0.16', '<') &&
|
||||
$type === 'checks'
|
||||
) {
|
||||
$this->expectException('yii\base\NotSupportedException');
|
||||
}
|
||||
|
||||
$connection = $this->getConnection(false);
|
||||
$connection->getSlavePdo(true)->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
|
||||
$constraints = $connection->getSchema()->{'getTable' . ucfirst($type)}($tableName, true);
|
||||
|
||||
@ -78,6 +78,8 @@ SQL;
|
||||
{
|
||||
$result = parent::constraintsProvider();
|
||||
|
||||
$result['1: check'][2][0]->expression = "(`C_check` <> _utf8mb4\\'\\')";
|
||||
|
||||
$result['2: primary key'][2]->name = null;
|
||||
|
||||
// Work aroung bug in MySQL 5.1 - it creates only this table in lowercase. O_o
|
||||
|
||||
Reference in New Issue
Block a user