|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2006-03-10 14:32 UTC] ce at netage dot bg
 Description:
------------
When using deferred constraints in postgresql, the commit statement doesn't raise exception on constraint violation
Reproduce code:
---------------
create table parent (id integer not null primary key);
create table child (parent integer not null references parent(id) deferrable);
$dbh = new PDO('pgsql:dbname=test;host=localhost');
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbh->beginTransaction();
$dbh->exec('SET CONSTRAINTS ALL DEFERRED');
$dbh->exec('insert into child VALUES (1)');
$dbh->commit();
Expected result:
----------------
PHP Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE[23503]: Foreign key violation: 7 ERROR:  insert or update on table "child" violates foreign key constraint "child_parent_fkey"
Actual result:
--------------
nothing
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 20:00:01 2025 UTC | 
My guess is that this patch will fix this issue, but I haven't tried it: Index: pgsql_driver.c =================================================================== RCS file: /repository/php-src/ext/pdo_pgsql/pgsql_driver.c,v retrieving revision 1.53.2.14 diff -u -p -r1.53.2.14 pgsql_driver.c --- pgsql_driver.c 9 Apr 2006 08:17:50 -0000 1.53.2.14 +++ pgsql_driver.c 9 Apr 2006 08:23:52 -0000 @@ -470,6 +470,7 @@ static int pdo_pgsql_transaction_cmd(con if (PQresultStatus(res) != PGRES_COMMAND_OK) { ret = 0; + pdo_pgsql_error(dbh, PQresultStatus(res), pdo_pgsql_sqlstate(res)); } PQclear(res);