From: Operating system: Linux PHP version: 5.2.13 Package: PostgreSQL related Bug Type: Bug Bug description:Cannot use SAVEPOINTs to recover from exceptions/errors
Description: ------------ Cannot use SAVEPOINTs to recover from errors/exceptions in a transaction. This method of wrapping multiple statements in a transaction, one or more of which can fail without aborting the transaction is outlined here : http://wiki.postgresql.org/wiki/Transactions_recovering_failures_in_scripts Test script: --------------- $dbconn = pg_connect("dbname=test") or die("Could not connect"); $query = "BEGIN; CREATE TABLE mytable(id INT CHECK (id < 5)); SAVEPOINT savepoint1; INSERT INTO mytable VALUES (8); RELEASE savepoint1; SAVEPOINT savepoint1; ROLLBACK TO savepoint1; RELEASE savepoint1; SAVEPOINT savepoint1; INSERT INTO mytable VALUES (1); RELEASE savepoint1; SAVEPOINT savepoint1; ROLLBACK TO savepoint1; RELEASE savepoint1; COMMIT;"; pg_query($dbconn, $query); echo pg_last_error(); Expected result: ---------------- The query should the table, fail the first insert, rollback, second insert succeeds then commits. This is what the SQL will do when put into psql (postgresql console). Actual result: -------------- Transaction fails entirely on the first check violation and does not continue: ERROR: new row for relation "mytable" violates check constraint "mytable_id_check" -- Edit bug report at http://bugs.php.net/bug.php?id=52294&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=52294&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=52294&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=52294&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=52294&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=52294&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=52294&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=52294&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=52294&r=needscript Try newer version: http://bugs.php.net/fix.php?id=52294&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=52294&r=support Expected behavior: http://bugs.php.net/fix.php?id=52294&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=52294&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=52294&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=52294&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52294&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=52294&r=dst IIS Stability: http://bugs.php.net/fix.php?id=52294&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=52294&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=52294&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=52294&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=52294&r=mysqlcfg