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