Patch bug47199_patch.diff for PostgreSQL related Bug #47199
Patch version 2010-04-12 03:01 UTC
Return to Bug #47199 |
Download this patch
Patch Revisions:
Developer: ewgraf@gmail.com
Index: ext/pgsql/tests/bug47199.phpt
===================================================================
--- ext/pgsql/tests/bug47199.phpt (revision 0)
+++ ext/pgsql/tests/bug47199.phpt (revision 0)
@@ -0,0 +1,23 @@
+--TEST--
+Bug #47199 pg_delete fails on NULL
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+?>
+--FILE--
+<?php
+
+require_once('config.inc');
+
+$dbh = @pg_connect($conn_str);
+$tbl_name = 'test_47199';
+@pg_query("DROP TABLE $tbl_name");
+pg_query("CREATE TABLE $tbl_name (null_field INT, not_null_field INT)");
+print(pg_delete($dbh, $tbl_name, array('null_field' => NULL,
'not_null_field' => 2),PGSQL_DML_STRING));
+@pg_query("DROP TABLE $tbl_name");
+pg_close($dbh);
+echo PHP_EOL."Done".PHP_EOL;
+?>
+--EXPECTF--
+DELETE FROM %s WHERE null_field IS NULL AND not_null_field=2;
+Done
Index: ext/pgsql/pgsql.c
===================================================================
--- ext/pgsql/pgsql.c (revision 294790)
+++ ext/pgsql/pgsql.c (working copy)
@@ -5523,7 +5523,7 @@
}
/* }}} */
-static inline int build_assignment_string(smart_str *querystr,
HashTable *ht, const char *pad, int pad_len TSRMLS_DC)
+static inline int build_assignment_string(smart_str *querystr,
HashTable *ht, int where_cond, const char *pad, int pad_len TSRMLS_DC)
{
HashPosition pos;
uint fld_len;
@@ -5542,8 +5542,13 @@
return -1;
}
smart_str_appendl(querystr, fld, fld_len - 1);
- smart_str_appendc(querystr, '=');
+ if (where_cond && Z_TYPE_PP(val) == IS_STRING &&
!strcmp(Z_STRVAL_PP(val), "NULL")) {
+ smart_str_appends(querystr, " IS ");
+ } else {
+ smart_str_appendc(querystr, '=');
+ }
+
switch(Z_TYPE_PP(val)) {
case IS_STRING:
smart_str_appendl(querystr,
Z_STRVAL_PP(val), Z_STRLEN_PP(val));
@@ -5604,12 +5609,12 @@
smart_str_appends(&querystr, table);
smart_str_appends(&querystr, " SET ");
- if (build_assignment_string(&querystr, Z_ARRVAL_P(var_array), ",", 1
TSRMLS_CC))
+ if (build_assignment_string(&querystr, Z_ARRVAL_P(var_array), 0,
",", 1 TSRMLS_CC))
goto cleanup;
smart_str_appends(&querystr, " WHERE ");
- if (build_assignment_string(&querystr, Z_ARRVAL_P(ids_array), " AND
", sizeof(" AND ")-1 TSRMLS_CC))
+ if (build_assignment_string(&querystr, Z_ARRVAL_P(ids_array), 1, "
AND ", sizeof(" AND ")-1 TSRMLS_CC))
goto cleanup;
smart_str_appendc(&querystr, ';');
@@ -5705,7 +5710,7 @@
smart_str_appends(&querystr, table);
smart_str_appends(&querystr, " WHERE ");
- if (build_assignment_string(&querystr, Z_ARRVAL_P(ids_array), " AND
", sizeof(" AND ")-1 TSRMLS_CC))
+ if (build_assignment_string(&querystr, Z_ARRVAL_P(ids_array), 1, "
AND ", sizeof(" AND ")-1 TSRMLS_CC))
goto cleanup;
smart_str_appendc(&querystr, ';');
@@ -5841,7 +5846,7 @@
smart_str_appends(&querystr, table);
smart_str_appends(&querystr, " WHERE ");
- if (build_assignment_string(&querystr, Z_ARRVAL_P(ids_array), " AND
", sizeof(" AND ")-1 TSRMLS_CC))
+ if (build_assignment_string(&querystr, Z_ARRVAL_P(ids_array), 1, "
AND ", sizeof(" AND ")-1 TSRMLS_CC))
goto cleanup;
smart_str_appendc(&querystr, ';');
|