Skip to content

Commit 9a1c637

Browse files
authored
Update according changes in db package (#347)
1 parent 28793b0 commit 9a1c637

File tree

4 files changed

+27
-38
lines changed

4 files changed

+27
-38
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
- New #307: Add parameters `$ifExists` and `$cascade` to `CommandInterface::dropTable()` and
4040
`DDLQueryBuilderInterface::dropTable()` methods (@vjik)
4141
- Chg #310: Remove usage of `hasLimit()` and `hasOffset()` methods of `DQLQueryBuilder` class (@Tigrov)
42-
- Enh #313: Refactor according changes in `db` package (@Tigrov)
42+
- Enh #313, #347: Refactor according changes in `db` package (@Tigrov)
4343
- New #311: Add `caseSensitive` option to like condition (@vjik)
4444
- Enh #315: Remove `getCacheKey()` and `getCacheTag()` methods from `Schema` class (@Tigrov)
4545
- Enh #319: Support `boolean` type (@Tigrov)

src/Schema.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use function array_change_key_case;
2121
use function array_column;
2222
use function array_map;
23-
use function array_reverse;
2423
use function implode;
2524
use function in_array;
2625
use function preg_replace;
@@ -70,16 +69,14 @@ protected function resolveTableName(string $name): TableSchemaInterface
7069
{
7170
$resolvedName = new TableSchema();
7271

73-
$parts = array_reverse(
74-
$this->db->getQuoter()->getTableNameParts($name)
75-
);
72+
$parts = $this->db->getQuoter()->getTableNameParts($name);
7673

77-
$resolvedName->name($parts[0] ?? '');
78-
$resolvedName->schemaName($parts[1] ?? $this->defaultSchema);
74+
$resolvedName->name($parts['name']);
75+
$resolvedName->schemaName($parts['schemaName'] ?? $this->defaultSchema);
7976

8077
$resolvedName->fullName(
8178
$resolvedName->getSchemaName() !== $this->defaultSchema ?
82-
implode('.', array_reverse($parts)) : $resolvedName->getName()
79+
implode('.', $parts) : $resolvedName->getName()
8380
);
8481

8582
return $resolvedName;
@@ -257,10 +254,10 @@ protected function loadTableIndexes(string $tableName): array
257254
ORDER BY "uicol"."COLUMN_POSITION" ASC
258255
SQL;
259256

260-
$resolvedName = $this->resolveTableName($tableName);
257+
$nameParts = $this->db->getQuoter()->getTableNameParts($tableName);
261258
$indexes = $this->db->createCommand($sql, [
262-
':schemaName' => $resolvedName->getSchemaName(),
263-
':tableName' => $resolvedName->getName(),
259+
':schemaName' => $nameParts['schemaName'] ?? $this->defaultSchema,
260+
':tableName' => $nameParts['name'],
264261
])->queryAll();
265262

266263
$indexes = array_map(array_change_key_case(...), $indexes);
@@ -623,10 +620,10 @@ private function loadTableConstraints(string $tableName, string $returnType): ar
623620
ORDER BY "uccol"."POSITION" ASC
624621
SQL;
625622

626-
$resolvedName = $this->resolveTableName($tableName);
623+
$nameParts = $this->db->getQuoter()->getTableNameParts($tableName);
627624
$constraints = $this->db->createCommand($sql, [
628-
':schemaName' => $resolvedName->getSchemaName(),
629-
':tableName' => $resolvedName->getName(),
625+
':schemaName' => $nameParts['schemaName'] ?? $this->defaultSchema,
626+
':tableName' => $nameParts['name'],
630627
])->queryAll();
631628

632629
$constraints = array_map(array_change_key_case(...), $constraints);

tests/Provider/QuoterProvider.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ public static function simpleTableNames(): array
5151
public static function tableNameParts(): array
5252
{
5353
return [
54-
['', ''],
55-
['[]', '[]'],
56-
['animal', 'animal'],
57-
['dbo.animal', 'animal', 'dbo'],
58-
['[dbo].[animal]', '[animal]', '[dbo]'],
59-
['[other].[animal2]', '[animal2]', '[other]'],
60-
['other.[animal2]', '[animal2]', 'other'],
61-
['other.animal2', 'animal2', 'other'],
54+
['', ['name' => '']],
55+
['""', ['name' => '']],
56+
['animal', ['name' => 'animal']],
57+
['"animal"', ['name' => 'animal']],
58+
['dbo.animal', ['schemaName' => 'dbo', 'name' => 'animal']],
59+
['"dbo"."animal"', ['schemaName' => 'dbo', 'name' => 'animal']],
60+
['"dbo".animal', ['schemaName' => 'dbo', 'name' => 'animal']],
61+
['dbo."animal"', ['schemaName' => 'dbo', 'name' => 'animal']],
6262
];
6363
}
6464
}

tests/QuoterTest.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,31 @@
44

55
namespace Yiisoft\Db\Oracle\Tests;
66

7+
use PHPUnit\Framework\Attributes\DataProviderExternal;
8+
use Yiisoft\Db\Oracle\Tests\Provider\QuoterProvider;
79
use Yiisoft\Db\Oracle\Tests\Support\TestTrait;
810
use Yiisoft\Db\Tests\AbstractQuoterTest;
911

1012
/**
1113
* @group oracle
12-
*
13-
* @psalm-suppress PropertyNotSetInConstructor
1414
*/
1515
final class QuoterTest extends AbstractQuoterTest
1616
{
1717
use TestTrait;
1818

19-
/**
20-
* @dataProvider \Yiisoft\Db\Oracle\Tests\Provider\QuoterProvider::tableNameParts
21-
*/
22-
public function testGetTableNameParts(string $tableName, string ...$expected): void
19+
#[DataProviderExternal(QuoterProvider::class, 'tableNameParts')]
20+
public function testGetTableNameParts(string $tableName, array $expected): void
2321
{
24-
parent::testGetTableNameParts($tableName, ...$expected);
22+
parent::testGetTableNameParts($tableName, $expected);
2523
}
2624

27-
/**
28-
* @dataProvider \Yiisoft\Db\Oracle\Tests\Provider\QuoterProvider::columnNames
29-
*/
25+
#[DataProviderExternal(QuoterProvider::class, 'columnNames')]
3026
public function testQuoteColumnName(string $columnName, string $expected): void
3127
{
3228
parent::testQuoteColumnName($columnName, $expected);
3329
}
3430

35-
/**
36-
* @dataProvider \Yiisoft\Db\Oracle\Tests\Provider\QuoterProvider::simpleColumnNames
37-
*/
31+
#[DataProviderExternal(QuoterProvider::class, 'simpleColumnNames')]
3832
public function testQuoteSimpleColumnName(
3933
string $columnName,
4034
string $expectedQuotedColumnName,
@@ -43,9 +37,7 @@ public function testQuoteSimpleColumnName(
4337
parent::testQuoteSimpleColumnName($columnName, $expectedQuotedColumnName, $expectedUnQuotedColumnName);
4438
}
4539

46-
/**
47-
* @dataProvider \Yiisoft\Db\Oracle\Tests\Provider\QuoterProvider::simpleTableNames
48-
*/
40+
#[DataProviderExternal(QuoterProvider::class, 'simpleTableNames')]
4941
public function testQuoteTableName(string $tableName, string $expected): void
5042
{
5143
parent::testQuoteTableName($tableName, $expected);

0 commit comments

Comments
 (0)