Merge pull request #8 from evanmiller/odbc-fix

Fix for variable-length fields using SQLGetData
This commit is contained in:
Evan Miller 2020-08-11 15:14:00 -04:00 committed by GitHub
commit b25eb73648
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 80 additions and 24 deletions

View File

@ -4,28 +4,78 @@ jobs:
include:
- compiler: clang
os: linux
addons:
apt:
packages:
- libiodbc2-dev
env:
- CONFIGURE_FLAGS=--with-iodbc=/usr
- compiler: clang
os: linux
addons:
apt:
packages:
- unixodbc-dev
env:
- CONFIGURE_FLAGS=--with-unixodbc=/usr
- compiler: gcc
os: linux
addons:
apt:
packages:
- libiodbc2-dev
env:
- CONFIGURE_FLAGS=--with-iodbc=/usr
- compiler: gcc
os: linux
addons:
apt:
packages:
- unixodbc-dev
env:
- CONFIGURE_FLAGS=--with-unixodbc=/usr
- compiler: clang
os: osx
osx_image: xcode11.4
addons:
homebrew:
packages:
- libiodbc
env:
- CONFIGURE_FLAGS=--with-iodbc=/usr/local/opt
- compiler: clang
os: osx
osx_image: xcode11.4
addons:
homebrew:
packages:
- unixodbc
env:
- CONFIGURE_FLAGS=--with-unixodbc=/usr/local/opt
- compiler: gcc
os: osx
osx_image: xcode11.4
addons:
apt:
packages:
- libiodbc2-dev
homebrew:
packages:
- libiodbc
addons:
homebrew:
packages:
- libiodbc
env:
- CONFIGURE_FLAGS=--with-iodbc=/usr/local/opt
- compiler: gcc
os: osx
osx_image: xcode11.4
addons:
homebrew:
packages:
- unixodbc
env:
- CONFIGURE_FLAGS=--with-unixodbc=/usr/local/opt
before_script:
- autoreconf -i -f -Wno-portability
script:
- ./configure --disable-man --disable-silent-rules --disable-glib --with-iodbc=/usr
- ./configure --disable-man --disable-silent-rules --disable-glib $CONFIGURE_FLAGS
- make
- ./src/util/mdb-array test/data/ASampleDatabase.accdb "Asset Items"
- ./src/util/mdb-array test/data/nwind.mdb "Customers"

View File

@ -120,6 +120,11 @@ if test "$with_unixodbc"; then
ODBC_LIBS="-L$with_unixodbc/lib"
CFLAGS="$CFLAGS -DUNIXODBC"
dnl SIZEOF_LONG_INT and HAVE_LONG_LONG are required by some versions of unixODBC
dnl https://github.com/lurcher/unixODBC/issues/40
AC_CHECK_SIZEOF([long int])
AC_CHECK_TYPES([long long])
OLDLDFLAGS=$LDFLAGS
LDFLAGS="$LDFLAGS $ODBC_LIBS"
AC_CHECK_LIB(odbcinst, SQLGetPrivateProfileString,

View File

@ -1634,28 +1634,29 @@ 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 + 1 - 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);
stmt->pos += cbValueMax - 1;
memcpy(rgbValue, str + stmt->pos, MIN(len - stmt->pos, cbValueMax-1));
((char *)rgbValue)[MIN(len - stmt->pos, cbValueMax-1)] = '\0';
stmt->pos += MIN(len - stmt->pos, cbValueMax-1);
if (cbValueMax - 1 < len - stmt->pos) {
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;
free(str);
str = NULL;
break;

View File

@ -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. */