felipe Sat, 06 Nov 2010 17:43:25 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=305130
Log: - Fixed bug #47199 (pg_delete() fails on NULL) patch by: ewgraf at gmail dot com Bug: http://bugs.php.net/47199 (Open) pg_delete fails on NULL Changed paths: U php/php-src/branches/PHP_5_3/NEWS U php/php-src/branches/PHP_5_3/ext/pgsql/pgsql.c A php/php-src/branches/PHP_5_3/ext/pgsql/tests/bug47199.phpt U php/php-src/trunk/ext/pgsql/pgsql.c A php/php-src/trunk/ext/pgsql/tests/bug47199.phpt
Modified: php/php-src/branches/PHP_5_3/NEWS =================================================================== --- php/php-src/branches/PHP_5_3/NEWS 2010-11-06 17:14:21 UTC (rev 305129) +++ php/php-src/branches/PHP_5_3/NEWS 2010-11-06 17:43:25 UTC (rev 305130) @@ -179,6 +179,7 @@ Pierre) - Fixed bug #47643 (array_diff() takes over 3000 times longer than php 5.2.4). (Felipe) +- Fixed bug #47199 (pg_delete() fails on NULL). (ewgraf at gmail dot com) - Fixed bug #45921 (Can't initialize character set hebrew). (Andrey) - Fixed bug #44248 (RFC2616 transgression while HTTPS request through proxy with SoapClient object). (Dmitry) Modified: php/php-src/branches/PHP_5_3/ext/pgsql/pgsql.c =================================================================== --- php/php-src/branches/PHP_5_3/ext/pgsql/pgsql.c 2010-11-06 17:14:21 UTC (rev 305129) +++ php/php-src/branches/PHP_5_3/ext/pgsql/pgsql.c 2010-11-06 17:43:25 UTC (rev 305130) @@ -5930,7 +5930,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; @@ -5949,7 +5949,11 @@ 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: @@ -6011,12 +6015,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, ';'); @@ -6112,7 +6116,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, ';'); @@ -6251,7 +6255,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, ';'); Added: php/php-src/branches/PHP_5_3/ext/pgsql/tests/bug47199.phpt =================================================================== --- php/php-src/branches/PHP_5_3/ext/pgsql/tests/bug47199.phpt (rev 0) +++ php/php-src/branches/PHP_5_3/ext/pgsql/tests/bug47199.phpt 2010-11-06 17:43:25 UTC (rev 305130) @@ -0,0 +1,67 @@ +--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 NOT NULL)"); + +pg_insert($dbh, $tbl_name, array('null_field' => null, 'not_null_field' => 1)); +pg_insert($dbh, $tbl_name, array('null_field' => null, 'not_null_field' => 2)); + +var_dump(pg_fetch_all(pg_query('SELECT * FROM '. $tbl_name))); + +$query = pg_delete($dbh, $tbl_name, array('null_field' => NULL,'not_null_field' => 2), PGSQL_DML_STRING|PGSQL_DML_EXEC); + +echo $query, "\n"; + +$query = pg_update($dbh, $tbl_name, array('null_field' => NULL, 'not_null_field' => 0), array('not_null_field' => 1, 'null_field' => ''), PGSQL_DML_STRING|PGSQL_DML_EXEC); + +echo $query, "\n"; + +var_dump(pg_fetch_all(pg_query('SELECT * FROM '. $tbl_name))); + +...@pg_query("DROP TABLE $tbl_name"); +pg_close($dbh); + +echo PHP_EOL."Done".PHP_EOL; + +?> +--EXPECTF-- +array(2) { + [0]=> + array(2) { + ["null_field"]=> + NULL + ["not_null_field"]=> + string(1) "1" + } + [1]=> + array(2) { + ["null_field"]=> + NULL + ["not_null_field"]=> + string(1) "2" + } +} +DELETE FROM test_47199 WHERE null_field IS NULL AND not_null_field=2; +UPDATE test_47199 SET null_field=NULL,not_null_field=0 WHERE not_null_field=1 AND null_field IS NULL; +array(1) { + [0]=> + array(2) { + ["null_field"]=> + NULL + ["not_null_field"]=> + string(1) "0" + } +} + +Done \ No newline at end of file Property changes on: php/php-src/branches/PHP_5_3/ext/pgsql/tests/bug47199.phpt ___________________________________________________________________ Added: svn:keywords + Id Rev Revision Added: svn:eol-style + native Modified: php/php-src/trunk/ext/pgsql/pgsql.c =================================================================== --- php/php-src/trunk/ext/pgsql/pgsql.c 2010-11-06 17:14:21 UTC (rev 305129) +++ php/php-src/trunk/ext/pgsql/pgsql.c 2010-11-06 17:43:25 UTC (rev 305130) @@ -5922,7 +5922,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; @@ -5941,7 +5941,11 @@ 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: @@ -6003,12 +6007,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, ';'); @@ -6104,7 +6108,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, ';'); @@ -6243,7 +6247,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, ';'); Added: php/php-src/trunk/ext/pgsql/tests/bug47199.phpt =================================================================== --- php/php-src/trunk/ext/pgsql/tests/bug47199.phpt (rev 0) +++ php/php-src/trunk/ext/pgsql/tests/bug47199.phpt 2010-11-06 17:43:25 UTC (rev 305130) @@ -0,0 +1,67 @@ +--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 NOT NULL)"); + +pg_insert($dbh, $tbl_name, array('null_field' => null, 'not_null_field' => 1)); +pg_insert($dbh, $tbl_name, array('null_field' => null, 'not_null_field' => 2)); + +var_dump(pg_fetch_all(pg_query('SELECT * FROM '. $tbl_name))); + +$query = pg_delete($dbh, $tbl_name, array('null_field' => NULL,'not_null_field' => 2), PGSQL_DML_STRING|PGSQL_DML_EXEC); + +echo $query, "\n"; + +$query = pg_update($dbh, $tbl_name, array('null_field' => NULL, 'not_null_field' => 0), array('not_null_field' => 1, 'null_field' => ''), PGSQL_DML_STRING|PGSQL_DML_EXEC); + +echo $query, "\n"; + +var_dump(pg_fetch_all(pg_query('SELECT * FROM '. $tbl_name))); + +...@pg_query("DROP TABLE $tbl_name"); +pg_close($dbh); + +echo PHP_EOL."Done".PHP_EOL; + +?> +--EXPECTF-- +array(2) { + [0]=> + array(2) { + ["null_field"]=> + NULL + ["not_null_field"]=> + string(1) "1" + } + [1]=> + array(2) { + ["null_field"]=> + NULL + ["not_null_field"]=> + string(1) "2" + } +} +DELETE FROM test_47199 WHERE null_field IS NULL AND not_null_field=2; +UPDATE test_47199 SET null_field=NULL,not_null_field=0 WHERE not_null_field=1 AND null_field IS NULL; +array(1) { + [0]=> + array(2) { + ["null_field"]=> + NULL + ["not_null_field"]=> + string(1) "0" + } +} + +Done \ No newline at end of file Property changes on: php/php-src/trunk/ext/pgsql/tests/bug47199.phpt ___________________________________________________________________ Added: svn:keywords + Id Rev Revision Added: svn:eol-style + native
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php