#26625 [Csd-Opn]: pg_convert sets NULL incorrectly for character data types
ID: 26625 User updated by: gregkiyomi at digitaljunkies dot ca Reported By: gregkiyomi at digitaljunkies dot ca -Status: Closed +Status: Open Bug Type: PostgreSQL related Operating System: linux PHP Version: 5.0.0b2 (beta2) New Comment: The 'corrected' code now puts nothing in for empty strings if PGSQL_CONV_FORCE_NULL is *not* set. It should put '' in. This will break queries. Expected result: Array ( [varchar_field1] = 'test' [varchar_field2] = NULL [varchar_field3] = '' ) Actual result: -- Array ( [varchar_field1] = 'test' [varchar_field2] = NULL [varchar_field3] = ) Previous Comments: [2003-12-15 19:57:21] [EMAIL PROTECTED] This bug has been fixed in CVS. In case this was a PHP problem, 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/. In case this was a documentation problem, the fix will show up soon at http://www.php.net/manual/. In case this was a PHP.net website problem, the change will show up on the PHP.net site and on the mirror sites in short time. Thank you for the report, and for helping us make PHP better. [2003-12-15 03:32:38] gregkiyomi at digitaljunkies dot ca Description: When using pg_convert() with PGSQL_CONV_FORCE_NULL option set the resulting value for character data types (text,char,varchar) is set as 'NULL' instead of NULL. This therefore inserts the string 'NULL' into the database instead of the desired NULL value. This also obviously doesn't fail a NOT NULL check as it should. The culprit is ext/pgsql/pgsql.c *** pgsql.c~Mon Dec 15 00:17:01 2003 --- pgsql.c Mon Dec 15 01:28:56 2003 *** *** 3785,3790 --- 3785,3791 if (Z_STRLEN_PP(val) == 0) { if (opt PGSQL_CONV_FORCE_NULL) { ZVAL_STRING(new_val, NULL, 1); + break; } else { ZVAL_STRING(new_val, empty_string, 1); This prevents the NULL value from being passed through php_pgsql_add_quotes(). This is also present in php 4.3.3. Reproduce code: --- $con_str = host=localhost dbname=database user=user password=pass; $con = pg_connect($con_str); $data = array(varchar_field1=test, varchar_field2=NULL, varchar_field3=); $array = pg_convert($con,test_table,$data,4); echo(pre); print_r($array); echo(/pre); Expected result: Array ( [varchar_field1] = 'test' [varchar_field2] = NULL [varchar_field3] = NULL ) Actual result: -- Array ( [varchar_field1] = 'test' [varchar_field2] = NULL [varchar_field3] = 'NULL' ) -- Edit this bug report at http://bugs.php.net/?id=26625edit=1
#26625 [NEW]: pg_convert sets NULL incorrectly for character data types
From: gregkiyomi at digitaljunkies dot ca Operating system: linux PHP version: 5.0.0b2 (beta2) PHP Bug Type: PostgreSQL related Bug description: pg_convert sets NULL incorrectly for character data types Description: When using pg_convert() with PGSQL_CONV_FORCE_NULL option set the resulting value for character data types (text,char,varchar) is set as 'NULL' instead of NULL. This therefore inserts the string 'NULL' into the database instead of the desired NULL value. This also obviously doesn't fail a NOT NULL check as it should. The culprit is ext/pgsql/pgsql.c *** pgsql.c~Mon Dec 15 00:17:01 2003 --- pgsql.c Mon Dec 15 01:28:56 2003 *** *** 3785,3790 --- 3785,3791 if (Z_STRLEN_PP(val) == 0) { if (opt PGSQL_CONV_FORCE_NULL) { ZVAL_STRING(new_val, NULL, 1); + break; } else { ZVAL_STRING(new_val, empty_string, 1); This prevents the NULL value from being passed through php_pgsql_add_quotes(). This is also present in php 4.3.3. Reproduce code: --- $con_str = host=localhost dbname=database user=user password=pass; $con = pg_connect($con_str); $data = array(varchar_field1=test, varchar_field2=NULL, varchar_field3=); $array = pg_convert($con,test_table,$data,4); echo(pre); print_r($array); echo(/pre); Expected result: Array ( [varchar_field1] = 'test' [varchar_field2] = NULL [varchar_field3] = NULL ) Actual result: -- Array ( [varchar_field1] = 'test' [varchar_field2] = NULL [varchar_field3] = 'NULL' ) -- Edit bug report at http://bugs.php.net/?id=26625edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=26625r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=26625r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=26625r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=26625r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=26625r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=26625r=needscript Try newer version: http://bugs.php.net/fix.php?id=26625r=oldversion Not developer issue:http://bugs.php.net/fix.php?id=26625r=support Expected behavior: http://bugs.php.net/fix.php?id=26625r=notwrong Not enough info:http://bugs.php.net/fix.php?id=26625r=notenoughinfo Submitted twice:http://bugs.php.net/fix.php?id=26625r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=26625r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=26625r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=26625r=dst IIS Stability: http://bugs.php.net/fix.php?id=26625r=isapi Install GNU Sed:http://bugs.php.net/fix.php?id=26625r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=26625r=float
#26625 [Fbk-Opn]: pg_convert sets NULL incorrectly for character data types
ID: 26625 User updated by: gregkiyomi at digitaljunkies dot ca Reported By: gregkiyomi at digitaljunkies dot ca -Status: Feedback +Status: Open Bug Type: PostgreSQL related Operating System: linux PHP Version: 5.0.0b2 (beta2) New Comment: http://snaps.php.net/php5-latest.tar.gz has the same problem, as does php 4.3. I posted the fix in my original post. In the switch statement in pgsql.c for text types (PG_TEXT,PG_CHAR,PG_VARCHAR) if the string length is 0 and the PGSQL_CONV_FORCE_NULL option is set then the value is set to NULL and then is run through the php_pgsql_add_quotes() function. This results with the value entered as 'NULL' when it should be NULL. The solution, as in my original post is to put a break; statement after the value is set to NULL so it doesn't get passed through the add quotes function. This was detailed in the diff I put in the original post. I have added this change and recompiled myself so the bug report was merely for the benefit of the developers and anyone else who's having this problem. Hope this helps!:) Previous Comments: [2003-12-15 09:23:22] [EMAIL PROTECTED] Please try using this CVS snapshot: http://snaps.php.net/php5-latest.tar.gz For Windows: http://snaps.php.net/win32/php5-win32-latest.zip [2003-12-15 03:32:38] gregkiyomi at digitaljunkies dot ca Description: When using pg_convert() with PGSQL_CONV_FORCE_NULL option set the resulting value for character data types (text,char,varchar) is set as 'NULL' instead of NULL. This therefore inserts the string 'NULL' into the database instead of the desired NULL value. This also obviously doesn't fail a NOT NULL check as it should. The culprit is ext/pgsql/pgsql.c *** pgsql.c~Mon Dec 15 00:17:01 2003 --- pgsql.c Mon Dec 15 01:28:56 2003 *** *** 3785,3790 --- 3785,3791 if (Z_STRLEN_PP(val) == 0) { if (opt PGSQL_CONV_FORCE_NULL) { ZVAL_STRING(new_val, NULL, 1); + break; } else { ZVAL_STRING(new_val, empty_string, 1); This prevents the NULL value from being passed through php_pgsql_add_quotes(). This is also present in php 4.3.3. Reproduce code: --- $con_str = host=localhost dbname=database user=user password=pass; $con = pg_connect($con_str); $data = array(varchar_field1=test, varchar_field2=NULL, varchar_field3=); $array = pg_convert($con,test_table,$data,4); echo(pre); print_r($array); echo(/pre); Expected result: Array ( [varchar_field1] = 'test' [varchar_field2] = NULL [varchar_field3] = NULL ) Actual result: -- Array ( [varchar_field1] = 'test' [varchar_field2] = NULL [varchar_field3] = 'NULL' ) -- Edit this bug report at http://bugs.php.net/?id=26625edit=1