#26864 [Opn->Csd]: pg_update & pg_delete ignore PGSQL_DML_EXEC option
| From: | iliaa@php.net | Date: | Sun, 11 Jan 2004 21:13:46 +0000 |
| Subject: | #26864 [Opn->Csd]: pg_update & pg_delete ignore PGSQL_DML_EXEC option | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-53142@lists.php.net to get a copy of this message | ||
ID: 26864
Updated by: iliaa@php.net
Reported By: benjcarson at digitaljunkies dot ca
-Status: Open
+Status: Closed
Bug Type: PostgreSQL related
Operating System: Linux
PHP Version: 5CVS-2004-01-10 (dev)
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2004-01-10 17:08:27] benjcarson at digitaljunkies dot ca
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 this bug report at http://bugs.php.net/?id=26864&edit=1