ID:               26625
 Updated by:       [EMAIL PROTECTED]
 Reported By:      gregkiyomi at digitaljunkies dot ca
-Status:           Open
+Status:           Feedback
 Bug Type:         PostgreSQL related
 Operating System: linux
 PHP Version:      5.0.0b2 (beta2)
 New Comment:

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




Previous Comments:
------------------------------------------------------------------------

[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=26625&edit=1

Reply via email to