From: benjcarson at digitaljunkies dot ca Operating system: Linux PHP version: 5CVS-2004-01-10 (dev) PHP Bug Type: PostgreSQL related Bug description: pg_update & pg_delete ignore PGSQL_DML_EXEC option
Description: ------------ Both pg_update() and pg_delete() ignore the PGSQL_DML_EXEC option and attempt to excute the query regardless of whether it is set or not. This is in contrast to pg_insert() which does not execute the query if PGSQL_DML_EXEC is not set. This also has the side effect of not being able to use pg_update() and pg_delete() with the PGSQL_DML_STRING option to create sql strings for queries that would fail if executed. This can be fixed fairly easily by changing a few lines in the php_pgsql_update() and php_pgsql_delete() functions in pgsql.c to match the behaviour of pg_insert(). On line 4427 of pgsql.c (in the latest CVS checkout, 2004-01-10), in the function php_pgsql_update(), the if statment: if (do_exec(&querystr, PGRES_COMMAND_OK, pg_link, opt TSRMLS_CC) == 0) ret = SUCCESS; Should probably be: if ((opt & (PGSQL_DML_EXEC|PGSQL_DML_ASYNC)) && do_exec(&querystr, PGRES_COMMAND_OK, pg_link, opt TSRMLS_CC) == 0) { ret = SUCCESS; } else if (opt & PGSQL_DML_STRING) { ret = SUCCESS; } The same new if statment can be used to replace the if statment on line 4520 in the php_pgsql_delete() function. Reproduce code: --------------- <?php error_reporting(E_ALL); $con = pg_connect("host=localhost dbname=db user=php password=password"); if (!$con) die("Unable to connect.\n"); $assoc = array("first_name"=>"name"); $where = array("contact_id"=>"8"); $sql = pg_update($con,"employee", $assoc, $where, PGSQL_DML_STRING); if (!$sql) echo "pg_update() failed.\n"; echo $sql; ?> Expected result: ---------------- UPDATE employee SET first_name='name' WHERE contact_id=8; Actual result: -------------- Notice: pg_update(): Failed to execute 'UPDATE employee SET first_name='name' WHERE contact_id=8;' in pg_update.php on line 11 pg_update() failed. -- Edit bug report at http://bugs.php.net/?id=26864&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=26864&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=26864&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=26864&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=26864&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=26864&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=26864&r=needscript Try newer version: http://bugs.php.net/fix.php?id=26864&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=26864&r=support Expected behavior: http://bugs.php.net/fix.php?id=26864&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=26864&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=26864&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=26864&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=26864&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=26864&r=dst IIS Stability: http://bugs.php.net/fix.php?id=26864&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=26864&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=26864&r=float