Implement SQLFetchW

Fixes #347
This commit is contained in:
Evan Miller 2021-08-31 14:23:12 -04:00
parent 16b2970931
commit a0e72c5dfa
3 changed files with 30 additions and 5 deletions

View File

@ -78,6 +78,18 @@ struct _sql_bind_info {
struct _sql_bind_info *next;
};
typedef SQLRETURN (*_mdb_odbc_sql_data_callback)
(SQLHSTMT hstmt,
SQLUSMALLINT icol,
SQLSMALLINT fCType,
SQLPOINTER rgbValue,
SQLLEN cbValueMax,
SQLLEN *pcbValue);
SQLRETURN _mdb_SQLFetch(
SQLHSTMT hstmt,
_mdb_odbc_sql_data_callback DataCallback);
#ifdef __cplusplus
}
#endif

View File

@ -835,13 +835,13 @@ unbind_columns(struct _hstmt *stmt)
stmt->bind_head = NULL;
}
SQLRETURN SQL_API SQLFetch(
SQLHSTMT hstmt)
SQLRETURN _mdb_SQLFetch(
SQLHSTMT hstmt,
_mdb_odbc_sql_data_callback DataCallback)
{
struct _hstmt *stmt = (struct _hstmt *) hstmt;
struct _sql_bind_info *cur = stmt->bind_head;
TRACE("SQLFetch");
if ( stmt->sql->limit >= 0 && stmt->rows_affected == stmt->sql->limit ) {
return SQL_NO_DATA_FOUND;
}
@ -850,7 +850,7 @@ SQLRETURN SQL_API SQLFetch(
while (cur && (final_retval == SQL_SUCCESS || final_retval == SQL_SUCCESS_WITH_INFO)) {
/* log error ? */
SQLLEN lenbind = 0;
SQLRETURN this_retval = SQLGetData(hstmt, cur->column_number, cur->column_bindtype,
SQLRETURN this_retval = DataCallback(hstmt, cur->column_number, cur->column_bindtype,
cur->varaddr, cur->column_bindlen, &lenbind);
if (cur->column_lenbind)
*(cur->column_lenbind) = lenbind;
@ -866,6 +866,12 @@ SQLRETURN SQL_API SQLFetch(
}
}
SQLRETURN SQL_API SQLFetch(
SQLHSTMT hstmt) {
TRACE("SQLFetch");
return _mdb_SQLFetch(hstmt, SQLGetData);
}
SQLRETURN SQL_API SQLFreeConnect(
SQLHDBC hdbc)
{

View File

@ -267,7 +267,8 @@ SQLRETURN SQL_API SQLGetDataW(
SQLLEN cbValueMax,
SQLLEN *pcbValue)
{
//todo: treat numbers correctly
if (fCType != SQL_C_CHAR)
return SQLGetData(hstmt, icol, fCType, rgbValue, cbValueMax, pcbValue);
size_t l=cbValueMax*4+1;
SQLCHAR *tmp=calloc(l,1);
@ -277,6 +278,12 @@ SQLRETURN SQL_API SQLGetDataW(
return ret;
}
SQLRETURN SQL_API SQLFetchW(
SQLHSTMT hstmt) {
TRACE("SQLFetchW");
return _mdb_SQLFetch(hstmt, SQLGetDataW);
}
SQLRETURN SQL_API SQLGetInfoW(
SQLHDBC hdbc,
SQLUSMALLINT fInfoType,