Skip to content

Commit 84e721d

Browse files
committed
fix pgsql/mssql/oracle missing quote
1 parent 073cbf2 commit 84e721d

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

phpstan.neon.dist

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ parameters:
3232

3333
# fix https://github.com/phpstan/phpstan-deprecation-rules/issues/52 and https://github.com/phpstan/phpstan/issues/6444
3434
-
35-
message: '~^Call to method (getVarcharTypeDeclarationSQL|getClobTypeDeclarationSQL|getCreateTableSQL)\(\) of deprecated class Doctrine\\DBAL\\Platforms\\(SQLServerPlatform|AbstractPlatform):\nUse.+instead\.$~'
35+
message: '~^Call to method (getVarcharTypeDeclarationSQL|getClobTypeDeclarationSQL|getCreateTableSQL|getCurrentDatabaseExpression)\(\) of deprecated class Doctrine\\DBAL\\Platforms\\(PostgreSQLPlatform|SQLServerPlatform|AbstractPlatform):\nUse.+instead\.$~'
3636
path: '*'
37-
count: 3
37+
count: 5
3838

3939
# TODO these rules are generated, this ignores should be fixed in the code
4040
# for src/Schema/TestCase.php

src/Schema/Migrator.php

+16-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111
use Atk4\Data\Persistence;
1212
use Atk4\Data\Persistence\Sql\Connection;
1313
use Atk4\Data\Reference\HasOne;
14+
use Doctrine\DBAL\Driver\Exception as DbalDriverException;
15+
use Doctrine\DBAL\Exception\DatabaseObjectNotFoundException;
1416
use Doctrine\DBAL\Exception\TableNotFoundException;
1517
use Doctrine\DBAL\Platforms\AbstractPlatform;
1618
use Doctrine\DBAL\Platforms\MySQLPlatform;
1719
use Doctrine\DBAL\Platforms\OraclePlatform;
1820
use Doctrine\DBAL\Platforms\SqlitePlatform;
21+
use Doctrine\DBAL\Platforms\SQLServerPlatform;
1922
use Doctrine\DBAL\Schema\AbstractSchemaManager;
2023
use Doctrine\DBAL\Schema\Table;
2124

@@ -107,8 +110,19 @@ public function create(): self
107110

108111
public function drop(): self
109112
{
110-
$this->createSchemaManager()
111-
->dropTable($this->getDatabasePlatform()->quoteIdentifier($this->table->getName()));
113+
try {
114+
$this->createSchemaManager()
115+
->dropTable($this->getDatabasePlatform()->quoteIdentifier($this->table->getName()));
116+
} catch (DatabaseObjectNotFoundException $e) {
117+
// fix exception not converted to TableNotFoundException for MSSQL
118+
// https://github.com/doctrine/dbal/pull/5492
119+
if ($this->getDatabasePlatform() instanceof SQLServerPlatform && $e->getPrevious() instanceof DbalDriverException
120+
&& preg_match('~[cC]annot drop the table \'.*\', because it does not exist or you do not have permission\.~', $e->getMessage())) {
121+
throw new TableNotFoundException($e->getPrevious(), $e->getQuery());
122+
}
123+
124+
throw $e;
125+
}
112126

113127
$this->createdTableNames = array_diff($this->createdTableNames, [$this->table->getName()]);
114128

tests/RandomTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ public function testTableWithSchema(): void
567567
$runWithDb = false;
568568
} else {
569569
$dbSchema = $this->db->getConnection()->dsql()
570-
->field(new Expression($this->getDatabasePlatform()->getCurrentDatabaseExpression(true)))
570+
->field(new Expression($this->getDatabasePlatform()->getCurrentDatabaseExpression(true))) // @phpstan-ignore-line
571571
->getOne();
572572
$userSchema = $dbSchema;
573573
$docSchema = $dbSchema;

tests/Schema/MigratorTest.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Doctrine\DBAL\Platforms\OraclePlatform;
1515
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
1616
use Doctrine\DBAL\Platforms\SQLServerPlatform;
17+
use Doctrine\DBAL\Schema\Identifier as DbalIdentifier;
1718

1819
class MigratorTest extends TestCase
1920
{
@@ -35,7 +36,14 @@ protected function createDemoMigrator(string $table): Migrator
3536

3637
protected function isTableExist(string $table): bool
3738
{
38-
return $this->createSchemaManager()->tablesExist([$table]);
39+
foreach ($this->createSchemaManager()->listTableNames() as $v) {
40+
$vUnquoted = (new DbalIdentifier($v))->getName();
41+
if ($vUnquoted === $table) {
42+
return true;
43+
}
44+
}
45+
46+
return false;
3947
}
4048

4149
public function testCreate(): void

0 commit comments

Comments
 (0)