|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-12-02 14:36 UTC] richard dot quadling at bandvulc dot co dot uk
Description:
------------
This bug has been reported before but repeatedly closed as a bogus bug.
It is NOT bogus. It is NOT a problem in the library. It IS a bug in the PHP code.
The problem is for any column where the content is NULL, the value retrieved by PHP is ' '. That is a single space.
The bug is in php_mssql.c (/* $Id: php_mssql.c,v 1.137.2.4 2004/11/15 23:35:50 iliaa Exp $ */)
Lines 798 to 810 are currently ...
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
ZVAL_STRINGL(result, data, length, 1);
break;
}
The problem is that "length" is never tested to see if it is zero, as per the Microsoft documentation (Online books and look for dbdata). It says ...
dbdata ... returns a BYTE pointer to the data for the column. A NULL BYTE pointer is returned if there is no such column or if the data has a null value. To make sure that the data is really a null value, check for a return of 0 from dbdatlen.
and ...
Remarks. The data is not null-terminated. To get the length of the data, use dbdatlen.
I would propose that the php_mssql.c code would be as follows ...
case SQLTEXT: {
int length;
char *data = charcol(offset);
length=dbdatlen(mssql_ptr->link,offset);
if (length == 0) {
ZVAL_EMPTY_STRING(result); // Force the return of an empty string if the length is 0 as data MAY not be NULL.
} else {
#if ilia_0
while (length>0 && data[length-1] == ' ') { /* nuke trailing whitespace */
length--;
}
#endif ZVAL_STRINGL(result, data, length, 1);
}
break;
}
Unfortunately, I am not in a position to test this (well, I have MSVC++V6.0 Standard, but cannot get PHP to compile. I am not very familiar with MSVC++ and its setup to know what is missing).
If someone can explain how I can submit this to the actual source online for compilation, then I'd be very grateful.
I'd be even more grateful if someone could help me get PHP compiled. Even money may be sent, though I'd rather buy beer or something fizzy for the ladies.
This possible fix does not interfere with the removing of trailing spaces, though I wonder what would happen if
Regards,
Richard Quadling.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 20:00:01 2025 UTC |
Simple test script to show the problem. <?php $rConn = mssql_connect('localhost','PHPBB_User','PHPBB_User'); $rResults = mssql_query('SELECT username, user_icq, LEN(user_icq) AS user_icq_len FROM PHPBB_User.phpbb_users'); while ($row = mssql_fetch_assoc($rResults)) { echo '<pre>' . var_export($row, True) . '</pre>Length of ' . $row['username'] . '\'s user_icq = ' . strlen($row['user_icq']) . '<br /><br /><br />'; } mssql_free_result($rResults); mssql_close($rConn); ?> Requires phpBB and at least 1 user defined with an ICQ number. Obviously, you could choose any field or any other MS SQL database. Richard.Hi, It'd be nice to see it working in php 5.1 because right now I am developing in php5. I've tried various php5 snaps and 5.0.4 stable without efect. I am on a Win2003 server and here is my try-case: <?php $c = mssql_pconnect('myserver'); $res = mssql_query('select top 1 Obrazek,len = len(Obrazek),bin = cast(Obrazek as varbinary) from katalog..Nabidka'); $a = mssql_fetch_assoc($res); //any method var_dump($a); print phpversion(); /* returns: array(3) { ["Obrazek"]=> string(1) " " ["len"]=> int(0) ["bin"]=> string(1) " " } 5.1.0-dev Thank you much :) */ ?>I seem to be having this same problem on PHP 5.1.2 (on Windows XP). Simple test script: <?php $db = mssql_connect($server, $user, $pswd); if (!$db) die(); mssql_select_db($dbname); $rs = mssql_query('select g_theme from g2_AlbumItem where g_id = 7'); if (!$rs) die(); $row = mssql_fetch_array($rs); mssql_free_result($rs); var_dump($row); mssql_close($db); ?> Returns: C:\MyServer>php testMsSql_mssql.php array(2) { [0]=> string(1) " " ["g_theme"]=> string(1) " " } I know this is not correct, the actual content of that column is a 0-byte string: C:\MyServer>sqlcmd -d ... -S ... -U ... -P ... -e 1> select g_theme from g2_albumitem 2> go select g_theme from g2_albumitem g_theme -------------------------------- (1 rows affected) 1> select len(g_theme) from g2_albumitem 2> go select len(g_theme) from g2_albumitem ----------- 0 (1 rows affected) 1> select 'x' + g_theme + 'x' from g2_albumitem 2> go select 'x' + g_theme + 'x' from g2_albumitem ---------------------------------- xx (1 rows affected) 1> Is anyone still working on this? It's been about 10 months since this bug was last updated. (Unfortunately I do not have a PHP Build environment.) Thanks.