#47199 [Opn->Fbk]: pg_delete fails on NULL
| From: | jani@php.net | Date: | Fri, 15 May 2009 00:31:01 +0000 |
| Subject: | #47199 [Opn->Fbk]: pg_delete fails on NULL | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-137351@lists.php.net to get a copy of this message | ||
ID: 47199
Updated by: jani@php.net
Reported By: andrew at labyrinth-it dot co dot uk
-Status: Open
+Status: Feedback
Bug Type: PostgreSQL related
Operating System: Linux (Fedora)
PHP Version: 5.2.8
New Comment:
Please try using this CVS snapshot:
http://snaps.php.net/php5.2-latest.tar.gz
For Windows:
http://windows.php.net/snapshots/
Previous Comments:
------------------------------------------------------------------------
[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