php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26864 pg_update & pg_delete ignore PGSQL_DML_EXEC option
Submitted: 2004-01-10 17:08 UTC Modified: 2004-01-11 16:13 UTC
From: benjcarson at digitaljunkies dot ca Assigned:
Status: Closed Package: PostgreSQL related
PHP Version: 5CVS-2004-01-10 (dev) OS: Linux
Private report: No CVE-ID:
 [2004-01-10 17:08 UTC] 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.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-11 16:13 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-2014 The PHP Group
All rights reserved.
Last updated: Thu Apr 17 01:01:56 2014 UTC