Skip to content

Commit

Permalink
Mark not supported constraint retrieving methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeymakinen committed Jun 28, 2017
1 parent e0df642 commit 452974c
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 14 deletions.
7 changes: 5 additions & 2 deletions framework/db/cubrid/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace yii\db\cubrid;

use yii\base\NotSupportedException;
use yii\db\Constraint;
use yii\db\ConstraintFinderTrait;
use yii\db\Expression;
Expand Down Expand Up @@ -210,18 +211,20 @@ protected function loadTableUniques($tableName)

/**
* @inheritDoc
* @throws NotSupportedException if this method is called.
*/
protected function loadTableChecks($tableName)
{
return [];
throw new NotSupportedException('CUBRID does not support check constraints.');
}

/**
* @inheritDoc
* @throws NotSupportedException if this method is called.
*/
protected function loadTableDefaultValues($tableName)
{
return [];
throw new NotSupportedException('CUBRID does not support default value constraints.');
}

/**
Expand Down
7 changes: 5 additions & 2 deletions framework/db/mysql/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace yii\db\mysql;

use yii\base\InvalidConfigException;
use yii\base\NotSupportedException;
use yii\db\ColumnSchema;
use yii\db\Constraint;
use yii\db\ConstraintFinderTrait;
Expand Down Expand Up @@ -177,18 +178,20 @@ protected function loadTableUniques($tableName)

/**
* @inheritDoc
* @throws NotSupportedException if this method is called.
*/
protected function loadTableChecks($tableName)
{
return [];
throw new NotSupportedException('MySQL does not support check constraints.');
}

/**
* @inheritDoc
* @throws NotSupportedException if this method is called.
*/
protected function loadTableDefaultValues($tableName)
{
return [];
throw new NotSupportedException('MySQL does not support default value constraints.');
}

/**
Expand Down
4 changes: 3 additions & 1 deletion framework/db/oci/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace yii\db\oci;

use yii\base\InvalidCallException;
use yii\base\NotSupportedException;
use yii\db\CheckConstraint;
use yii\db\ColumnSchema;
use yii\db\Connection;
Expand Down Expand Up @@ -220,10 +221,11 @@ protected function loadTableChecks($tableName)

/**
* @inheritDoc
* @throws NotSupportedException if this method is called.
*/
protected function loadTableDefaultValues($tableName)
{
return [];
throw new NotSupportedException('Oracle does not support default value constraints.');
}

/**
Expand Down
4 changes: 3 additions & 1 deletion framework/db/pgsql/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace yii\db\pgsql;

use yii\base\NotSupportedException;
use yii\db\CheckConstraint;
use yii\db\Constraint;
use yii\db\ConstraintFinderTrait;
Expand Down Expand Up @@ -260,10 +261,11 @@ protected function loadTableChecks($tableName)

/**
* @inheritDoc
* @throws NotSupportedException if this method is called.
*/
protected function loadTableDefaultValues($tableName)
{
return [];
throw new NotSupportedException('PostgreSQL does not support default value constraints.');
}

/**
Expand Down
5 changes: 3 additions & 2 deletions framework/db/sqlite/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,11 @@ protected function loadTableChecks($tableName)

/**
* @inheritDoc
* @throws NotSupportedException if this method is called.
*/
protected function loadTableDefaultValues($tableName)
{
return [];
throw new NotSupportedException('SQLite does not support default value constraints.');
}

/**
Expand Down Expand Up @@ -362,7 +363,7 @@ protected function loadColumnSchema($info)
* Sets the isolation level of the current transaction.
* @param string $level The transaction isolation level to use for this transaction.
* This can be either [[Transaction::READ_UNCOMMITTED]] or [[Transaction::SERIALIZABLE]].
* @throws \yii\base\NotSupportedException when unsupported isolation levels are used.
* @throws NotSupportedException when unsupported isolation levels are used.
* SQLite only supports SERIALIZABLE and READ UNCOMMITTED.
* @see http://www.sqlite.org/pragma.html#pragma_read_uncommitted
*/
Expand Down
20 changes: 16 additions & 4 deletions tests/framework/db/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ public function constraintsProvider()
'isUnique' => true,
]),
]],
'1: default' => ['T_constraints_1', 'defaultValues', []],
'1: default' => ['T_constraints_1', 'defaultValues', false],

