Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert ES/BOOLEAN to SQL C BIT #20

Merged
merged 2 commits into from
Sep 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions driver/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions driver/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
8 changes: 4 additions & 4 deletions driver/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions driver/handles.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
4 changes: 3 additions & 1 deletion driver/queries.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
10 changes: 0 additions & 10 deletions test/test_conversion_sql2c_ints.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = "\
Expand Down Expand Up @@ -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[] = "\
Expand Down