mirror of
https://github.com/mdbtools/mdbtools.git
synced 2026-03-10 00:20:54 +08:00
Don't automatically add terminators when reading data parts
via SQLGetData for OLE fields if the column type is OLE, then we don't add terminators see https://docs.microsoft.com/en-us/sql/odbc/reference/syntax/sqlgetdata-function?view=sql-server-ver15 and https://www.ibm.com/support/knowledgecenter/SSEPEK_11.0.0/odbc/src/tpc/db2z_fngetdata.html "The buffer that the rgbValue argument specifies contains nul-terminated values, unless you retrieve binary data, or the SQL data type of the column is graphic (DBCS) and the C buffer type is SQL_C_CHAR."
This commit is contained in:
+15
-3
@@ -1640,14 +1640,26 @@ SQLRETURN SQL_API SQLGetData(
|
|||||||
return SQL_SUCCESS_WITH_INFO;
|
return SQL_SUCCESS_WITH_INFO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* if the column type is OLE, then we don't add terminators
|
||||||
|
see https://docs.microsoft.com/en-us/sql/odbc/reference/syntax/sqlgetdata-function?view=sql-server-ver15
|
||||||
|
and https://www.ibm.com/support/knowledgecenter/SSEPEK_11.0.0/odbc/src/tpc/db2z_fngetdata.html
|
||||||
|
|
||||||
|
"The buffer that the rgbValue argument specifies contains nul-terminated values, unless you retrieve
|
||||||
|
binary data, or the SQL data type of the column is graphic (DBCS) and the C buffer type is SQL_C_CHAR."
|
||||||
|
*/
|
||||||
|
const int needsTerminator = (col->col_type != MDB_OLE);
|
||||||
|
|
||||||
const int totalSizeRemaining = len - stmt->pos;
|
const int totalSizeRemaining = len - stmt->pos;
|
||||||
const int partsRemain = cbValueMax - 1 < totalSizeRemaining;
|
const int partsRemain = cbValueMax - ( needsTerminator ? 1 : 0 ) < totalSizeRemaining;
|
||||||
const int sizeToReadThisPart = partsRemain ? cbValueMax - 1 : totalSizeRemaining;
|
const int sizeToReadThisPart = partsRemain ? cbValueMax - ( needsTerminator ? 1 : 0 ) : totalSizeRemaining;
|
||||||
memcpy(rgbValue, str + stmt->pos, sizeToReadThisPart);
|
memcpy(rgbValue, str + stmt->pos, sizeToReadThisPart);
|
||||||
|
|
||||||
|
if (needsTerminator)
|
||||||
|
{
|
||||||
((char *)rgbValue)[sizeToReadThisPart] = '\0';
|
((char *)rgbValue)[sizeToReadThisPart] = '\0';
|
||||||
|
}
|
||||||
if (partsRemain) {
|
if (partsRemain) {
|
||||||
stmt->pos += cbValueMax - 1;
|
stmt->pos += cbValueMax - ( needsTerminator ? 1 : 0 );
|
||||||
if (col->col_type != MDB_OLE) { free(str); str = NULL; }
|
if (col->col_type != MDB_OLE) { free(str); str = NULL; }
|
||||||
strcpy(sqlState, "01004"); // truncated
|
strcpy(sqlState, "01004"); // truncated
|
||||||
return SQL_SUCCESS_WITH_INFO;
|
return SQL_SUCCESS_WITH_INFO;
|
||||||
|
|||||||
Reference in New Issue
Block a user