'2: primary key' => ['T_constraints_2', 'primaryKey', new Constraint([
'name' => 'CN_pk',
Expand Down Expand Up @@ -518,7 +518,7 @@ public function constraintsProvider()
]),
]],
'2: check' => ['T_constraints_2', 'checks', []],
'2: default' => ['T_constraints_2', 'defaultValues', []],
'2: default' => ['T_constraints_2', 'defaultValues', false],

'3: primary key' => ['T_constraints_3', 'primaryKey', null],
'3: foreign key' => ['T_constraints_3', 'foreignKeys', [
Expand All @@ -541,7 +541,7 @@ public function constraintsProvider()
]),
]],
'3: check' => ['T_constraints_3', 'checks', []],
'3: default' => ['T_constraints_3', 'defaultValues', []],
'3: default' => ['T_constraints_3', 'defaultValues', false],

'4: primary key' => ['T_constraints_4', 'primaryKey', new Constraint([
'name' => AnyValue::getInstance(),
Expand All @@ -554,7 +554,7 @@ public function constraintsProvider()
]),
]],
'4: check' => ['T_constraints_4', 'checks', []],
'4: default' => ['T_constraints_4', 'defaultValues', []],
'4: default' => ['T_constraints_4', 'defaultValues', false],
];
}

Expand All @@ -573,6 +573,10 @@ public function uppercaseConstraintsProvider()
*/
public function testTableSchemaConstraints($tableName, $type, $expected)
{
if ($expected === false) {
$this->expectException('yii\base\NotSupportedException');
}

$constraints = $this->getConnection(false)->getSchema()->{'getTable' . ucfirst($type)}($tableName);
$this->assertMetadataEquals($expected, $constraints);
}
Expand All @@ -582,6 +586,10 @@ public function testTableSchemaConstraints($tableName, $type, $expected)
*/
public function testTableSchemaConstraintsWithPdoUppercase($tableName, $type, $expected)
{
if ($expected === false) {
$this->expectException('yii\base\NotSupportedException');
}

$connection = $this->getConnection(false);
$connection->getSlavePdo()->setAttribute(PDO::ATTR_CASE, PDO::CASE_UPPER);
$constraints = $connection->getSchema()->{'getTable' . ucfirst($type)}($tableName, true);
Expand All @@ -593,6 +601,10 @@ public function testTableSchemaConstraintsWithPdoUppercase($tableName, $type, $e
*/
public function testTableSchemaConstraintsWithPdoLowercase($tableName, $type, $expected)
{
if ($expected === false) {
$this->expectException('yii\base\NotSupportedException');
}

$connection = $this->getConnection(false);
$connection->getSlavePdo()->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
$constraints = $connection->getSchema()->{'getTable' . ucfirst($type)}($tableName, true);
Expand Down
6 changes: 5 additions & 1 deletion tests/framework/db/cubrid/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,18 @@ public function constraintsProvider()
foreach ($result as $name => $constraints) {
$result[$name][2] = $this->convertPropertiesToAnycase($constraints[2]);
}
$result['1: check'][2] = [];
$result['1: check'][2] = false;
unset($result['1: index'][2][0]);

$result['2: check'][2] = false;
unset($result['2: index'][2][0]);

$result['3: foreign key'][2][0]->onDelete = 'RESTRICT';
$result['3: foreign key'][2][0]->onUpdate = 'RESTRICT';
$result['3: index'][2] = [];
$result['3: check'][2] = false;

$result['4: check'][2] = false;
return $result;
}

Expand Down
6 changes: 6 additions & 0 deletions tests/framework/db/mssql/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,20 @@ public function constraintsProvider()
{
$result = parent::constraintsProvider();
$result['1: check'][2][0]->expression = '([C_check]<>\'\')';
$result['1: default'][2] = [];
$result['1: default'][2][] = new DefaultValueConstraint([
'name' => AnyValue::getInstance(),
'columnNames' => ['C_default'],
'value' => '((0))',
]);

$result['2: default'][2] = [];

$result['3: foreign key'][2][0]->foreignSchemaName = 'dbo';
$result['3: index'][2] = [];
$result['3: default'][2] = [];

$result['4: default'][2] = [];
return $result;
}
}
6 changes: 5 additions & 1 deletion tests/framework/db/mysql/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ class SchemaTest extends \yiiunit\framework\db\SchemaTest
public function constraintsProvider()
{
$result = parent::constraintsProvider();
$result['1: check'][2] = [];
$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;
}
}

0 comments on commit 452974c

Please sign in to comment.