From ed92516533be470fd145ec8a2ae957d9c9015b33 Mon Sep 17 00:00:00 2001 From: Lawrin Novitsky Date: Sun, 4 Feb 2018 23:01:24 +0100 Subject: [PATCH] [ODBC-134] Fix and testcase. Fetch would fail, if unbound column contained NULL, and for that column some arbitrary descriptor field was set by application(but not value/len/ind buffer ptrs). The bug affected ADO, as that is something it can do in some cases with CursorLocation adUseClient --- ma_desc.c | 4 +++- test/result2.c | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ma_desc.c b/ma_desc.c index 14f1dabd..18fbd38b 100644 --- a/ma_desc.c +++ b/ma_desc.c @@ -975,7 +975,9 @@ SQLRETURN MADB_DescSetField(SQLHDESC DescriptorHandle, break; } - if (DescRecord) + /* inUse is only used to check if column/parameter was bound or not. Thus we do not set it for each field, but only for those, + that make column/parameter "bound" */ + if (DescRecord && (DescRecord->DataPtr != NULL || DescRecord->OctetLengthPtr != NULL || DescRecord->IndicatorPtr != NULL)) DescRecord->inUse= 1; } return ret; diff --git a/test/result2.c b/test/result2.c index 3b65ad7d..816982c0 100644 --- a/test/result2.c +++ b/test/result2.c @@ -1140,6 +1140,22 @@ ODBC_TEST(t_odbc73) return OK; } + +ODBC_TEST(t_odbc134) +{ + SQLHANDLE Ard; + + OK_SIMPLE_STMT(Stmt, "SELECT NULL"); + + CHECK_STMT_RC(Stmt, SQLGetStmtAttr(Stmt, SQL_ATTR_APP_ROW_DESC, &Ard, 0, NULL)); + CHECK_DESC_RC(Ard, SQLSetDescField(Ard, 1, SQL_DESC_TYPE, (SQLPOINTER)SQL_NUMERIC, 0)); + CHECK_STMT_RC(Stmt, SQLFetch(Stmt)); + CHECK_STMT_RC(Stmt, SQLFreeStmt(Stmt, SQL_CLOSE)); + + return OK; +} + + MA_ODBC_TESTS my_tests[]= { {t_bug32420, "t_bug32420"}, @@ -1164,6 +1180,7 @@ MA_ODBC_TESTS my_tests[]= {t_odbc77, "t_odbc-77-analyze_table"}, {t_odbc78, "t_odbc-78-sql_no_data"}, {t_odbc73, "t_odbc-73-bin_collation"}, + {t_odbc134, "t_odbc-134-fetch_unbound_null"}, {NULL, NULL} };