mirror of
https://github.com/mdbtools/mdbtools.git
synced 2025-04-05 20:31:00 +08:00
Fix for variable-length fields using SQLGetData
See: brianb/mdbtools#130 brianb/mdbtools#131 evanmiller/mdbtools#6
This commit is contained in:
parent
02c5544c14
commit
e330feebd6
src/odbc
@ -1634,28 +1634,28 @@ SQLRETURN SQL_API SQLGetData(
|
||||
str = NULL;
|
||||
return SQL_NO_DATA;
|
||||
}
|
||||
if (pcbValue) {
|
||||
*pcbValue = len;
|
||||
if (cbValueMax < 0) {
|
||||
strcpy(sqlState, "HY090"); // Invalid string or buffer length
|
||||
free(str);
|
||||
str = NULL;
|
||||
return SQL_ERROR;
|
||||
}
|
||||
if (!cbValueMax) {
|
||||
if (pcbValue) {
|
||||
*pcbValue = len - stmt->pos;
|
||||
}
|
||||
if (cbValueMax == 0) {
|
||||
free(str);
|
||||
str = NULL;
|
||||
return SQL_SUCCESS_WITH_INFO;
|
||||
}
|
||||
if (len - stmt->pos > cbValueMax) {
|
||||
/* the buffer we were given is too small, so
|
||||
truncate it to the size of the buffer */
|
||||
memcpy(rgbValue, str, cbValueMax);
|
||||
snprintf(rgbValue, cbValueMax, "%s", str + stmt->pos);
|
||||
if (stmt->pos + cbValueMax < len + 1) {
|
||||
stmt->pos += cbValueMax - 1;
|
||||
if (col->col_type != MDB_OLE) { free(str); str = NULL; }
|
||||
strcpy(sqlState, "01004"); // trunctated
|
||||
strcpy(sqlState, "01004"); // truncated
|
||||
return SQL_SUCCESS_WITH_INFO;
|
||||
}
|
||||
|
||||
memcpy(rgbValue, str + stmt->pos, len - stmt->pos);
|
||||
if (pcbValue)
|
||||
*pcbValue = len - stmt->pos;
|
||||
stmt->pos += len - stmt->pos;
|
||||
stmt->pos = len;
|
||||
free(str);
|
||||
str = NULL;
|
||||
break;
|
||||
|
@ -174,7 +174,7 @@ int i;
|
||||
szSqlState, szErrorMsg);
|
||||
return 1;
|
||||
}
|
||||
SQLBindCol(hstmt, 3, SQL_CHAR, szCol1, 60, &length);
|
||||
SQLBindCol(hstmt, 3, SQL_CHAR, szCol1, sizeof(szCol1), &length);
|
||||
//SQLBindCol(hstmt, 1, SQL_CHAR, szCol1, 60, NULL);
|
||||
|
||||
/* Execute statement with first row. */
|
||||
|
Loading…
Reference in New Issue
Block a user