|
11 | 11 | use Atk4\Data\Persistence;
|
12 | 12 | use Atk4\Data\Persistence\Sql\Connection;
|
13 | 13 | use Atk4\Data\Reference\HasOne;
|
| 14 | +use Doctrine\DBAL\Driver\Exception as DbalDriverException; |
| 15 | +use Doctrine\DBAL\Exception\DatabaseObjectNotFoundException; |
14 | 16 | use Doctrine\DBAL\Exception\TableNotFoundException;
|
15 | 17 | use Doctrine\DBAL\Platforms\AbstractPlatform;
|
16 | 18 | use Doctrine\DBAL\Platforms\MySQLPlatform;
|
17 | 19 | use Doctrine\DBAL\Platforms\OraclePlatform;
|
18 | 20 | use Doctrine\DBAL\Platforms\SqlitePlatform;
|
| 21 | +use Doctrine\DBAL\Platforms\SQLServerPlatform; |
19 | 22 | use Doctrine\DBAL\Schema\AbstractSchemaManager;
|
20 | 23 | use Doctrine\DBAL\Schema\Table;
|
21 | 24 |
|
@@ -107,8 +110,19 @@ public function create(): self
|
107 | 110 |
|
108 | 111 | public function drop(): self
|
109 | 112 | {
|
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 | + } |
112 | 126 |
|
113 | 127 | $this->createdTableNames = array_diff($this->createdTableNames, [$this->table->getName()]);
|
114 | 128 |
|
|
0 commit comments