PHP 4.0 Bug #4351: Informix LVARCHAR fields returned from ifx_fetch_row() are too long
| From: | alex dot shepherd at cse dot co dot nz | Date: | Tue, 09 May 2000 02:07:39 +0000 |
| Subject: | PHP 4.0 Bug #4351: Informix LVARCHAR fields returned from ifx_fetch_row() are too long | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-18542@lists.php.net to get a copy of this message | ||
From: alex.shepherd@cse.co.nz
Operating system: Debian Linux 2.2.14
PHP version: 4.0 Release Candidate 1
PHP Bug Type: Other
Bug description: Informix LVARCHAR fields returned from ifx_fetch_row() are too long
We are using PHP4RC1 with Informix 9.2 on Linux. I have just noticed something that was causing a
problem when LVARCHAR fields are returned into a Row array.
The PHP string that a LVARCHAR field is returned into seems to have two extra NULLs on the end which
was causing some other problems in our application. I have tried CHAR(255) and VERCHAR(255) which
seem to work fine as the add_assoc_string() function uses strlen() to determine its length where as
LVARCHAR uses add_assoc_stringl() which relies upon the passed length parameter.
To debug the problem I modified the following section of the code (lines 2116-2128 of ifx.ec) to
cause a warning:
case SQLLVARCHAR:
ifx_var_flag(&lvar_tmp,1);
EXEC SQL GET DESCRIPTOR :descrpid VALUE :i :lvar_tmp = DATA;
fieldleng=ifx_var_getlen(&lvar_tmp);
if ((char_data = (char *)emalloc(fieldleng + 1)) == NULL) {
php_error(E_WARNING, "Out of memory");
RETURN_FALSE;
}
//----Begin Debug Code Here---------
php_error(E_WARNING,"ifx_fetch_row: SQLLVARCHAR ifx_var_getlen: %d strlen: %d",
fieldleng, strlen( ifx_var_getdata(&lvar_tmp) ) ) ;
//----End Debug Code Here---------
memcpy(char_data,ifx_var_getdata(&lvar_tmp),fieldleng);
ifx_var_dealloc(&lvar_tmp);
add_assoc_stringl(return_value, fieldname, char_data, fieldleng,0);
break;
This causes the following line to be displayed in the browser:
Warning: ifx_fetch_row: SQLLVARCHAR ifx_var_getlen: 12 strlen: 10 in ifx_session.inc on line 110.
I had a look around in the ESQL/C manuals etc and they say the the call ifx_var_getlen() returns the
size of a buffer needed to store the field data. My guess is that this includs a 16bit length word
as well as the actual string and whould explain the two extra NULL chars.
To solve my imediate problem I have added 2 lines at line 2121 of ifx.ec:
fieldleng=ifx_var_getlen(&lvar_tmp);
//----Begin Hack to Fix Problem---------
if( fieldleng > 2 )
fieldleng -= 2 ;
//----End Hack to Fix Problem---------
if ((char_data = (char *)emalloc(fieldleng + 1)) == NULL) {