Skip to content
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 src/Drivers/PdoPgsql/PdoPgsqlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
2 changes: 1 addition & 1 deletion src/Drivers/Pgsql/PgsqlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
47 changes: 47 additions & 0 deletions tests/cases/integration/exceptions.postgres.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php declare(strict_types = 1);

/**
* @testCase
* @dataProvider? ../../databases.ini pgsql
*/

namespace NextrasTests\Dbal;

use Nextras\Dbal\Drivers\Exception\ForeignKeyConstraintViolationException;
use Tester\Assert;

require_once __DIR__ . '/../../bootstrap.php';


class ExceptionsPostgresTest extends IntegrationTestCase
{

public function testForeignKeyRestrictException()
{
$this->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();
2 changes: 2 additions & 0 deletions tests/cases/integration/platform.postgres.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Loading