php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36681 pgsql: Deferred constraints do not raise an exception on commit
Submitted: 2006-03-10 14:32 UTC Modified: 2006-09-19 15:46 UTC
Votes:5
Avg. Score:4.4 ± 1.2
Reproduced:5 of 5 (100.0%)
Same Version:3 (60.0%)
Same OS:2 (40.0%)
From: ce at netage dot bg Assigned:
Status: Closed Package: PDO related
PHP Version: 5.1.2 OS: Linux & Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ce at netage dot bg
New email:
PHP Version: OS:

 

 [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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-10 17:52 UTC] kouber@php.net
I'm reproducing the bug on Windows XP with PHP 5.1.2.
 [2006-04-09 08:24 UTC] wez@php.net
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);


 [2006-04-09 13:46 UTC] ce at netage dot bg
I tested it against 5.1.2. It looks to me as if it works! :-)
 [2006-09-19 15:46 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Feb 04 05:01:30 2025 UTC