From a0e72c5dfac106f4369d639f012cfb4e4ac8cfd4 Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Tue, 31 Aug 2021 14:23:12 -0400 Subject: [PATCH] Implement SQLFetchW Fixes #347 --- src/odbc/mdbodbc.h | 12 ++++++++++++ src/odbc/odbc.c | 14 ++++++++++---- src/odbc/odbcw.c | 9 ++++++++- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/odbc/mdbodbc.h b/src/odbc/mdbodbc.h index 2206dc6..6752389 100644 --- a/src/odbc/mdbodbc.h +++ b/src/odbc/mdbodbc.h @@ -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 diff --git a/src/odbc/odbc.c b/src/odbc/odbc.c index bb29249..fe55a60 100644 --- a/src/odbc/odbc.c +++ b/src/odbc/odbc.c @@ -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) { diff --git a/src/odbc/odbcw.c b/src/odbc/odbcw.c index 899dbd9..2fa9911 100644 --- a/src/odbc/odbcw.c +++ b/src/odbc/odbcw.c @@ -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,