#31641 [Opn]: empty string returned as single space
| From: | tomasz at biznespolska dot pl | Date: | Fri, 21 Jan 2005 16:20:38 +0000 |
| Subject: | #31641 [Opn]: empty string returned as single space | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-72600@lists.php.net to get a copy of this message | ||
ID: 31641
User updated by: tomasz at biznespolska dot pl
Reported By: tomasz at biznespolska dot pl
Status: Open
Bug Type: MSSQL related
Operating System: win32
PHP Version: 4.3.10
New Comment:
Ofcourse I mean "empty strings" not "empty spaces". Should be:
"It is very rare that someone will store in database single space, but
storing empty string is very common."
Previous Comments:
------------------------------------------------------------------------
[2005-01-21 17:12:44] tomasz at biznespolska dot pl
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 this bug report at http://bugs.php.net/?id=31641&edit=1