From:             tomasz at biznespolska dot pl
Operating system: win32
PHP version:      4.3.10
PHP Bug Type:     MSSQL related
Bug description:  empty string returned as single space

Description:
------------
I'd like to continue thread:
http://bugs.php.net/bug.php?id=25777
Because it's already closed I wasn't able to add my comments there.

By disabling rtriming of text fields, new bug was introduced - empty
strings are returned as single space. I know that is because of MS DBLib,
but there is no problem to fix that in PHP.

It is very rare that someone will store in database single space, but
storing empty spaces is very common. So in my opinion most common usage
should be considered.
For example: if ( empty($text_from_db) ) { // do something }

In my opinion ' ' should replaced by ''. 

I don't how to submit this to CVS, so I put it here:

ext/mssql/mssql.c line 805:

case SQLTEXT: {
        int length;
        char *data = charcol(offset);

        length=dbdatlen(mssql_ptr->link,offset);
#if ilia_0
        while (length>0 && data[length-1] == ' ') { /* nuke trailing whitespace
*/
                length--;
        }
#endif
        if ( length==1 && data[0]==' ' ) { /* single space to empty string */
                length=0;
        }
        
        Z_STRVAL_P(result) = estrndup(data,length);
        Z_STRLEN_P(result) = length;
        Z_TYPE_P(result) = IS_STRING;
        break;
}


Reproduce code:
---------------
//mssql_connect(...);
var_dump(mssql_fetch_row(mssql_query("SELECT ''")));

Expected result:
----------------
array(1) { [0]=> string(0) "" }

Actual result:
--------------
array(1) { [0]=> string(1) " " }

-- 
Edit bug report at http://bugs.php.net/?id=31641&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=31641&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=31641&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=31641&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=31641&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=31641&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=31641&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=31641&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=31641&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=31641&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=31641&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=31641&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=31641&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=31641&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=31641&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=31641&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=31641&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=31641&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=31641&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=31641&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=31641&r=mysqlcfg

Reply via email to