diff --git a/src/Drivers/PdoPgsql/PdoPgsqlDriver.php b/src/Drivers/PdoPgsql/PdoPgsqlDriver.php index eb73a799..561b79df 100644 --- a/src/Drivers/PdoPgsql/PdoPgsqlDriver.php +++ b/src/Drivers/PdoPgsql/PdoPgsqlDriver.php @@ -141,7 +141,7 @@ protected function createException(string $error, int $errorNo, string $sqlState } elseif ($sqlState === '23502') { return new NotNullConstraintViolationException($error, $errorNo, $sqlState, null, $query); - } elseif ($sqlState === '23503') { + } elseif ($sqlState === '23001' || $sqlState === '23503') { return new ForeignKeyConstraintViolationException($error, $errorNo, $sqlState, null, $query); } elseif ($sqlState === '23505') { diff --git a/src/Drivers/Pgsql/PgsqlDriver.php b/src/Drivers/Pgsql/PgsqlDriver.php index 3fe64f22..55820102 100644 --- a/src/Drivers/Pgsql/PgsqlDriver.php +++ b/src/Drivers/Pgsql/PgsqlDriver.php @@ -341,7 +341,7 @@ protected function createException(string $error, int $errorNo, ?string $sqlStat } elseif ($sqlState === '23502') { return new NotNullConstraintViolationException($error, $errorNo, $sqlState, null, $query); - } elseif ($sqlState === '23503') { + } elseif ($sqlState === '23001' || $sqlState === '23503') { return new ForeignKeyConstraintViolationException($error, $errorNo, $sqlState, null, $query); } elseif ($sqlState === '23505') { diff --git a/tests/cases/integration/exceptions.postgres.phpt b/tests/cases/integration/exceptions.postgres.phpt new file mode 100644 index 00000000..62e17cf0 --- /dev/null +++ b/tests/cases/integration/exceptions.postgres.phpt @@ -0,0 +1,47 @@ +lockConnection($this->connection); + + $this->connection->query('DROP TABLE IF EXISTS dbal_restrict_children'); + $this->connection->query('DROP TABLE IF EXISTS dbal_restrict_parents'); + $this->connection->query('CREATE TABLE dbal_restrict_parents (id INT PRIMARY KEY)'); + $this->connection->query(' + CREATE TABLE dbal_restrict_children ( + parent_id INT NOT NULL REFERENCES dbal_restrict_parents (id) ON DELETE RESTRICT + ) + '); + $this->connection->query('INSERT INTO dbal_restrict_parents (id) VALUES (1)'); + $this->connection->query('INSERT INTO dbal_restrict_children (parent_id) VALUES (1)'); + + try { + Assert::exception(function () { + $this->connection->query('DELETE FROM dbal_restrict_parents WHERE id = 1'); + }, ForeignKeyConstraintViolationException::class); + } finally { + $this->connection->query('DROP TABLE IF EXISTS dbal_restrict_children'); + $this->connection->query('DROP TABLE IF EXISTS dbal_restrict_parents'); + } + } +} + + +$test = new ExceptionsPostgresTest(); +$test->run(); diff --git a/tests/cases/integration/platform.postgres.phpt b/tests/cases/integration/platform.postgres.phpt index a68207c2..ead4bb7c 100644 --- a/tests/cases/integration/platform.postgres.phpt +++ b/tests/cases/integration/platform.postgres.phpt @@ -287,6 +287,8 @@ class PlatformPostgresTest extends IntegrationTestCase public function testPrimarySequence(): void { + $this->lockConnection($this->connection); + Assert::same('public.books_id_seq', $this->connection->getPlatform()->getPrimarySequenceName('books')); $this->connection->query("DROP SEQUENCE IF EXISTS second_schema.temp_sequence_for_test");