Skip to content

Commit 1c9760d

Browse files
authored
Remove support dots in table names (#380)
1 parent 737fe6d commit 1c9760d

File tree

4 files changed

+6
-24
lines changed

4 files changed

+6
-24
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
- Enh #372: Provide `yiisoft/db-implementation` virtual package (@vjik)
5151
- Enh #375: Adapt to `Param` refactoring in `yiisoft/db` package (@vjik)
5252
- Enh #376: Adapt to conditions refactoring in `yiisoft/db` package (@vjik)
53+
- Enh #380: Remove support dots in table names (@Tigrov)
5354

5455
## 1.2.0 March 21, 2024
5556

src/Quoter.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,17 @@
88

99
use function array_map;
1010
use function array_slice;
11-
use function preg_match;
12-
use function preg_match_all;
11+
use function explode;
1312

1413
/**
1514
* Implements the MSSQL Server quoting and unquoting methods.
1615
*/
1716
final class Quoter extends BaseQuoter
1817
{
19-
public function quoteColumnName(string $name): string
20-
{
21-
if (preg_match('/^\[.*]$/', $name)) {
22-
return $name;
23-
}
24-
25-
return parent::quoteColumnName($name);
26-
}
27-
2818
public function getTableNameParts(string $name, bool $withColumn = false): array
2919
{
30-
if (preg_match_all('/([^.\[\]]+)|\[([^\[\]]+)]/', $name, $matches) > 0) {
31-
$parts = array_slice($matches[0], -4, 4);
32-
33-
return array_map($this->unquoteSimpleTableName(...), $parts);
34-
}
20+
$parts = array_slice(explode('.', $name), -4, 4);
3521

36-
return [$this->unquoteSimpleTableName($name)];
22+
return array_map($this->unquoteSimpleTableName(...), $parts);
3723
}
3824
}

tests/Provider/QuoterProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public static function tableNameParts(): array
4747
['catalog.other.animal2', 'animal2', 'other', 'catalog'],
4848
['server.catalog.other.animal2', 'animal2', 'other', 'catalog', 'server'],
4949
['unknown_part.server.catalog.other.animal2', 'animal2', 'other', 'catalog', 'server'],
50-
['[[dbo]].[[animal]]', 'animal', 'dbo'],
51-
['[[other]].[[animal2]]', 'animal2', 'other'],
50+
['{{dbo}}.{{animal}}', '{{animal}}', '{{dbo}}'],
51+
['{{other}}.{{animal2}}', '{{animal2}}', '{{other}}'],
5252
];
5353
}
5454
}

tests/Support/Fixture/mssql.sql

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ IF OBJECT_ID('[T_constraints_1]', 'U') IS NOT NULL DROP TABLE [T_constraints_1];
2828
IF OBJECT_ID('[T_upsert]', 'U') IS NOT NULL DROP TABLE [T_upsert];
2929
IF OBJECT_ID('[T_upsert_1]', 'U') IS NOT NULL DROP TABLE [T_upsert_1];
3030
IF OBJECT_ID('[T_upsert_varbinary]', 'U') IS NOT NULL DROP TABLE [T_upsert_varbinary];
31-
IF OBJECT_ID('[table.with.special.characters]', 'U') IS NOT NULL DROP TABLE [table.with.special.characters];
3231
IF OBJECT_ID('[foo1]', 'U') IS NOT NULL DROP TABLE [foo1];
3332
IF OBJECT_ID('[stranger ''table]', 'U') IS NOT NULL DROP TABLE [stranger 'table];
3433

@@ -356,10 +355,6 @@ CREATE TABLE [T_upsert_1]
356355
[a] INT NOT NULL PRIMARY KEY
357356
);
358357

359-
CREATE TABLE [dbo].[table.with.special.characters] (
360-
[id] [int]
361-
);
362-
363358
CREATE TABLE [T_upsert_varbinary]
364359
(
365360
[id] INT NOT NULL,

0 commit comments

Comments
 (0)