PHP with sybase-ct and TEXT

Brage Førland brage at zoo.uib.no
Wed May 31 06:07:16 EDT 2000


When compiling PHP (4.0.0) with sybase-ct, TEXT fields is truncated to 255
chars when fetching rows.

The problem seems to be that php relies on ct_bind() to convert all fields
to type CS_CHAR_TYPE when fetching them. FreeTDS (in tds_convert_text) then
truncates the field to 255 chars (instead of the maxlenght given as argument
to ct_bind()).

The converted TEXT-field should probably also include the trailing \0 in the
length.

The patch below will fix PHP, but I'm not sure what effect it will have on
other applications.

	-Brage



*** src/tds/convert.c.old	Wed May 31 11:18:33 2000
--- src/tds/convert.c	Wed May 31 11:07:40 2000
***************
*** 98,107 ****
        case SYBCHAR:
  	 cplen = srclen;
  	 if (destlen<cplen) cplen = destlen;
! 	 if (cplen>255) cplen=255;
           memcpy(dest, src, cplen);
! 	 dest[cplen]='\0';
!          return cplen;
     }
  }
  TDS_INT tds_convert_binary(int srctype,unsigned char *src,TDS_INT srclen,
--- 98,107 ----
        case SYBCHAR:
  	 cplen = srclen;
  	 if (destlen<cplen) cplen = destlen;
! 	 /* if (cplen>255) cplen=255; */
           memcpy(dest, src, cplen);
! 	 dest[cplen+1]='\0';
!          return cplen+1;
     }
  }
  TDS_INT tds_convert_binary(int srctype,unsigned char *src,TDS_INT srclen,




More information about the FreeTDS mailing list