ID: 47199
User updated by: andrew at labyrinth-it dot co dot uk
Reported By: andrew at labyrinth-it dot co dot uk
-Status: No Feedback
+Status: Open
Bug Type: PostgreSQL related
Operating System: Linux (Fedora)
PHP Version: 5.2.8
New Comment:
Sorry, I think I posted my reply in the wrong place, so let me try
again.
I have just downloaded and tested the latest PHP version:
PHP 5.2.10RC2-dev (cli) (built: May 31 2009 07:16:36)
With this version I still get the same error. The Postgresql version I
am testing against is:
PostgreSQL 8.3.5 on i386-redhat-linux-gnu, compiled by GCC gcc (GCC)
4.3.2 20081007 (Red Hat 4.3.2-6)
The call to:
print(pg_delete($db,'demo',$row,PGSQL_DML_STRING))
still prints out:
DELETE FROM demo WHERE id=1 AND col1=NULL;
The final test should use the SQL language "IS NULL" test rather than
"=NULL" which never evaluates to true.
The same problem exists if using pg_update, which produces:
UPDATE demo SET id=2,col1='Two' WHERE id=1 AND col1=NULL;
Again, "col1=NULL" will never evaluate to true using SQL, and the test
col1 IS NULL should be used instead.
Previous Comments:
------------------------------------------------------------------------
[2009-05-22 01:00:00] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
------------------------------------------------------------------------
[2009-05-19 15:34:41] andrew at labyrinth-it dot co dot uk
For completeness, I get the error running on Fedora 10 with Postgres
8.3.5
------------------------------------------------------------------------
[2009-05-19 15:31:54] andrew at labyrinth-it dot co dot uk
I am using:
PHP 5.2.10-dev (cli) (built: May 19 2009 15:40:36)
and still get the same error result.
This error is also in the pg_update function, where NULl values are
compared with "= NULL" rather than "IS NULL" in the WHERE part of the
generated SQL.
------------------------------------------------------------------------
[2009-05-15 00:31:00] jani@php.net
Please try using this CVS snapshot:
http://snaps.php.net/php5.2-latest.tar.gz
For Windows:
http://windows.php.net/snapshots/
------------------------------------------------------------------------
[2009-01-23 11:46:35] andrew at labyrinth-it dot co dot uk
Description:
------------
pg_delete uses incorrect syntax for NULL columns. The code generated
compares values with "col = NULL" instead of "col IS NULL". As a result,
the row is not matched so is not deleted.
Reproduce code:
---------------
<?php
$db = pg_connect("host=localhost dbname=andrew user=andrew
password=andrew");
$sql = 'SELECT * FROM demo';
$qry = pg_query($sql);
while ($row = pg_fetch_array($qry, null, PGSQL_ASSOC)) {
print_r($row);
pg_delete($db,'demo',$row); //1
print(pg_delete($db,'demo',$row,PGSQL_DML_STRING))
}
pg_free_result($qry);
$qry = pg_query($sql);
while ($row = pg_fetch_array($qry, null, PGSQL_ASSOC)) {
print_r($row); //2
}
pg_free_result($qry);
pg_close($db);
Expected result:
----------------
The first loop should read and display all rows in the table, and then
delete the rows. The second loop should not display any data at all.
---
Array
(
[id] => 1
[col1] =>
)
DELETE FROM demo WHERE id=1 AND col1 IS NULL;
Actual result:
--------------
When this runs, the second loop displays results for tables that have
NULL columns at the start of the run.
---
Array
(
[id] => 1
[col1] =>
)
DELETE FROM demo WHERE id=1 AND col1=NULL;
Array
(
[id] => 1
[col1] =>
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=47199&edit=1