ID:               30962
 User updated by:  richard dot quadling at bandvulc dot co dot uk
 Reported By:      richard dot quadling at bandvulc dot co dot uk
-Status:           Closed
+Status:           Open
 Bug Type:         MSSQL related
 Operating System: Windows XP Pro SP2
-PHP Version:      5.0.2
+PHP Version:      5.0.3
 New Comment:

Back again in V5.0.3!

Or should that be still here?

I notice that the version of the code now tests to see if the length is
0 before the conversion of the data to its appropriate type.

Is it possible, that there is a distinction between NULL and 0?

My C knowledge says no. NULL is 0, but I may be wrong!

The reason I say this, is that if I make the column NULL, then I get
NULL. If I make the column an empty string (i.e. select all and then
delete - doing this in Enterprise Manager), I get a space in the result
set! Argh!

Is there ANY way a debug version could be built that reported that the
code that has been modified is actually called. I'd really like to know
what length IS being returned if the field is empty.

I am more than willing to help get this fixed, but I need some hand
holding in getting MSVC++ setup appropriately. I do not know what
additional tools I need. I am in the process of downloading Cygwin to
start some work on the PHP documentation (just getting the CHM compiled
first!).


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

[2004-12-03 03:27:19] [EMAIL PROTECTED]

This bug has been fixed in CVS.

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/.
 
Thank you for the report, and for helping us make PHP better.



------------------------------------------------------------------------

[2004-12-02 14:36:14] 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.



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=30962&edit=1

Reply via email to