Opened 18 years ago

Last modified 18 years ago

#990 closed defect (fixed)

OGR ODBC driver unable to read large text fields properly

Reported by: szekerest@… Owned by: warmerdam
Priority: high Milestone:
Component: default Version: unspecified
Severity: critical Keywords:
Cc: amagnum2@…

Description

It seems that the OGR ODBC driver does not handle large text fields
(like large WKT) properly. The OGR driver loads the data by 511 byte chunks
but leaves the terminating zero byte in the buffer after reading the
next chunk. It causes that only the first 511 byte will be considered
as the field value have been read.

This problem related to the Microsoft's ODBC driver implementation which 
places one or two zero terminators into the returned buffer when calling 
SQLGetData on text field and the size of the data to be returned is larger 
then the buffer size. For unicode text fields (ntext with MSSQL) two extra 
terminators reside in the returning buffer.

To fix this problem cpl_odbc.cpp should be modified as to trim the 
terminators,like the followings:


if( cbDataLen > (int) (sizeof(szWrkData)-1) )
{
   cbDataLen = (int) (sizeof(szWrkData)-1);
  if (nFetchType == SQL_C_CHAR) 
	while ((cbDataLen > 1) && (szWrkData[cbDataLen - 1] == 0)) --
cbDataLen;  // trimming the extra terminators
}


Tamas Szekeres

Attachments (1)

cpl_odbc.cpp (43.3 KB ) - added by szekerest@… 18 years ago.
Proposed patch to fix this problem

Download all attachments as: .zip

Change History (4)

by szekerest@…, 18 years ago

Attachment: cpl_odbc.cpp added

Proposed patch to fix this problem

comment:1 by szekerest@…, 18 years ago

Is this problem under consideration?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcsqlgetdata.asp

should be taken into account:

"If the data was converted to a variable-length data type, such as character or
binary, SQLGetData checks whether the length of the data exceeds BufferLength.
If the length of character data (including the null-termination character)
exceeds BufferLength, SQLGetData truncates the data to BufferLength less the
length of a null-termination character. It then null-terminates the data. If the
length of binary data exceeds the length of the data buffer, SQLGetData
truncates it to BufferLength bytes."

Tamas

comment:2 by warmerdam, 18 years ago

Tamas, 

I should have read your bug report more carefully when you first reported
it.  Now I see why this was happening to you, but not too me.  Because
it relates to double byte unicode which I don't use. 

I have applied the patch.  Thanks!

comment:3 by amagnum2@…, 18 years ago

*** Bug 1073 has been marked as a duplicate of this bug. ***
Note: See TracTickets for help on using tickets.