From 05d1b373d591389fad7e0c3becfc372e7f6f1167 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Fri, 20 Aug 2021 11:21:46 +1000 Subject: [PATCH] [odbc] Format boolean values correctly as SQL_C_CHAR (#327) When a boolean column value is requested as a SQL_C_CHAR value, correctly return a "1" or "0" string value --- src/odbc/odbc.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/odbc/odbc.c b/src/odbc/odbc.c index a3b5276..050e9cf 100644 --- a/src/odbc/odbc.c +++ b/src/odbc/odbc.c @@ -1465,9 +1465,19 @@ SQLRETURN SQL_API SQLGetData( if (col->col_type == MDB_BOOL) { // bool cannot be null - *(BOOL*)rgbValue = col->cur_value_len ? 0 : 1; - if (pcbValue) - *pcbValue = 1; + if (fCType == SQL_C_CHAR) { + if ( col->cur_value_len ) + ((char *)rgbValue)[0] = '0'; + else + ((char *)rgbValue)[0] = '1'; + ((char *)rgbValue)[1] = '\0'; + if (pcbValue) + *pcbValue = sizeof(SQLCHAR); + } else { + *(BOOL*)rgbValue = col->cur_value_len ? 0 : 1; + if (pcbValue) + *pcbValue = 1; + } return SQL_SUCCESS; } if (col->cur_value_len == 0) {