|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-09-23 19:36 UTC] keyur@php.net
Description: ------------ SQL_DATE column data is coming back corrupted when it follows a WVARCHAR column in the SELECT statement. Test script: --------------- We have a test table with 2 columns: COUNTRY (WVARCHAR) and MONTH (DATE) and execute the statement: SELECT country, month FROM table; Expected result: ---------------- Month should be the full date: yyyy-mm-dd Actual result: -------------- Month is corrupted: yyyy-mm<4 bytes of junk> PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 17:00:01 2025 UTC |
I have discovered an issue with postgres and SQL_DESC_OCTET_LENGTH for constant string values. e.g. given your 'foo' table used in the test CREATE TABLE FOO(ID INT, VARCHAR_COL VARCHAR(100), DATE_COL DATE)'); select id,varchar_col,date_col,'string constant' from foo; The postgres ODBC driver returns the 'string constant' column as coltype=SQL_VARCHAR but the SQLColAttributes(result->stmt, (SQLUSMALLINT)(i+1), colfieldid, NULL, 0, NULL, &displaysize); call sets displaysize=0 when colfieldid=SQL_DESC_OCTET_LENGTH. As displaysize=0 this causes an allocation of 1 byte of data storage for the field and junk data is returned. If SQL_COLUMN_DISPLAY_SIZE is used then it returns The value set for MaxVarcharSize in the odbc.ini file(4000 in many examples). Or if MaxVarcharSize is not set it defaults to 255 unless the string is more than 255 bytes long in which case it returns the number of bytes in the constant string(I tried this with 300 euro symbols, 3 bytes each in UTF8, and got 900 as a result). But for data from char/varchar columns SQL_COLUMN_DISPLAY_SIZE returns the number of characters(not bytes) which was the original multibyte character problem. This may be more a postgres ODBC driver issue than a php bug but prior to the change to use SQL_DESC_OCTET_LENGTH this worked ok. One option could be to check for displaysize==0 and try SQL_COLUMN_DISPLAY_SIZE instead.