Skip to content

Update according changes in db package #347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
- New #307: Add parameters `$ifExists` and `$cascade` to `CommandInterface::dropTable()` and
`DDLQueryBuilderInterface::dropTable()` methods (@vjik)
- Chg #310: Remove usage of `hasLimit()` and `hasOffset()` methods of `DQLQueryBuilder` class (@Tigrov)
- Enh #313: Refactor according changes in `db` package (@Tigrov)
- Enh #313, #347: Refactor according changes in `db` package (@Tigrov)
- New #311: Add `caseSensitive` option to like condition (@vjik)
- Enh #315: Remove `getCacheKey()` and `getCacheTag()` methods from `Schema` class (@Tigrov)
- Enh #319: Support `boolean` type (@Tigrov)
Expand Down
23 changes: 10 additions & 13 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use function array_change_key_case;
use function array_column;
use function array_map;
use function array_reverse;
use function implode;
use function in_array;
use function preg_replace;
Expand Down Expand Up @@ -70,16 +69,14 @@ protected function resolveTableName(string $name): TableSchemaInterface
{
$resolvedName = new TableSchema();

$parts = array_reverse(
$this->db->getQuoter()->getTableNameParts($name)
);
$parts = $this->db->getQuoter()->getTableNameParts($name);

$resolvedName->name($parts[0] ?? '');
$resolvedName->schemaName($parts[1] ?? $this->defaultSchema);
$resolvedName->name($parts['name']);
$resolvedName->schemaName($parts['schemaName'] ?? $this->defaultSchema);

$resolvedName->fullName(
$resolvedName->getSchemaName() !== $this->defaultSchema ?
implode('.', array_reverse($parts)) : $resolvedName->getName()
implode('.', $parts) : $resolvedName->getName()
);

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

$resolvedName = $this->resolveTableName($tableName);
$nameParts = $this->db->getQuoter()->getTableNameParts($tableName);
$indexes = $this->db->createCommand($sql, [
':schemaName' => $resolvedName->getSchemaName(),
':tableName' => $resolvedName->getName(),
':schemaName' => $nameParts['schemaName'] ?? $this->defaultSchema,
':tableName' => $nameParts['name'],
])->queryAll();

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

$resolvedName = $this->resolveTableName($tableName);
$nameParts = $this->db->getQuoter()->getTableNameParts($tableName);
$constraints = $this->db->createCommand($sql, [
':schemaName' => $resolvedName->getSchemaName(),
':tableName' => $resolvedName->getName(),
':schemaName' => $nameParts['schemaName'] ?? $this->defaultSchema,
':tableName' => $nameParts['name'],
])->queryAll();

$constraints = array_map(array_change_key_case(...), $constraints);
Expand Down
16 changes: 8 additions & 8 deletions tests/Provider/QuoterProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ public static function simpleTableNames(): array
public static function tableNameParts(): array
{
return [
['', ''],
['[]', '[]'],
['animal', 'animal'],
['dbo.animal', 'animal', 'dbo'],
['[dbo].[animal]', '[animal]', '[dbo]'],
['[other].[animal2]', '[animal2]', '[other]'],
['other.[animal2]', '[animal2]', 'other'],
['other.animal2', 'animal2', 'other'],
['', ['name' => '']],
['""', ['name' => '']],
['animal', ['name' => 'animal']],
['"animal"', ['name' => 'animal']],
['dbo.animal', ['schemaName' => 'dbo', 'name' => 'animal']],
['"dbo"."animal"', ['schemaName' => 'dbo', 'name' => 'animal']],
['"dbo".animal', ['schemaName' => 'dbo', 'name' => 'animal']],
['dbo."animal"', ['schemaName' => 'dbo', 'name' => 'animal']],
];
}
}
24 changes: 8 additions & 16 deletions tests/QuoterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,31 @@

namespace Yiisoft\Db\Oracle\Tests;

use PHPUnit\Framework\Attributes\DataProviderExternal;
use Yiisoft\Db\Oracle\Tests\Provider\QuoterProvider;
use Yiisoft\Db\Oracle\Tests\Support\TestTrait;
use Yiisoft\Db\Tests\AbstractQuoterTest;

/**
* @group oracle
*
* @psalm-suppress PropertyNotSetInConstructor
*/
final class QuoterTest extends AbstractQuoterTest
{
use TestTrait;

/**
* @dataProvider \Yiisoft\Db\Oracle\Tests\Provider\QuoterProvider::tableNameParts
*/
public function testGetTableNameParts(string $tableName, string ...$expected): void
#[DataProviderExternal(QuoterProvider::class, 'tableNameParts')]
public function testGetTableNameParts(string $tableName, array $expected): void
{
parent::testGetTableNameParts($tableName, ...$expected);
parent::testGetTableNameParts($tableName, $expected);
}

/**
* @dataProvider \Yiisoft\Db\Oracle\Tests\Provider\QuoterProvider::columnNames
*/
#[DataProviderExternal(QuoterProvider::class, 'columnNames')]
public function testQuoteColumnName(string $columnName, string $expected): void
{
parent::testQuoteColumnName($columnName, $expected);
}

/**
* @dataProvider \Yiisoft\Db\Oracle\Tests\Provider\QuoterProvider::simpleColumnNames
*/
#[DataProviderExternal(QuoterProvider::class, 'simpleColumnNames')]
public function testQuoteSimpleColumnName(
string $columnName,
string $expectedQuotedColumnName,
Expand All @@ -43,9 +37,7 @@ public function testQuoteSimpleColumnName(
parent::testQuoteSimpleColumnName($columnName, $expectedQuotedColumnName, $expectedUnQuotedColumnName);
}

/**
* @dataProvider \Yiisoft\Db\Oracle\Tests\Provider\QuoterProvider::simpleTableNames
*/
#[DataProviderExternal(QuoterProvider::class, 'simpleTableNames')]
public function testQuoteTableName(string $tableName, string $expected): void
{
parent::testQuoteTableName($tableName, $expected);
Expand Down