diff --git a/driver/connect.c b/driver/connect.c index 6a627d17..df8e8b28 100644 --- a/driver/connect.c +++ b/driver/connect.c @@ -872,8 +872,8 @@ static void set_display_size(esodbc_estype_st *es_type) break; - case ESODBC_SQL_BOOLEAN: - es_type->display_size = /*'false'*/5; + case SQL_BIT: + es_type->display_size = /*'0/1'*/1; break; case ESODBC_SQL_NULL: @@ -894,8 +894,6 @@ static void set_display_size(esodbc_estype_st *es_type) case SQL_DECIMAL: case SQL_NUMERIC: - case SQL_BIT: - case SQL_INTERVAL_MONTH: case SQL_INTERVAL_YEAR: case SQL_INTERVAL_YEAR_TO_MONTH: @@ -1054,6 +1052,17 @@ static void *copy_types_rows(estype_row_st *type_row, SQLULEN rows_fetched, LWSTR(&types[i].type_name)); return NULL; } + DBG("ES type `" LWPDL "` resolved to C concise: %hd, SQL: %hd.", + LWSTR(&types[i].type_name), types[i].c_concise_type, sql_type); + + /* BOOLEAN is used in catalog calls (like SYS TYPES / SQLGetTypeInfo), + * and the data type is piped through to the app (just like with any + * other statement), which causes issues, since it's a non-SQL type + * => change it to SQL_BIT */ + if (types[i].data_type == ESODBC_SQL_BOOLEAN) { + types[i].data_type = ESODBC_ES_TO_SQL_BOOLEAN; + } + /* .data_type is used in data conversions -> make sure the SQL type * derived from type's name is the same with type reported value */ if (sql_type != types[i].data_type) { diff --git a/driver/convert.c b/driver/convert.c index a9ebf19e..e07acb60 100644 --- a/driver/convert.c +++ b/driver/convert.c @@ -316,6 +316,7 @@ SQLULEN get_param_size(esodbc_rec_st *irec) case METATYPE_INTERVAL_WOSEC: return irec->length; + case METATYPE_BIT: case METATYPE_EXACT_NUMERIC: // TODO: make DEC, NUM a floating meta? if (irec->concise_type != SQL_DECIMAL && diff --git a/driver/defs.h b/driver/defs.h index a4b1c589..ee3e3620 100644 --- a/driver/defs.h +++ b/driver/defs.h @@ -116,8 +116,8 @@ /* * Versions */ -/* driver version ex. 1.2(b0a34b4,u,d) */ -#define ESODBC_DRIVER_VER STR(DRV_VER_MAJOR) "." STR(DRV_VER_MINOR) \ +/* driver version ex. 7.0.0(b0a34b4,u,d) */ +#define ESODBC_DRIVER_VER STR(DRV_VERSION) \ "(" STR(DRV_SRC_VER) "," STR(DRV_ENCODING) "," STR(DRV_BUILD_TYPE) ")" /* TODO: learn it from ES */ #define ESODBC_ELASTICSEARCH_VER "7.x" @@ -355,8 +355,8 @@ #define ESODBC_ES_TO_CSQL_DOUBLE SQL_C_DOUBLE #define ESODBC_ES_TO_SQL_DOUBLE SQL_DOUBLE /* 16: ??? -> SQL_C_TINYINT */ -#define ESODBC_ES_TO_CSQL_BOOLEAN SQL_C_STINYINT /* TODO: _C_BIT? */ -#define ESODBC_ES_TO_SQL_BOOLEAN ESODBC_SQL_BOOLEAN +#define ESODBC_ES_TO_CSQL_BOOLEAN SQL_C_BIT +#define ESODBC_ES_TO_SQL_BOOLEAN SQL_BIT /* 12: SQL_VARCHAR -> SQL_C_WCHAR */ #define ESODBC_ES_TO_CSQL_KEYWORD SQL_C_WCHAR /* XXX: CBOR needs _CHAR */ #define ESODBC_ES_TO_SQL_KEYWORD SQL_VARCHAR diff --git a/driver/handles.c b/driver/handles.c index 4e3d190d..7e790432 100644 --- a/driver/handles.c +++ b/driver/handles.c @@ -2001,15 +2001,15 @@ static esodbc_metatype_et sqltype_to_meta(SQLSMALLINT concise) case SQL_INTERVAL_MINUTE_TO_SECOND: return METATYPE_INTERVAL_WSEC; - case SQL_BIT: - return METATYPE_BIT; - case SQL_GUID: return METATYPE_UID; + /* bool */ + case SQL_BIT: /* ES/SQL types */ case ESODBC_SQL_BOOLEAN: - return METATYPE_EXACT_NUMERIC; + return METATYPE_BIT; + case ESODBC_SQL_NULL: return METATYPE_MAX; @@ -2087,6 +2087,7 @@ static esodbc_metatype_et sqlctype_to_meta(SQLSMALLINT concise) case SQL_C_INTERVAL_MINUTE_TO_SECOND: return METATYPE_INTERVAL_WSEC; + /* boolean */ case SQL_C_BIT: return METATYPE_BIT; diff --git a/driver/queries.c b/driver/queries.c index 429950cb..2be3893a 100644 --- a/driver/queries.c +++ b/driver/queries.c @@ -56,6 +56,7 @@ static void set_col_size(esodbc_rec_st *rec) case METATYPE_UNKNOWN: /* SYS TYPES call */ break; + case METATYPE_BIT: case METATYPE_EXACT_NUMERIC: case METATYPE_FLOAT_NUMERIC: /* ignore, the .precision field is not used in IRDs, its value is @@ -1334,7 +1335,7 @@ static esodbc_estype_st *match_es_type(esodbc_rec_st *arec, irec->concise_type == SQL_TYPE_TIME); return lookup_es_type(dbc, SQL_TYPE_TIMESTAMP, /*no prec*/0); case METATYPE_BIT: - return lookup_es_type(dbc, ESODBC_SQL_BOOLEAN, /*no prec*/0); + return lookup_es_type(dbc, SQL_BIT, /*no prec*/0); case METATYPE_UID: return lookup_es_type(dbc, SQL_VARCHAR, /*no prec: TEXT*/0); @@ -1591,6 +1592,7 @@ static SQLRETURN convert_param_val(esodbc_rec_st *arec, esodbc_rec_st *irec, case SQL_UNKNOWN_TYPE: /* NULL */ return c2sql_null(arec, irec, dest, len); + case SQL_BIT: /* BIT */ case ESODBC_SQL_BOOLEAN: /* BOOLEAN */ return c2sql_boolean(arec, irec, pos, dest, len); diff --git a/test/test_conversion_sql2c_ints.cc b/test/test_conversion_sql2c_ints.cc index 860417fb..e96005bb 100644 --- a/test/test_conversion_sql2c_ints.cc +++ b/test/test_conversion_sql2c_ints.cc @@ -378,12 +378,7 @@ TEST_F(ConvertSQL2C_Ints, Long2BigInt_signed_min) { #undef SQL_VAL #undef SQL #define SQL_RAW LLONG_MIN -//#define SQL_VAL STR(SQL_RAW) -#ifdef _WIN64 #define SQL_VAL "-9223372036854775808" // 0x8000000000000000 -#else /* _WIN64 */ -#define SQL_VAL "-2147483648" -#endif /* _WIN64 */ #define SQL "CAST(" SQL_VAL " AS INTEGER)" const char json_answer[] = "\ @@ -416,12 +411,7 @@ TEST_F(ConvertSQL2C_Ints, Long2UBigInt_signed_max) { #undef SQL_VAL #undef SQL #define SQL_RAW LLONG_MAX -//#define SQL_VAL STR(SQL_RAW) -#ifdef _WIN64 #define SQL_VAL "9223372036854775807" // 0x7fffffffffffffff -#else /* _WIN64 */ -#define SQL_VAL "2147483647" -#endif /* _WIN64 */ #define SQL "CAST(" SQL_VAL " AS INTEGER)" const char json_answer[] = "\