From 15364b8e78b97c1621056f620939b9a600013233 Mon Sep 17 00:00:00 2001 From: freemine Date: Thu, 22 Oct 2020 20:19:18 +0800 Subject: [PATCH] refactor --- src/client/src/tscPrepare.c | 3 +- src/connector/odbc/src/todbc.c | 1104 +++++---------------------- src/connector/odbc/src/todbc_conv.c | 329 +++++--- src/connector/odbc/src/todbc_conv.h | 79 +- src/connector/odbc/src/todbc_util.h | 2 - src/connector/odbc/tests/odbc.py | 4 +- 6 files changed, 472 insertions(+), 1049 deletions(-) diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 1739e4348c..68f2ecbf0e 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -268,7 +268,6 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) { if (1) { // allow user bind param data with different type - short size = 0; union { int8_t v1; int16_t v2; @@ -600,7 +599,7 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) { if ((*bind->length) > (uintptr_t)param->bytes) { return TSDB_CODE_TSC_INVALID_VALUE; } - size = (short)*bind->length; + short size = (short)*bind->length; STR_WITH_SIZE_TO_VARSTR(data + param->offset, bind->buffer, size); return TSDB_CODE_SUCCESS; } break; diff --git a/src/connector/odbc/src/todbc.c b/src/connector/odbc/src/todbc.c index 594d53d132..5ec8846128 100644 --- a/src/connector/odbc/src/todbc.c +++ b/src/connector/odbc/src/todbc.c @@ -144,7 +144,7 @@ do { \ D("%s: elapsed: [%.6f]s", #statement, delta); \ } while (0) -#define CHK_CONV(statement) \ +#define CHK_CONV(todb, statement) \ do { \ TSDB_CONV_CODE code = (statement); \ switch (code) { \ @@ -163,7 +163,7 @@ do { \ } break; \ case TSDB_CONV_TRUNC_FRACTION: { \ SET_ERROR(sql, "01S07", TSDB_CODE_ODBC_CONV_TRUNC_FRAC, ""); \ - return SQL_ERROR; \ + return todb ? SQL_ERROR : SQL_SUCCESS_WITH_INFO; \ } break; \ case TSDB_CONV_TRUNC: { \ SET_ERROR(sql, "22001", TSDB_CODE_ODBC_CONV_TRUNC, ""); \ @@ -221,6 +221,10 @@ struct sql_s { uint64_t refcount; conn_t *conn; + iconv_t w2c; // wchar* -> char* + iconv_t u2c; // unicode -> char* + iconv_t u2w; // unicode -> wchar* + TAOS_STMT *stmt; param_bind_t *params; int n_params; @@ -250,6 +254,29 @@ static pthread_once_t init_once = PTHREAD_ONCE_INIT; static void init_routine(void); static int do_field_display_size(TAOS_FIELD *field); +static iconv_t sql_get_w2c(sql_t *sql) { + if (sql->w2c == (iconv_t)-1) { + sql->w2c = iconv_open("UTF-8", "UCS-2LE"); + } + + return sql->w2c; +} + +// static iconv_t sql_get_u2c(sql_t *sql) { +// if (sql->u2c == (iconv_t)-1) { +// sql->u2c = iconv_open("UTF-8", "UCS-4LE"); +// } +// +// return sql->u2c; +// } +// +// static iconv_t sql_get_u2w(sql_t *sql) { +// if (sql->u2w == (iconv_t)-1) { +// sql->u2w = iconv_open("UCS-2LE", "UCS-4LE"); +// } +// +// return sql->u2w; +// } static SQLRETURN doSQLAllocEnv(SQLHENV *EnvironmentHandle) { @@ -456,6 +483,10 @@ static SQLRETURN doSQLAllocStmt(SQLHDBC ConnectionHandle, break; } + sql->w2c = (iconv_t)-1; + sql->u2c = (iconv_t)-1; + sql->u2w = (iconv_t)-1; + sql->conn = conn; DASSERT(INC_REF(sql)>0); @@ -547,6 +578,20 @@ static SQLRETURN doSQLFreeStmt(SQLHSTMT StatementHandle, sql->conn = NULL; FREE_ERROR(sql); + + if (sql->w2c!=(iconv_t)-1) { + iconv_close(sql->w2c); + sql->w2c = (iconv_t)-1; + } + if (sql->u2c!=(iconv_t)-1) { + iconv_close(sql->u2c); + sql->u2c = (iconv_t)-1; + } + if (sql->u2w!=(iconv_t)-1) { + iconv_close(sql->u2w); + sql->u2w = (iconv_t)-1; + } + free(sql); return SQL_SUCCESS; @@ -753,64 +798,6 @@ SQLRETURN SQL_API SQLColAttribute(SQLHSTMT StatementHandle, return r; } -static SQLRETURN conv_tsdb_bool_to_c_bit(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t b); -static SQLRETURN conv_tsdb_bool_to_c_tinyint(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t b); -static SQLRETURN conv_tsdb_bool_to_c_short(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t b); -static SQLRETURN conv_tsdb_bool_to_c_long(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t b); -static SQLRETURN conv_tsdb_bool_to_c_sbigint(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t b); -static SQLRETURN conv_tsdb_bool_to_c_float(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t b); -static SQLRETURN conv_tsdb_bool_to_c_double(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t b); -static SQLRETURN conv_tsdb_bool_to_c_char(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t b); -static SQLRETURN conv_tsdb_bool_to_c_binary(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t b); -static SQLRETURN conv_tsdb_v1_to_c_tinyint(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t v1); -static SQLRETURN conv_tsdb_v1_to_c_short(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t v1); -static SQLRETURN conv_tsdb_v1_to_c_long(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t v1); -static SQLRETURN conv_tsdb_v1_to_c_sbigint(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t v1); -static SQLRETURN conv_tsdb_v1_to_c_float(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t v1); -static SQLRETURN conv_tsdb_v1_to_c_double(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t v1); -static SQLRETURN conv_tsdb_v1_to_c_char(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t v1); -static SQLRETURN conv_tsdb_v1_to_c_binary(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t v1); -static SQLRETURN conv_tsdb_v2_to_c_short(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int16_t v2); -static SQLRETURN conv_tsdb_v2_to_c_long(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int16_t v2); -static SQLRETURN conv_tsdb_v2_to_c_sbigint(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int16_t v2); -static SQLRETURN conv_tsdb_v2_to_c_float(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int16_t v2); -static SQLRETURN conv_tsdb_v2_to_c_double(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int16_t v2); -static SQLRETURN conv_tsdb_v2_to_c_char(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int16_t v2); -static SQLRETURN conv_tsdb_v2_to_c_binary(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int16_t v2); -static SQLRETURN conv_tsdb_v4_to_c_long(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int32_t v4); -static SQLRETURN conv_tsdb_v4_to_c_sbigint(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int32_t v4); -static SQLRETURN conv_tsdb_v4_to_c_float(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int32_t v4); -static SQLRETURN conv_tsdb_v4_to_c_double(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int32_t v4); -static SQLRETURN conv_tsdb_v4_to_c_char(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int32_t v4); -static SQLRETURN conv_tsdb_v4_to_c_binary(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int32_t v4); -static SQLRETURN conv_tsdb_v8_to_c_sbigint(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int64_t v8); -static SQLRETURN conv_tsdb_v8_to_c_float(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int64_t v8); -static SQLRETURN conv_tsdb_v8_to_c_double(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int64_t v8); -static SQLRETURN conv_tsdb_v8_to_c_char(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int64_t v8); -static SQLRETURN conv_tsdb_v8_to_c_binary(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int64_t v8); -static SQLRETURN conv_tsdb_f4_to_c_float(sql_t *sql, c_target_t *target, TAOS_FIELD *field, float f4); -static SQLRETURN conv_tsdb_f4_to_c_double(sql_t *sql, c_target_t *target, TAOS_FIELD *field, float f4); -static SQLRETURN conv_tsdb_f4_to_c_char(sql_t *sql, c_target_t *target, TAOS_FIELD *field, float f4); -static SQLRETURN conv_tsdb_f4_to_c_binary(sql_t *sql, c_target_t *target, TAOS_FIELD *field, float f4); -static SQLRETURN conv_tsdb_f8_to_c_double(sql_t *sql, c_target_t *target, TAOS_FIELD *field, double f8); -static SQLRETURN conv_tsdb_f8_to_c_char(sql_t *sql, c_target_t *target, TAOS_FIELD *field, double f8); -static SQLRETURN conv_tsdb_f8_to_c_binary(sql_t *sql, c_target_t *target, TAOS_FIELD *field, double f8); -static SQLRETURN conv_tsdb_ts_to_c_v8(sql_t *sql, c_target_t *target, TAOS_FIELD *field, SQL_TIMESTAMP_STRUCT *ts); -static SQLRETURN conv_tsdb_ts_to_c_str(sql_t *sql, c_target_t *target, TAOS_FIELD *field, SQL_TIMESTAMP_STRUCT *ts); -static SQLRETURN conv_tsdb_ts_to_c_bin(sql_t *sql, c_target_t *target, TAOS_FIELD *field, SQL_TIMESTAMP_STRUCT *ts); -static SQLRETURN conv_tsdb_ts_to_c_ts(sql_t *sql, c_target_t *target, TAOS_FIELD *field, SQL_TIMESTAMP_STRUCT *ts); -static SQLRETURN conv_tsdb_bin_to_c_str(sql_t *sql, c_target_t *target, TAOS_FIELD *field, const unsigned char *bin); -static SQLRETURN conv_tsdb_bin_to_c_bin(sql_t *sql, c_target_t *target, TAOS_FIELD *field, const unsigned char *bin); -static SQLRETURN conv_tsdb_str_to_c_bit(sql_t *sql, c_target_t *target, TAOS_FIELD *field, const char *str); -static SQLRETURN conv_tsdb_str_to_c_v1(sql_t *sql, c_target_t *target, TAOS_FIELD *field, const char *str); -static SQLRETURN conv_tsdb_str_to_c_v2(sql_t *sql, c_target_t *target, TAOS_FIELD *field, const char *str); -static SQLRETURN conv_tsdb_str_to_c_v4(sql_t *sql, c_target_t *target, TAOS_FIELD *field, const char *str); -static SQLRETURN conv_tsdb_str_to_c_v8(sql_t *sql, c_target_t *target, TAOS_FIELD *field, const char *str); -static SQLRETURN conv_tsdb_str_to_c_f4(sql_t *sql, c_target_t *target, TAOS_FIELD *field, const char *str); -static SQLRETURN conv_tsdb_str_to_c_f8(sql_t *sql, c_target_t *target, TAOS_FIELD *field, const char *str); -static SQLRETURN conv_tsdb_str_to_c_str(sql_t *sql, c_target_t *target, TAOS_FIELD *field, const char *str); -static SQLRETURN conv_tsdb_str_to_c_bin(sql_t *sql, c_target_t *target, TAOS_FIELD *field, const char *str); - static SQLRETURN doSQLGetData(SQLHSTMT StatementHandle, SQLUSMALLINT ColumnNumber, SQLSMALLINT TargetType, SQLPOINTER TargetValue, SQLLEN BufferLength, @@ -865,89 +852,45 @@ static SQLRETURN doSQLGetData(SQLHSTMT StatementHandle, target.soi = StrLen_or_Ind; switch (field->type) { - case TSDB_DATA_TYPE_BOOL: { - int8_t v = *(int8_t*)row; - if (v) v = 1; - switch (target.ct) { - case SQL_C_BIT: return conv_tsdb_bool_to_c_bit(sql, &target, field, v); - case SQL_C_TINYINT: return conv_tsdb_bool_to_c_tinyint(sql, &target, field, v); - case SQL_C_SHORT: return conv_tsdb_bool_to_c_short(sql, &target, field, v); - case SQL_C_LONG: return conv_tsdb_bool_to_c_long(sql, &target, field, v); - case SQL_C_SBIGINT: return conv_tsdb_bool_to_c_sbigint(sql, &target, field, v); - case SQL_C_FLOAT: return conv_tsdb_bool_to_c_float(sql, &target, field, v); - case SQL_C_DOUBLE: return conv_tsdb_bool_to_c_double(sql, &target, field, v); - case SQL_C_CHAR: return conv_tsdb_bool_to_c_char(sql, &target, field, v); - case SQL_C_BINARY: return conv_tsdb_bool_to_c_binary(sql, &target, field, v); - default: { - SET_ERROR(sql, "HYC00", TSDB_CODE_ODBC_NOT_SUPPORT, - "no convertion from [%s] to [%s[%d][0x%x]] for col [%d]", - taos_data_type(field->type), sql_c_type(target.ct), target.ct, target.ct, ColumnNumber); - return SQL_ERROR; - } - } - } break; - case TSDB_DATA_TYPE_TINYINT: { - int8_t v = *(int8_t*)row; - switch (target.ct) { - case SQL_C_TINYINT: return conv_tsdb_v1_to_c_tinyint(sql, &target, field, v); - case SQL_C_SHORT: return conv_tsdb_v1_to_c_short(sql, &target, field, v); - case SQL_C_LONG: return conv_tsdb_v1_to_c_long(sql, &target, field, v); - case SQL_C_SBIGINT: return conv_tsdb_v1_to_c_sbigint(sql, &target, field, v); - case SQL_C_FLOAT: return conv_tsdb_v1_to_c_float(sql, &target, field, v); - case SQL_C_DOUBLE: return conv_tsdb_v1_to_c_double(sql, &target, field, v); - case SQL_C_CHAR: return conv_tsdb_v1_to_c_char(sql, &target, field, v); - case SQL_C_BINARY: return conv_tsdb_v1_to_c_binary(sql, &target, field, v); - default: { - SET_ERROR(sql, "HYC00", TSDB_CODE_ODBC_NOT_SUPPORT, - "no convertion from [%s] to [%s[%d][0x%x]] for col [%d]", - taos_data_type(field->type), sql_c_type(target.ct), target.ct, target.ct, ColumnNumber); - return SQL_ERROR; - } - } - } break; - case TSDB_DATA_TYPE_SMALLINT: { - int16_t v = *(int16_t*)row; - switch (target.ct) { - case SQL_C_SHORT: return conv_tsdb_v2_to_c_short(sql, &target, field, v); - case SQL_C_LONG: return conv_tsdb_v2_to_c_long(sql, &target, field, v); - case SQL_C_SBIGINT: return conv_tsdb_v2_to_c_sbigint(sql, &target, field, v); - case SQL_C_FLOAT: return conv_tsdb_v2_to_c_float(sql, &target, field, v); - case SQL_C_DOUBLE: return conv_tsdb_v2_to_c_double(sql, &target, field, v); - case SQL_C_CHAR: return conv_tsdb_v2_to_c_char(sql, &target, field, v); - case SQL_C_BINARY: return conv_tsdb_v2_to_c_binary(sql, &target, field, v); - default: { - SET_ERROR(sql, "HYC00", TSDB_CODE_ODBC_NOT_SUPPORT, - "no convertion from [%s] to [%s[%d][0x%x]] for col [%d]", - taos_data_type(field->type), sql_c_type(target.ct), target.ct, target.ct, ColumnNumber); - return SQL_ERROR; - } - } - } break; - case TSDB_DATA_TYPE_INT: { - int32_t v = *(int32_t*)row; - switch (target.ct) { - case SQL_C_LONG: return conv_tsdb_v4_to_c_long(sql, &target, field, v); - case SQL_C_SBIGINT: return conv_tsdb_v4_to_c_sbigint(sql, &target, field, v); - case SQL_C_FLOAT: return conv_tsdb_v4_to_c_float(sql, &target, field, v); - case SQL_C_DOUBLE: return conv_tsdb_v4_to_c_double(sql, &target, field, v); - case SQL_C_CHAR: return conv_tsdb_v4_to_c_char(sql, &target, field, v); - case SQL_C_BINARY: return conv_tsdb_v4_to_c_binary(sql, &target, field, v); - default: { - SET_ERROR(sql, "HYC00", TSDB_CODE_ODBC_NOT_SUPPORT, - "no convertion from [%s] to [%s[%d][0x%x]] for col [%d]", - taos_data_type(field->type), sql_c_type(target.ct), target.ct, target.ct, ColumnNumber); - return SQL_ERROR; - } - } - } break; + case TSDB_DATA_TYPE_BOOL: + case TSDB_DATA_TYPE_TINYINT: + case TSDB_DATA_TYPE_SMALLINT: + case TSDB_DATA_TYPE_INT: case TSDB_DATA_TYPE_BIGINT: { - int64_t v = *(int64_t*)row; + int64_t v; + switch (field->type) { + case TSDB_DATA_TYPE_BOOL: v = *(int8_t*)row; if (v) v = 1; break; + case TSDB_DATA_TYPE_TINYINT: v = *(int8_t*)row; break; + case TSDB_DATA_TYPE_SMALLINT: v = *(int16_t*)row; break; + case TSDB_DATA_TYPE_INT: v = *(int32_t*)row; break; + case TSDB_DATA_TYPE_BIGINT: // fall through + default: v = *(int64_t*)row; break; + } switch (target.ct) { - case SQL_C_SBIGINT: return conv_tsdb_v8_to_c_sbigint(sql, &target, field, v); - case SQL_C_FLOAT: return conv_tsdb_v8_to_c_float(sql, &target, field, v); - case SQL_C_DOUBLE: return conv_tsdb_v8_to_c_double(sql, &target, field, v); - case SQL_C_CHAR: return conv_tsdb_v8_to_c_char(sql, &target, field, v); - case SQL_C_BINARY: return conv_tsdb_v8_to_c_binary(sql, &target, field, v); + case SQL_C_BIT: { + CHK_CONV(0, tsdb_int64_to_bit(v, TargetValue)); + } break; + case SQL_C_TINYINT: { + CHK_CONV(0, tsdb_int64_to_tinyint(v, TargetValue)); + } break; + case SQL_C_SHORT: { + CHK_CONV(0, tsdb_int64_to_smallint(v, TargetValue)); + } break; + case SQL_C_LONG: { + CHK_CONV(0, tsdb_int64_to_int(v, TargetValue)); + } break; + case SQL_C_SBIGINT: { + CHK_CONV(0, tsdb_int64_to_bigint(v, TargetValue)); + } break; + case SQL_C_FLOAT: { + CHK_CONV(0, tsdb_int64_to_float(v, TargetValue)); + } break; + case SQL_C_DOUBLE: { + CHK_CONV(0, tsdb_int64_to_double(v, TargetValue)); + } break; + case SQL_C_CHAR: { + CHK_CONV(0, tsdb_int64_to_char(v, TargetValue, BufferLength)); + } break; default: { SET_ERROR(sql, "HYC00", TSDB_CODE_ODBC_NOT_SUPPORT, "no convertion from [%s] to [%s[%d][0x%x]] for col [%d]", @@ -959,10 +902,17 @@ static SQLRETURN doSQLGetData(SQLHSTMT StatementHandle, case TSDB_DATA_TYPE_FLOAT: { float v = *(float*)row; switch (target.ct) { - case SQL_C_FLOAT: return conv_tsdb_f4_to_c_float(sql, &target, field, v); - case SQL_C_DOUBLE: return conv_tsdb_f4_to_c_double(sql, &target, field, v); - case SQL_C_CHAR: return conv_tsdb_f4_to_c_char(sql, &target, field, v); - case SQL_C_BINARY: return conv_tsdb_f4_to_c_binary(sql, &target, field, v); + case SQL_C_FLOAT: { + *(float*)TargetValue = v; + return SQL_SUCCESS; + } break; + case SQL_C_DOUBLE: { + *(double*)TargetValue = v; + return SQL_SUCCESS; + } break; + case SQL_C_CHAR: { + CHK_CONV(0, tsdb_double_to_char(v, TargetValue, BufferLength)); + } break; default: { SET_ERROR(sql, "HYC00", TSDB_CODE_ODBC_NOT_SUPPORT, "no convertion from [%s] to [%s[%d][0x%x]] for col [%d]", @@ -974,9 +924,13 @@ static SQLRETURN doSQLGetData(SQLHSTMT StatementHandle, case TSDB_DATA_TYPE_DOUBLE: { double v = *(double*)row; switch (target.ct) { - case SQL_C_DOUBLE: return conv_tsdb_f8_to_c_double(sql, &target, field, v); - case SQL_C_CHAR: return conv_tsdb_f8_to_c_char(sql, &target, field, v); - case SQL_C_BINARY: return conv_tsdb_f8_to_c_binary(sql, &target, field, v); + case SQL_C_DOUBLE: { + *(double*)TargetValue = v; + return SQL_SUCCESS; + } break; + case SQL_C_CHAR: { + CHK_CONV(0, tsdb_double_to_char(v, TargetValue, BufferLength)); + } break; default: { SET_ERROR(sql, "HYC00", TSDB_CODE_ODBC_NOT_SUPPORT, "no convertion from [%s] to [%s[%d][0x%x]] for col [%d]", @@ -999,11 +953,18 @@ static SQLRETURN doSQLGetData(SQLHSTMT StatementHandle, ts.second = tm.tm_sec; ts.fraction = v%1000 * 1000000; switch (target.ct) { - case SQL_C_SBIGINT: return conv_tsdb_ts_to_c_v8(sql, &target, field, &ts); - case SQL_C_CHAR: return conv_tsdb_ts_to_c_str(sql, &target, field, &ts); - case SQL_C_BINARY: return conv_tsdb_ts_to_c_bin(sql, &target, field, &ts); + case SQL_C_SBIGINT: { + *(int64_t*)TargetValue = v; + return SQL_SUCCESS; + } break; + case SQL_C_CHAR: { + CHK_CONV(0, tsdb_timestamp_to_char(ts, TargetValue, BufferLength)); + } break; case SQL_C_TYPE_TIMESTAMP: - case SQL_C_TIMESTAMP: return conv_tsdb_ts_to_c_ts(sql, &target, field, &ts); + case SQL_C_TIMESTAMP: { + *(SQL_TIMESTAMP_STRUCT*)TargetValue = ts; + return SQL_SUCCESS; + } break; default: { SET_ERROR(sql, "HYC00", TSDB_CODE_ODBC_NOT_SUPPORT, "no convertion from [%s] to [%s[%d][0x%x]] for col [%d]", @@ -1013,10 +974,12 @@ static SQLRETURN doSQLGetData(SQLHSTMT StatementHandle, } } break; case TSDB_DATA_TYPE_BINARY: { - const unsigned char *bin = (const unsigned char *)row; + size_t field_bytes = field->bytes; + field_bytes -= VARSTR_HEADER_SIZE; switch (target.ct) { - case SQL_C_CHAR: return conv_tsdb_bin_to_c_str(sql, &target, field, bin); - case SQL_C_BINARY: return conv_tsdb_bin_to_c_bin(sql, &target, field, bin); + case SQL_C_CHAR: { + CHK_CONV(0, tsdb_chars_to_char((const char*)row, field_bytes, TargetValue, BufferLength)); + } break; default: { SET_ERROR(sql, "HYC00", TSDB_CODE_ODBC_NOT_SUPPORT, "no convertion from [%s] to [%s[%d][0x%x]] for col [%d]", @@ -1026,17 +989,12 @@ static SQLRETURN doSQLGetData(SQLHSTMT StatementHandle, } } break; case TSDB_DATA_TYPE_NCHAR: { - const char *str = (const char *)row; + size_t field_bytes = field->bytes; + field_bytes -= VARSTR_HEADER_SIZE; switch (target.ct) { - case SQL_C_BIT: return conv_tsdb_str_to_c_bit(sql, &target, field, str); - case SQL_C_TINYINT: return conv_tsdb_str_to_c_v1(sql, &target, field, str); - case SQL_C_SHORT: return conv_tsdb_str_to_c_v2(sql, &target, field, str); - case SQL_C_LONG: return conv_tsdb_str_to_c_v4(sql, &target, field, str); - case SQL_C_SBIGINT: return conv_tsdb_str_to_c_v8(sql, &target, field, str); - case SQL_C_FLOAT: return conv_tsdb_str_to_c_f4(sql, &target, field, str); - case SQL_C_DOUBLE: return conv_tsdb_str_to_c_f8(sql, &target, field, str); - case SQL_C_CHAR: return conv_tsdb_str_to_c_str(sql, &target, field, str); - case SQL_C_BINARY: return conv_tsdb_str_to_c_bin(sql, &target, field, str); + case SQL_C_CHAR: { + CHK_CONV(0, tsdb_chars_to_char((const char*)row, field_bytes, TargetValue, BufferLength)); + } break; default: { SET_ERROR(sql, "HYC00", TSDB_CODE_ODBC_NOT_SUPPORT, "no convertion from [%s] to [%s[%d][0x%x]] for col [%d]", @@ -1268,33 +1226,37 @@ static SQLRETURN do_bind_param_value(sql_t *sql, int idx_row, int idx, param_bin bind->length = &bind->buffer_length; switch (valueType) { case SQL_C_BIT: { - CHK_CONV(tsdb_int64_to_bit(1, *(int8_t*)paramValue, &bind->u.b)); + CHK_CONV(1, tsdb_int64_to_bit(*(int8_t*)paramValue, &bind->u.b)); } break; case SQL_C_TINYINT: case SQL_C_STINYINT: { - CHK_CONV(tsdb_int64_to_bit(1, *(int8_t*)paramValue, &bind->u.b)); + CHK_CONV(1, tsdb_int64_to_bit(*(int8_t*)paramValue, &bind->u.b)); } break; case SQL_C_SHORT: case SQL_C_SSHORT: { - CHK_CONV(tsdb_int64_to_bit(1, *(int16_t*)paramValue, &bind->u.b)); + CHK_CONV(1, tsdb_int64_to_bit(*(int16_t*)paramValue, &bind->u.b)); } break; case SQL_C_LONG: case SQL_C_SLONG: { - CHK_CONV(tsdb_int64_to_bit(1, *(int32_t*)paramValue, &bind->u.b)); + CHK_CONV(1, tsdb_int64_to_bit(*(int32_t*)paramValue, &bind->u.b)); } break; case SQL_C_SBIGINT: { - CHK_CONV(tsdb_int64_to_bit(1, *(int64_t*)paramValue, &bind->u.b)); + CHK_CONV(1, tsdb_int64_to_bit(*(int64_t*)paramValue, &bind->u.b)); + } break; + case SQL_C_FLOAT: { + CHK_CONV(1, tsdb_double_to_bit(*(float*)paramValue, &bind->u.b)); + } break; + case SQL_C_DOUBLE: { + CHK_CONV(1, tsdb_double_to_bit(*(double*)paramValue, &bind->u.b)); } break; case SQL_C_CHAR: { - CHK_CONV(tsdb_chars_to_bit(1, (const char *)paramValue, &bind->u.b)); + CHK_CONV(1, tsdb_chars_to_bit((const char *)paramValue, *soi, &bind->u.b)); } break; case SQL_C_WCHAR: { - CHK_CONV(tsdb_wchars_to_bit(1, (const unsigned char*)paramValue, *soi, &bind->u.b)); + CHK_CONV(1, tsdb_wchars_to_bit(sql_get_w2c(sql), (const unsigned char*)paramValue, *soi, &bind->u.b)); } break; case SQL_C_USHORT: case SQL_C_ULONG: - case SQL_C_FLOAT: - case SQL_C_DOUBLE: case SQL_C_UTINYINT: case SQL_C_UBIGINT: case SQL_C_BINARY: @@ -1322,28 +1284,28 @@ static SQLRETURN do_bind_param_value(sql_t *sql, int idx_row, int idx, param_bin bind->length = &bind->buffer_length; switch (valueType) { case SQL_C_BIT: { - CHK_CONV(tsdb_int64_to_tinyint(1, *(int8_t*)paramValue, &bind->u.v1)); + CHK_CONV(1, tsdb_int64_to_tinyint(*(int8_t*)paramValue, &bind->u.v1)); } break; case SQL_C_STINYINT: case SQL_C_TINYINT: { - CHK_CONV(tsdb_int64_to_tinyint(1, *(int8_t*)paramValue, &bind->u.v1)); + CHK_CONV(1, tsdb_int64_to_tinyint(*(int8_t*)paramValue, &bind->u.v1)); } break; case SQL_C_SSHORT: case SQL_C_SHORT: { - CHK_CONV(tsdb_int64_to_tinyint(1, *(int16_t*)paramValue, &bind->u.v1)); + CHK_CONV(1, tsdb_int64_to_tinyint(*(int16_t*)paramValue, &bind->u.v1)); } break; case SQL_C_SLONG: case SQL_C_LONG: { - CHK_CONV(tsdb_int64_to_tinyint(1, *(int32_t*)paramValue, &bind->u.v1)); + CHK_CONV(1, tsdb_int64_to_tinyint(*(int32_t*)paramValue, &bind->u.v1)); } break; case SQL_C_SBIGINT: { - CHK_CONV(tsdb_int64_to_tinyint(1, *(int64_t*)paramValue, &bind->u.v1)); + CHK_CONV(1, tsdb_int64_to_tinyint(*(int64_t*)paramValue, &bind->u.v1)); } break; case SQL_C_CHAR: { - CHK_CONV(tsdb_chars_to_tinyint(1, (const char*)paramValue, &bind->u.v1)); + CHK_CONV(1, tsdb_chars_to_tinyint((const char*)paramValue, *soi, &bind->u.v1)); } break; case SQL_C_WCHAR: { - CHK_CONV(tsdb_wchars_to_tinyint(1, (const unsigned char*)paramValue, *soi, &bind->u.v1)); + CHK_CONV(1, tsdb_wchars_to_tinyint(sql_get_w2c(sql), (const unsigned char*)paramValue, *soi, &bind->u.v1)); } break; case SQL_C_USHORT: case SQL_C_ULONG: @@ -1376,28 +1338,28 @@ static SQLRETURN do_bind_param_value(sql_t *sql, int idx_row, int idx, param_bin bind->length = &bind->buffer_length; switch (valueType) { case SQL_C_BIT: { - CHK_CONV(tsdb_int64_to_smallint(1, *(int8_t*)paramValue, &bind->u.v2)); + CHK_CONV(1, tsdb_int64_to_smallint(*(int8_t*)paramValue, &bind->u.v2)); } break; case SQL_C_STINYINT: case SQL_C_TINYINT: { - CHK_CONV(tsdb_int64_to_smallint(1, *(int8_t*)paramValue, &bind->u.v2)); + CHK_CONV(1, tsdb_int64_to_smallint(*(int8_t*)paramValue, &bind->u.v2)); } break; case SQL_C_SSHORT: case SQL_C_SHORT: { - CHK_CONV(tsdb_int64_to_smallint(1, *(int16_t*)paramValue, &bind->u.v2)); + CHK_CONV(1, tsdb_int64_to_smallint(*(int16_t*)paramValue, &bind->u.v2)); } break; case SQL_C_SLONG: case SQL_C_LONG: { - CHK_CONV(tsdb_int64_to_smallint(1, *(int32_t*)paramValue, &bind->u.v2)); + CHK_CONV(1, tsdb_int64_to_smallint(*(int32_t*)paramValue, &bind->u.v2)); } break; case SQL_C_SBIGINT: { - CHK_CONV(tsdb_int64_to_smallint(1, *(int64_t*)paramValue, &bind->u.v2)); + CHK_CONV(1, tsdb_int64_to_smallint(*(int64_t*)paramValue, &bind->u.v2)); } break; case SQL_C_CHAR: { - CHK_CONV(tsdb_chars_to_smallint(1, (const char*)paramValue, &bind->u.v2)); + CHK_CONV(1, tsdb_chars_to_smallint((const char*)paramValue, *soi, &bind->u.v2)); } break; case SQL_C_WCHAR: { - CHK_CONV(tsdb_wchars_to_smallint(1, (const unsigned char*)paramValue, *soi, &bind->u.v2)); + CHK_CONV(1, tsdb_wchars_to_smallint(sql_get_w2c(sql), (const unsigned char*)paramValue, *soi, &bind->u.v2)); } break; case SQL_C_USHORT: case SQL_C_ULONG: @@ -1430,28 +1392,28 @@ static SQLRETURN do_bind_param_value(sql_t *sql, int idx_row, int idx, param_bin bind->length = &bind->buffer_length; switch (valueType) { case SQL_C_BIT: { - CHK_CONV(tsdb_int64_to_int(1, *(int8_t*)paramValue, &bind->u.v4)); + CHK_CONV(1, tsdb_int64_to_int(*(int8_t*)paramValue, &bind->u.v4)); } break; case SQL_C_STINYINT: case SQL_C_TINYINT: { - CHK_CONV(tsdb_int64_to_int(1, *(int8_t*)paramValue, &bind->u.v4)); + CHK_CONV(1, tsdb_int64_to_int(*(int8_t*)paramValue, &bind->u.v4)); } break; case SQL_C_SSHORT: case SQL_C_SHORT: { - CHK_CONV(tsdb_int64_to_int(1, *(int16_t*)paramValue, &bind->u.v4)); + CHK_CONV(1, tsdb_int64_to_int(*(int16_t*)paramValue, &bind->u.v4)); } break; case SQL_C_SLONG: case SQL_C_LONG: { - CHK_CONV(tsdb_int64_to_int(1, *(int32_t*)paramValue, &bind->u.v4)); + CHK_CONV(1, tsdb_int64_to_int(*(int32_t*)paramValue, &bind->u.v4)); } break; case SQL_C_SBIGINT: { - CHK_CONV(tsdb_int64_to_int(1, *(int64_t*)paramValue, &bind->u.v4)); + CHK_CONV(1, tsdb_int64_to_int(*(int64_t*)paramValue, &bind->u.v4)); } break; case SQL_C_CHAR: { - CHK_CONV(tsdb_chars_to_int(1, (const char*)paramValue, &bind->u.v4)); + CHK_CONV(1, tsdb_chars_to_int((const char*)paramValue, *soi, &bind->u.v4)); } break; case SQL_C_WCHAR: { - CHK_CONV(tsdb_wchars_to_int(1, (const unsigned char*)paramValue, *soi, &bind->u.v4)); + CHK_CONV(1, tsdb_wchars_to_int(sql_get_w2c(sql), (const unsigned char*)paramValue, *soi, &bind->u.v4)); } break; case SQL_C_USHORT: case SQL_C_ULONG: @@ -1484,28 +1446,28 @@ static SQLRETURN do_bind_param_value(sql_t *sql, int idx_row, int idx, param_bin bind->length = &bind->buffer_length; switch (valueType) { case SQL_C_BIT: { - CHK_CONV(tsdb_int64_to_bigint(1, *(int8_t*)paramValue, &bind->u.v8)); + CHK_CONV(1, tsdb_int64_to_bigint(*(int8_t*)paramValue, &bind->u.v8)); } break; case SQL_C_STINYINT: case SQL_C_TINYINT: { - CHK_CONV(tsdb_int64_to_bigint(1, *(int8_t*)paramValue, &bind->u.v8)); + CHK_CONV(1, tsdb_int64_to_bigint(*(int8_t*)paramValue, &bind->u.v8)); } break; case SQL_C_SSHORT: case SQL_C_SHORT: { - CHK_CONV(tsdb_int64_to_bigint(1, *(int16_t*)paramValue, &bind->u.v8)); + CHK_CONV(1, tsdb_int64_to_bigint(*(int16_t*)paramValue, &bind->u.v8)); } break; case SQL_C_SLONG: case SQL_C_LONG: { - CHK_CONV(tsdb_int64_to_bigint(1, *(int32_t*)paramValue, &bind->u.v8)); + CHK_CONV(1, tsdb_int64_to_bigint(*(int32_t*)paramValue, &bind->u.v8)); } break; case SQL_C_SBIGINT: { - CHK_CONV(tsdb_int64_to_bigint(1, *(int64_t*)paramValue, &bind->u.v8)); + CHK_CONV(1, tsdb_int64_to_bigint(*(int64_t*)paramValue, &bind->u.v8)); } break; case SQL_C_CHAR: { - CHK_CONV(tsdb_chars_to_bigint(1, (const char*)paramValue, &bind->u.v8)); + CHK_CONV(1, tsdb_chars_to_bigint((const char*)paramValue, *soi, &bind->u.v8)); } break; case SQL_C_WCHAR: { - CHK_CONV(tsdb_wchars_to_bigint(1, (const unsigned char*)paramValue, *soi, &bind->u.v8)); + CHK_CONV(1, tsdb_wchars_to_bigint(sql_get_w2c(sql), (const unsigned char*)paramValue, *soi, &bind->u.v8)); } break; case SQL_C_USHORT: case SQL_C_ULONG: @@ -1538,37 +1500,39 @@ static SQLRETURN do_bind_param_value(sql_t *sql, int idx_row, int idx, param_bin bind->length = &bind->buffer_length; switch (valueType) { case SQL_C_BIT: { - CHK_CONV(tsdb_int64_to_float(1, *(int8_t*)paramValue, &bind->u.f4)); + CHK_CONV(1, tsdb_int64_to_float(*(int8_t*)paramValue, &bind->u.f4)); } break; case SQL_C_STINYINT: case SQL_C_TINYINT: { - CHK_CONV(tsdb_int64_to_float(1, *(int8_t*)paramValue, &bind->u.f4)); + CHK_CONV(1, tsdb_int64_to_float(*(int8_t*)paramValue, &bind->u.f4)); } break; case SQL_C_SSHORT: case SQL_C_SHORT: { - CHK_CONV(tsdb_int64_to_float(1, *(int16_t*)paramValue, &bind->u.f4)); + CHK_CONV(1, tsdb_int64_to_float(*(int16_t*)paramValue, &bind->u.f4)); } break; case SQL_C_SLONG: case SQL_C_LONG: { - CHK_CONV(tsdb_int64_to_float(1, *(int32_t*)paramValue, &bind->u.f4)); + CHK_CONV(1, tsdb_int64_to_float(*(int32_t*)paramValue, &bind->u.f4)); } break; case SQL_C_SBIGINT: { - CHK_CONV(tsdb_int64_to_float(1, *(int64_t*)paramValue, &bind->u.f4)); + CHK_CONV(1, tsdb_int64_to_float(*(int64_t*)paramValue, &bind->u.f4)); } break; case SQL_C_FLOAT: { bind->u.f4 = *(float*)paramValue; } break; + case SQL_C_DOUBLE: { + bind->u.f4 = (float)*(double*)paramValue; + } break; case SQL_C_CHAR: { - CHK_CONV(tsdb_chars_to_float(1, (const char*)paramValue, &bind->u.f4)); + CHK_CONV(1, tsdb_chars_to_float((const char*)paramValue, *soi, &bind->u.f4)); } break; case SQL_C_WCHAR: { - CHK_CONV(tsdb_wchars_to_float(1, (const unsigned char*)paramValue, *soi, &bind->u.f4)); + CHK_CONV(1, tsdb_wchars_to_float(sql_get_w2c(sql), (const unsigned char*)paramValue, *soi, &bind->u.f4)); } break; case SQL_C_USHORT: case SQL_C_ULONG: case SQL_C_UTINYINT: case SQL_C_UBIGINT: - case SQL_C_DOUBLE: case SQL_C_BINARY: case SQL_C_DATE: case SQL_C_TIME: @@ -1594,22 +1558,22 @@ static SQLRETURN do_bind_param_value(sql_t *sql, int idx_row, int idx, param_bin bind->length = &bind->buffer_length; switch (valueType) { case SQL_C_BIT: { - CHK_CONV(tsdb_int64_to_double(1, *(int8_t*)paramValue, &bind->u.f8)); + CHK_CONV(1, tsdb_int64_to_double(*(int8_t*)paramValue, &bind->u.f8)); } break; case SQL_C_STINYINT: case SQL_C_TINYINT: { - CHK_CONV(tsdb_int64_to_double(1, *(int8_t*)paramValue, &bind->u.f8)); + CHK_CONV(1, tsdb_int64_to_double(*(int8_t*)paramValue, &bind->u.f8)); } break; case SQL_C_SSHORT: case SQL_C_SHORT: { - CHK_CONV(tsdb_int64_to_double(1, *(int16_t*)paramValue, &bind->u.f8)); + CHK_CONV(1, tsdb_int64_to_double(*(int16_t*)paramValue, &bind->u.f8)); } break; case SQL_C_SLONG: case SQL_C_LONG: { - CHK_CONV(tsdb_int64_to_double(1, *(int32_t*)paramValue, &bind->u.f8)); + CHK_CONV(1, tsdb_int64_to_double(*(int32_t*)paramValue, &bind->u.f8)); } break; case SQL_C_SBIGINT: { - CHK_CONV(tsdb_int64_to_double(1, *(int64_t*)paramValue, &bind->u.f8)); + CHK_CONV(1, tsdb_int64_to_double(*(int64_t*)paramValue, &bind->u.f8)); } break; case SQL_C_FLOAT: { bind->u.f8 = *(float*)paramValue; @@ -1618,10 +1582,10 @@ static SQLRETURN do_bind_param_value(sql_t *sql, int idx_row, int idx, param_bin bind->u.f8 = *(double*)paramValue; } break; case SQL_C_CHAR: { - CHK_CONV(tsdb_chars_to_double(1, (const char*)paramValue, &bind->u.f8)); + CHK_CONV(1, tsdb_chars_to_double((const char*)paramValue, *soi, &bind->u.f8)); } break; case SQL_C_WCHAR: { - CHK_CONV(tsdb_wchars_to_double(1, (const unsigned char*)paramValue, *soi, &bind->u.f8)); + CHK_CONV(1, tsdb_wchars_to_double(sql_get_w2c(sql), (const unsigned char*)paramValue, *soi, &bind->u.f8)); } break; case SQL_C_USHORT: case SQL_C_ULONG: @@ -2281,7 +2245,7 @@ static SQLRETURN doSQLDescribeCol(SQLHSTMT StatementHandle, } break; case TSDB_DATA_TYPE_BINARY: { - *DataType = SQL_BINARY; + *DataType = SQL_CHAR; if (ColumnSize) *ColumnSize -= VARSTR_HEADER_SIZE; } break; @@ -2474,709 +2438,5 @@ static int do_field_display_size(TAOS_FIELD *field) { return 10; } -// convertion from TSDB_DATA_TYPE_XXX to SQL_C_XXX -static SQLRETURN conv_tsdb_bool_to_c_bit(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t b) -{ - int8_t v = b; - memcpy(target->ptr, &v, sizeof(v)); - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_bool_to_c_tinyint(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t b) -{ - int8_t v = b; - memcpy(target->ptr, &v, sizeof(v)); - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_bool_to_c_short(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t b) -{ - int16_t v = b; - memcpy(target->ptr, &v, sizeof(v)); - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_bool_to_c_long(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t b) -{ - int32_t v = b; - memcpy(target->ptr, &v, sizeof(v)); - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_bool_to_c_sbigint(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t b) -{ - int64_t v = b; - memcpy(target->ptr, &v, sizeof(v)); - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_bool_to_c_float(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t b) -{ - float v = b; - memcpy(target->ptr, &v, sizeof(v)); - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_bool_to_c_double(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t b) -{ - double v = b; - memcpy(target->ptr, &v, sizeof(v)); - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_bool_to_c_char(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t b) -{ - DASSERT(target->len>0); - *target->soi = 1; - target->ptr[0] = '0' + b; - if (target->len>1) { - target->ptr[1] = '\0'; - } - - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_bool_to_c_binary(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t b) -{ - DASSERT(target->len>0); - *target->soi = 1; - target->ptr[0] = '0' + b; - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_v1_to_c_tinyint(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t v1) -{ - int8_t v = v1; - memcpy(target->ptr, &v, sizeof(v)); - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_v1_to_c_short(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t v1) -{ - int16_t v = v1; - memcpy(target->ptr, &v, sizeof(v)); - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_v1_to_c_long(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t v1) -{ - int32_t v = v1; - memcpy(target->ptr, &v, sizeof(v)); - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_v1_to_c_sbigint(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t v1) -{ - int64_t v = v1; - memcpy(target->ptr, &v, sizeof(v)); - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_v1_to_c_float(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t v1) -{ - float v = v1; - memcpy(target->ptr, &v, sizeof(v)); - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_v1_to_c_double(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t v1) -{ - double v = v1; - memcpy(target->ptr, &v, sizeof(v)); - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_v1_to_c_char(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t v1) -{ - char buf[64]; - int n = snprintf(buf, sizeof(buf), "%d", v1); - DASSERT(nsoi = n; - strncpy(target->ptr, buf, (n>=target->len ? target->len : n+1)); - if (n<=target->len) return SQL_SUCCESS; - SET_ERROR(sql, "22003", TSDB_CODE_ODBC_CONV_UNDEF, "TSDB_DATA_TYPE_TINYINT -> SQL_C_BIT"); - return SQL_SUCCESS_WITH_INFO; -} - -static SQLRETURN conv_tsdb_v1_to_c_binary(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int8_t v1) -{ - char buf[64]; - int n = snprintf(buf, sizeof(buf), "%d", v1); - DASSERT(nsoi = n; - strncpy(target->ptr, buf, (n>target->len ? target->len : n)); - if (n<=target->len) return SQL_SUCCESS; - SET_ERROR(sql, "22003", TSDB_CODE_ODBC_CONV_UNDEF, "TSDB_DATA_TYPE_TINYINT -> SQL_C_BIT"); - return SQL_SUCCESS_WITH_INFO; -} - -static SQLRETURN conv_tsdb_v2_to_c_short(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int16_t v2) -{ - int16_t v = v2; - memcpy(target->ptr, &v, sizeof(v)); - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_v2_to_c_long(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int16_t v2) -{ - int32_t v = v2; - memcpy(target->ptr, &v, sizeof(v)); - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_v2_to_c_sbigint(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int16_t v2) -{ - int64_t v = v2; - memcpy(target->ptr, &v, sizeof(v)); - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_v2_to_c_float(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int16_t v2) -{ - float v = v2; - memcpy(target->ptr, &v, sizeof(v)); - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_v2_to_c_double(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int16_t v2) -{ - double v = v2; - memcpy(target->ptr, &v, sizeof(v)); - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_v2_to_c_char(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int16_t v2) -{ - char buf[64]; - int n = snprintf(buf, sizeof(buf), "%d", v2); - DASSERT(nsoi = n; - strncpy(target->ptr, buf, (n>=target->len ? target->len : n+1)); - if (n<=target->len) return SQL_SUCCESS; - SET_ERROR(sql, "22003", TSDB_CODE_ODBC_CONV_UNDEF, "TSDB_DATA_TYPE_SMALLINT -> SQL_C_CHAR"); - return SQL_SUCCESS_WITH_INFO; -} - -static SQLRETURN conv_tsdb_v2_to_c_binary(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int16_t v2) -{ - char buf[64]; - int n = snprintf(buf, sizeof(buf), "%d", v2); - DASSERT(nsoi = n; - strncpy(target->ptr, buf, (n>target->len ? target->len : n)); - if (n<=target->len) return SQL_SUCCESS; - SET_ERROR(sql, "22003", TSDB_CODE_ODBC_CONV_UNDEF, "TSDB_DATA_TYPE_SMALLINT -> SQL_C_CHAR"); - return SQL_SUCCESS_WITH_INFO; -} - - -static SQLRETURN conv_tsdb_v4_to_c_long(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int32_t v4) -{ - int32_t v = v4; - memcpy(target->ptr, &v, sizeof(v)); - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_v4_to_c_sbigint(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int32_t v4) -{ - int64_t v = v4; - memcpy(target->ptr, &v, sizeof(v)); - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_v4_to_c_float(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int32_t v4) -{ - float v = v4; - memcpy(target->ptr, &v, sizeof(v)); - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_v4_to_c_double(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int32_t v4) -{ - double v = v4; - memcpy(target->ptr, &v, sizeof(v)); - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_v4_to_c_char(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int32_t v4) -{ - char buf[64]; - int n = snprintf(buf, sizeof(buf), "%d", v4); - DASSERT(nsoi = n; - strncpy(target->ptr, buf, (n>=target->len ? target->len : n+1)); - if (n<=target->len) return SQL_SUCCESS; - SET_ERROR(sql, "22003", TSDB_CODE_ODBC_CONV_UNDEF, "TSDB_DATA_TYPE_INTEGER -> SQL_C_CHAR"); - return SQL_SUCCESS_WITH_INFO; -} - -static SQLRETURN conv_tsdb_v4_to_c_binary(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int32_t v4) -{ - char buf[64]; - int n = snprintf(buf, sizeof(buf), "%d", v4); - DASSERT(nsoi = n; - strncpy(target->ptr, buf, (n>target->len ? target->len : n)); - if (n<=target->len) return SQL_SUCCESS; - SET_ERROR(sql, "22003", TSDB_CODE_ODBC_CONV_UNDEF, "TSDB_DATA_TYPE_INTEGER -> SQL_C_BINARY"); - return SQL_SUCCESS_WITH_INFO; -} - - -static SQLRETURN conv_tsdb_v8_to_c_sbigint(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int64_t v8) -{ - int64_t v = v8; - memcpy(target->ptr, &v, sizeof(v)); - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_v8_to_c_float(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int64_t v8) -{ - float v = v8; - memcpy(target->ptr, &v, sizeof(v)); - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_v8_to_c_double(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int64_t v8) -{ - double v = v8; - memcpy(target->ptr, &v, sizeof(v)); - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_v8_to_c_char(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int64_t v8) -{ - char buf[64]; - int n = snprintf(buf, sizeof(buf), "%" PRId64 "", v8); - DASSERT(nsoi = n; - strncpy(target->ptr, buf, (n>=target->len ? target->len : n+1)); - if (n<=target->len) return SQL_SUCCESS; - SET_ERROR(sql, "22003", TSDB_CODE_ODBC_CONV_UNDEF, "TSDB_DATA_TYPE_BIGINT -> SQL_C_CHAR"); - return SQL_SUCCESS_WITH_INFO; -} - -static SQLRETURN conv_tsdb_v8_to_c_binary(sql_t *sql, c_target_t *target, TAOS_FIELD *field, int64_t v8) -{ - char buf[64]; - int n = snprintf(buf, sizeof(buf), "%" PRId64 "", v8); - DASSERT(nsoi = n; - strncpy(target->ptr, buf, (n>target->len ? target->len : n)); - if (n<=target->len) return SQL_SUCCESS; - SET_ERROR(sql, "22003", TSDB_CODE_ODBC_CONV_UNDEF, "TSDB_DATA_TYPE_BIGINT -> SQL_C_BINARY"); - return SQL_SUCCESS_WITH_INFO; -} - - -static SQLRETURN conv_tsdb_f4_to_c_float(sql_t *sql, c_target_t *target, TAOS_FIELD *field, float f4) -{ - float v = f4; - memcpy(target->ptr, &v, sizeof(v)); - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_f4_to_c_double(sql_t *sql, c_target_t *target, TAOS_FIELD *field, float f4) -{ - double v = f4; - memcpy(target->ptr, &v, sizeof(v)); - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_f4_to_c_char(sql_t *sql, c_target_t *target, TAOS_FIELD *field, float f4) -{ - char buf[64]; - int n = snprintf(buf, sizeof(buf), "%g", f4); - DASSERT(nsoi = n; - strncpy(target->ptr, buf, (n>=target->len ? target->len : n+1)); - if (n<=target->len) return SQL_SUCCESS; - SET_ERROR(sql, "22003", TSDB_CODE_ODBC_CONV_UNDEF, "TSDB_DATA_TYPE_FLOAT -> SQL_C_CHAR"); - return SQL_SUCCESS_WITH_INFO; -} - -static SQLRETURN conv_tsdb_f4_to_c_binary(sql_t *sql, c_target_t *target, TAOS_FIELD *field, float f4) -{ - char buf[64]; - int n = snprintf(buf, sizeof(buf), "%g", f4); - DASSERT(nsoi = n; - strncpy(target->ptr, buf, (n>target->len ? target->len : n)); - if (n<=target->len) return SQL_SUCCESS; - SET_ERROR(sql, "22003", TSDB_CODE_ODBC_CONV_UNDEF, "TSDB_DATA_TYPE_FLOAT -> SQL_C_BINARY"); - return SQL_SUCCESS_WITH_INFO; -} - - -static SQLRETURN conv_tsdb_f8_to_c_double(sql_t *sql, c_target_t *target, TAOS_FIELD *field, double f8) -{ - double v = f8; - memcpy(target->ptr, &v, sizeof(v)); - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_f8_to_c_char(sql_t *sql, c_target_t *target, TAOS_FIELD *field, double f8) -{ - char buf[64]; - int n = snprintf(buf, sizeof(buf), "%.6f", f8); - DASSERT(nsoi = n; - strncpy(target->ptr, buf, (n>=target->len ? target->len : n+1)); - if (n<=target->len) return SQL_SUCCESS; - SET_ERROR(sql, "22003", TSDB_CODE_ODBC_CONV_UNDEF, "TSDB_DATA_TYPE_DOUBLE -> SQL_C_CHAR"); - return SQL_SUCCESS_WITH_INFO; -} - -static SQLRETURN conv_tsdb_f8_to_c_binary(sql_t *sql, c_target_t *target, TAOS_FIELD *field, double f8) -{ - char buf[64]; - int n = snprintf(buf, sizeof(buf), "%g", f8); - DASSERT(nsoi = n; - strncpy(target->ptr, buf, (n>target->len ? target->len : n)); - if (n<=target->len) return SQL_SUCCESS; - SET_ERROR(sql, "22003", TSDB_CODE_ODBC_CONV_UNDEF, "TSDB_DATA_TYPE_DOUBLE -> SQL_C_BINARY"); - return SQL_SUCCESS_WITH_INFO; -} - - -static SQLRETURN conv_tsdb_ts_to_c_v8(sql_t *sql, c_target_t *target, TAOS_FIELD *field, SQL_TIMESTAMP_STRUCT *ts) -{ - struct tm tm = {0}; - tm.tm_sec = ts->second; - tm.tm_min = ts->minute; - tm.tm_hour = ts->hour; - tm.tm_mday = ts->day; - tm.tm_mon = ts->month - 1; - tm.tm_year = ts->year - 1900; - time_t t = mktime(&tm); - DASSERT(sizeof(t) == sizeof(int64_t)); - int64_t v = (int64_t)t; - v *= 1000; - v += ts->fraction / 1000000; - memcpy(target->ptr, &v, sizeof(v)); - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_ts_to_c_str(sql_t *sql, c_target_t *target, TAOS_FIELD *field, SQL_TIMESTAMP_STRUCT *ts) -{ - struct tm tm = {0}; - tm.tm_sec = ts->second; - tm.tm_min = ts->minute; - tm.tm_hour = ts->hour; - tm.tm_mday = ts->day; - tm.tm_mon = ts->month - 1; - tm.tm_year = ts->year - 1900; - - char buf[64]; - int n = strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm); - DASSERT(n < sizeof(buf)); - - *target->soi = n; - - unsigned int fraction = ts->fraction; - fraction /= 1000000; - snprintf(target->ptr, target->len, "%s.%03d", buf, fraction); - if (target->soi) *target->soi = strlen((const char*)target->ptr); - - if (n <= target->len) { - return SQL_SUCCESS; - } - - SET_ERROR(sql, "22003", TSDB_CODE_ODBC_CONV_UNDEF, "TSDB_DATA_TYPE_TIMESTAMP -> SQL_C_CHAR"); - return SQL_SUCCESS_WITH_INFO; -} - -static SQLRETURN conv_tsdb_ts_to_c_bin(sql_t *sql, c_target_t *target, TAOS_FIELD *field, SQL_TIMESTAMP_STRUCT *ts) -{ - struct tm tm = {0}; - tm.tm_sec = ts->second; - tm.tm_min = ts->minute; - tm.tm_hour = ts->hour; - tm.tm_mday = ts->day; - tm.tm_mon = ts->month - 1; - tm.tm_year = ts->year - 1900; - - char buf[64]; - int n = strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm); - DASSERT(n < sizeof(buf)); - - unsigned int fraction = ts->fraction; - fraction /= 1000000; - snprintf(target->ptr, target->len, "%s.%03d", buf, fraction); - if (target->soi) *target->soi = strlen((const char*)target->ptr); - - if (n <= target->len) { - return SQL_SUCCESS; - } - - SET_ERROR(sql, "22003", TSDB_CODE_ODBC_CONV_UNDEF, "TSDB_DATA_TYPE_TIMESTAMP -> SQL_C_BINARY"); - return SQL_SUCCESS_WITH_INFO; -} - -static SQLRETURN conv_tsdb_ts_to_c_ts(sql_t *sql, c_target_t *target, TAOS_FIELD *field, SQL_TIMESTAMP_STRUCT *ts) -{ - DASSERT(target->len == sizeof(*ts)); - memcpy(target->ptr, ts, sizeof(*ts)); - *target->soi = target->len; - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_bin_to_c_str(sql_t *sql, c_target_t *target, TAOS_FIELD *field, const unsigned char *bin) -{ - if (target->len<1) { - SET_ERROR(sql, "HY090", TSDB_CODE_ODBC_BAD_ARG, ""); - return SQL_ERROR; - } - size_t field_bytes = field->bytes - VARSTR_HEADER_SIZE; - size_t n = strnlen((const char*)bin, field_bytes); - - if (n < target->len) { - memcpy(target->ptr, bin, n); - target->ptr[n] = '\0'; - *target->soi = n; - return SQL_SUCCESS; - } - n = target->len - 1; - *target->soi = n; - if (n > 0) { - memcpy(target->ptr, bin, n-1); - target->ptr[n-1] = '\0'; - } - SET_ERROR(sql, "01004", TSDB_CODE_ODBC_CONV_TRUNC, ""); - return SQL_SUCCESS_WITH_INFO; -} - -static SQLRETURN conv_tsdb_bin_to_c_bin(sql_t *sql, c_target_t *target, TAOS_FIELD *field, const unsigned char *bin) -{ - if (target->len<1) { - SET_ERROR(sql, "HY090", TSDB_CODE_ODBC_BAD_ARG, ""); - return SQL_ERROR; - } - size_t field_bytes = field->bytes - VARSTR_HEADER_SIZE; - size_t n = strnlen((const char*)bin, field_bytes); - - if (n <= target->len) { - memcpy(target->ptr, bin, n); - if (nlen) target->ptr[n] = '\0'; - *target->soi = n; - return SQL_SUCCESS; - } - - n = target->len; - memcpy(target->ptr, bin, n); - *target->soi = n; - SET_ERROR(sql, "01004", TSDB_CODE_ODBC_CONV_TRUNC, ""); - return SQL_SUCCESS_WITH_INFO; -} - -static SQLRETURN conv_tsdb_str_to_c_bit(sql_t *sql, c_target_t *target, TAOS_FIELD *field, const char *str) -{ - int bytes = 0; - double f8 = 0; - int n = sscanf(str, "%lf%n", &f8, &bytes); - - int8_t v = f8; - memcpy(target->ptr, &v, sizeof(v)); - - *target->soi = 1; - - if (n!=1 || bytes!=strlen(str)) { - SET_ERROR(sql, "22018", TSDB_CODE_ODBC_CONV_UNDEF, "TSDB_DATA_TYPE_NCHAR -> SQL_C_BIT"); - return SQL_SUCCESS_WITH_INFO; - } - - char buf[64]; - snprintf(buf, sizeof(buf), "%d", v); - - if (strcmp(buf, str)==0) { - if (v==0 || v==1) return SQL_SUCCESS; - SET_ERROR(sql, "22003", TSDB_CODE_ODBC_CONV_UNDEF, "TSDB_DATA_TYPE_NCHAR -> SQL_C_BIT"); - return SQL_SUCCESS_WITH_INFO; - } - - if (f8>0 || f8<2) { - SET_ERROR(sql, "01S07", TSDB_CODE_ODBC_CONV_TRUNC, "TSDB_DATA_TYPE_NCHAR -> SQL_C_BIT"); - return SQL_SUCCESS_WITH_INFO; - } - - if (f8<0 || f8>2) { - SET_ERROR(sql, "22003", TSDB_CODE_ODBC_CONV_UNDEF, "TSDB_DATA_TYPE_NCHAR -> SQL_C_BIT"); - return SQL_SUCCESS_WITH_INFO; - } - - SET_ERROR(sql, "01S07", TSDB_CODE_ODBC_CONV_UNDEF, "TSDB_DATA_TYPE_NCHAR -> SQL_C_BIT"); - return SQL_SUCCESS_WITH_INFO; -} - -static SQLRETURN conv_tsdb_str_to_c_v1(sql_t *sql, c_target_t *target, TAOS_FIELD *field, const char *str) -{ - int bytes = 0; - double f8 = 0; - int n = sscanf(str, "%lf%n", &f8, &bytes); - - int8_t v = f8; - memcpy(target->ptr, &v, sizeof(v)); - - *target->soi = 1; - - if (n!=1 || bytes!=strlen(str)) { - SET_ERROR(sql, "22018", TSDB_CODE_ODBC_CONV_UNDEF, "TSDB_DATA_TYPE_NCHAR -> SQL_C_TINYINT"); - return SQL_SUCCESS_WITH_INFO; - } - - char buf[64]; - snprintf(buf, sizeof(buf), "%d", v); - - if (strcmp(buf, str)==0) return SQL_SUCCESS; - - if (f8>INT8_MAX || f8 SQL_C_TINYINT"); - return SQL_SUCCESS_WITH_INFO; - } - - SET_ERROR(sql, "01S07", TSDB_CODE_ODBC_CONV_TRUNC, "TSDB_DATA_TYPE_NCHAR -> SQL_C_TINYINT"); - return SQL_SUCCESS_WITH_INFO; -} - -static SQLRETURN conv_tsdb_str_to_c_v2(sql_t *sql, c_target_t *target, TAOS_FIELD *field, const char *str) -{ - int bytes = 0; - double f8 = 0; - int n = sscanf(str, "%lf%n", &f8, &bytes); - - int16_t v = f8; - memcpy(target->ptr, &v, sizeof(v)); - - *target->soi = 2; - - if (n!=1 || bytes!=strlen(str)) { - SET_ERROR(sql, "22018", TSDB_CODE_ODBC_CONV_UNDEF, "TSDB_DATA_TYPE_NCHAR -> SQL_C_SHORT"); - return SQL_SUCCESS_WITH_INFO; - } - - char buf[64]; - snprintf(buf, sizeof(buf), "%d", v); - - if (strcmp(buf, str)==0) return SQL_SUCCESS; - - if (f8>INT16_MAX || f8 SQL_C_SHORT"); - return SQL_SUCCESS_WITH_INFO; - } - - SET_ERROR(sql, "01S07", TSDB_CODE_ODBC_CONV_TRUNC, "TSDB_DATA_TYPE_NCHAR -> SQL_C_SHORT"); - return SQL_SUCCESS_WITH_INFO; -} - -static SQLRETURN conv_tsdb_str_to_c_v4(sql_t *sql, c_target_t *target, TAOS_FIELD *field, const char *str) -{ - int bytes = 0; - double f8 = 0; - int n = sscanf(str, "%lf%n", &f8, &bytes); - - int32_t v = f8; - memcpy(target->ptr, &v, sizeof(v)); - - *target->soi = 4; - - if (n!=1 || bytes!=strlen(str)) { - SET_ERROR(sql, "22018", TSDB_CODE_ODBC_CONV_UNDEF, "TSDB_DATA_TYPE_NCHAR -> SQL_C_LONG"); - return SQL_SUCCESS_WITH_INFO; - } - - char buf[64]; - snprintf(buf, sizeof(buf), "%d", v); - - if (strcmp(buf, str)==0) return SQL_SUCCESS; - - if (f8>INT32_MAX || f8 SQL_C_LONG"); - return SQL_SUCCESS_WITH_INFO; - } - - SET_ERROR(sql, "01S07", TSDB_CODE_ODBC_CONV_TRUNC, "TSDB_DATA_TYPE_NCHAR -> SQL_C_LONG"); - return SQL_SUCCESS_WITH_INFO; -} - -static SQLRETURN conv_tsdb_str_to_c_v8(sql_t *sql, c_target_t *target, TAOS_FIELD *field, const char *str) -{ - int bytes = 0; - double f8 = 0; - int n = sscanf(str, "%lf%n", &f8, &bytes); - - int64_t v = f8; - memcpy(target->ptr, &v, sizeof(v)); - - *target->soi = 8; - - if (n!=1 || bytes!=strlen(str)) { - SET_ERROR(sql, "22018", TSDB_CODE_ODBC_CONV_UNDEF, "TSDB_DATA_TYPE_NCHAR -> SQL_C_SBIGINT"); - return SQL_SUCCESS_WITH_INFO; - } - - char buf[64]; - snprintf(buf, sizeof(buf), "%" PRId64 "", v); - - if (strcmp(buf, str)==0) return SQL_SUCCESS; - - if (f8>INT64_MAX || f8 SQL_C_SBIGINT"); - return SQL_SUCCESS_WITH_INFO; - } - - SET_ERROR(sql, "01S07", TSDB_CODE_ODBC_CONV_TRUNC, "TSDB_DATA_TYPE_NCHAR -> SQL_C_SBIGINT"); - return SQL_SUCCESS_WITH_INFO; -} - -static SQLRETURN conv_tsdb_str_to_c_f4(sql_t *sql, c_target_t *target, TAOS_FIELD *field, const char *str) -{ - int bytes = 0; - double f8 = 0; - int n = sscanf(str, "%lf%n", &f8, &bytes); - - float v = f8; - memcpy(target->ptr, &v, sizeof(v)); - - *target->soi = 4; - - if (n!=1 || bytes!=strlen(str)) { - SET_ERROR(sql, "22018", TSDB_CODE_ODBC_CONV_UNDEF, "TSDB_DATA_TYPE_NCHAR -> SQL_C_FLOAT"); - return SQL_SUCCESS_WITH_INFO; - } - - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_str_to_c_f8(sql_t *sql, c_target_t *target, TAOS_FIELD *field, const char *str) -{ - int bytes = 0; - double f8 = 0; - int n = sscanf(str, "%lf%n", &f8, &bytes); - - float v = f8; - memcpy(target->ptr, &v, sizeof(v)); - - *target->soi = 8; - - if (n!=1 || bytes!=strlen(str)) { - SET_ERROR(sql, "22018", TSDB_CODE_ODBC_CONV_UNDEF, "TSDB_DATA_TYPE_NCHAR -> SQL_C_DOUBLE"); - return SQL_SUCCESS_WITH_INFO; - } - - return SQL_SUCCESS; -} - -static SQLRETURN conv_tsdb_str_to_c_str(sql_t *sql, c_target_t *target, TAOS_FIELD *field, const char *str) -{ - return conv_tsdb_bin_to_c_str(sql, target, field, (const unsigned char*)str); -} - -static SQLRETURN conv_tsdb_str_to_c_bin(sql_t *sql, c_target_t *target, TAOS_FIELD *field, const char *str) -{ - return conv_tsdb_bin_to_c_bin(sql, target, field, (const unsigned char*)str); -} - - diff --git a/src/connector/odbc/src/todbc_conv.c b/src/connector/odbc/src/todbc_conv.c index ccfead3eb3..c4e0ff653f 100644 --- a/src/connector/odbc/src/todbc_conv.c +++ b/src/connector/odbc/src/todbc_conv.c @@ -17,43 +17,102 @@ #include "todbc_util.h" +#include #include #include #include #include +typedef struct buf_s buf_t; + +struct buf_s { + char buf[1024*16+1]; + + char *ptr; +}; + +static char* buf_init(buf_t *buf, size_t len); +static void buf_clean(buf_t *buf); + +static char* buf_init(buf_t *buf, size_t len) { + if (len>sizeof(buf->buf)) { + buf->ptr = (char*)malloc(len); + } else if (len>0) { + buf->ptr = &buf->buf[0]; + } else { + buf->ptr = NULL; + } + return buf->ptr; +} + +static void buf_clean(buf_t *buf) { + if (buf->ptr && buf->ptr != buf->buf) { + free(buf->ptr); + buf->ptr = NULL; + } +} + +TSDB_CONV_CODE tsdb_iconv_conv(iconv_t cnv, const unsigned char *src, size_t *slen, unsigned char *dst, size_t *dlen) { + if(cnv == (iconv_t)-1) return TSDB_CONV_GENERAL; + + char *s = (char*)src; + char *d = (char*)dst; + size_t sl = *slen; + size_t dl = *dlen; + + int n = iconv(cnv, &s, &sl, &d, &dl); + int e = errno; + if (dl) *d = '\0'; // what if all consumed? + + *slen = sl; + *dlen = dl; + + if (e==0) { + if (n) return TSDB_CONV_BAD_CHAR; + return TSDB_CONV_OK; + } + + iconv(cnv, NULL, NULL, NULL, NULL); + + switch (e) { + case E2BIG: return TSDB_CONV_TRUNC; + case EILSEQ: return TSDB_CONV_BAD_CHAR; + case EINVAL: return TSDB_CONV_BAD_CHAR; + default: return TSDB_CONV_GENERAL; + } +} // src: int -TSDB_CONV_CODE tsdb_int64_to_bit(int todb, int64_t src, int8_t *dst) { +TSDB_CONV_CODE tsdb_int64_to_bit(int64_t src, int8_t *dst) { *dst = (int8_t)src; if (src==0 || src==1) return TSDB_CONV_OK; return TSDB_CONV_OOR; } -TSDB_CONV_CODE tsdb_int64_to_tinyint(int todb, int64_t src, int8_t *dst) { +TSDB_CONV_CODE tsdb_int64_to_tinyint(int64_t src, int8_t *dst) { *dst = (int8_t)src; if (src == *dst) return TSDB_CONV_OK; return TSDB_CONV_OOR; } -TSDB_CONV_CODE tsdb_int64_to_smallint(int todb, int64_t src, int16_t *dst) { +TSDB_CONV_CODE tsdb_int64_to_smallint(int64_t src, int16_t *dst) { *dst = (int16_t)src; if (src == *dst) return TSDB_CONV_OK; return TSDB_CONV_OOR; } -TSDB_CONV_CODE tsdb_int64_to_int(int todb, int64_t src, int32_t *dst) { +TSDB_CONV_CODE tsdb_int64_to_int(int64_t src, int32_t *dst) { *dst = (int32_t)src; if (src == *dst) return TSDB_CONV_OK; return TSDB_CONV_OOR; } -TSDB_CONV_CODE tsdb_int64_to_bigint(int todb, int64_t src, int64_t *dst) { +TSDB_CONV_CODE tsdb_int64_to_bigint(int64_t src, int64_t *dst) { *dst = src; return TSDB_CONV_OK; } -TSDB_CONV_CODE tsdb_int64_to_ts(int todb, int64_t src, int64_t *dst) { +TSDB_CONV_CODE tsdb_int64_to_ts(int64_t src, int64_t *dst) { *dst = src; time_t t = (time_t)(src / 1000); @@ -63,7 +122,7 @@ TSDB_CONV_CODE tsdb_int64_to_ts(int todb, int64_t src, int64_t *dst) { return TSDB_CONV_OOR; } -TSDB_CONV_CODE tsdb_int64_to_float(int todb, int64_t src, float *dst) { +TSDB_CONV_CODE tsdb_int64_to_float(int64_t src, float *dst) { *dst = (float)src; int64_t v = (int64_t)*dst; @@ -72,7 +131,7 @@ TSDB_CONV_CODE tsdb_int64_to_float(int todb, int64_t src, float *dst) { return TSDB_CONV_OOR; } -TSDB_CONV_CODE tsdb_int64_to_double(int todb, int64_t src, double *dst) { +TSDB_CONV_CODE tsdb_int64_to_double(int64_t src, double *dst) { *dst = (double)src; int64_t v = (int64_t)*dst; @@ -81,7 +140,7 @@ TSDB_CONV_CODE tsdb_int64_to_double(int todb, int64_t src, double *dst) { return TSDB_CONV_OOR; } -TSDB_CONV_CODE tsdb_int64_to_char(int todb, int64_t src, char *dst, size_t dlen) { +TSDB_CONV_CODE tsdb_int64_to_char(int64_t src, char *dst, size_t dlen) { int n = snprintf(dst, dlen, "%" PRId64 "", src); if (n=2) return TSDB_CONV_OOR; @@ -102,7 +161,7 @@ TSDB_CONV_CODE tsdb_double_to_bit(int todb, double src, int8_t *dst) { return TSDB_CONV_TRUNC; } -TSDB_CONV_CODE tsdb_double_to_tinyint(int todb, double src, int8_t *dst) { +TSDB_CONV_CODE tsdb_double_to_tinyint(double src, int8_t *dst) { *dst = (int8_t)src; if (srcSCHAR_MAX) return TSDB_CONV_OOR; @@ -114,7 +173,7 @@ TSDB_CONV_CODE tsdb_double_to_tinyint(int todb, double src, int8_t *dst) { return TSDB_CONV_TRUNC; } -TSDB_CONV_CODE tsdb_double_to_smallint(int todb, double src, int16_t *dst) { +TSDB_CONV_CODE tsdb_double_to_smallint(double src, int16_t *dst) { *dst = (int16_t)src; if (srcSHRT_MAX) return TSDB_CONV_OOR; @@ -126,7 +185,7 @@ TSDB_CONV_CODE tsdb_double_to_smallint(int todb, double src, int16_t *dst) { return TSDB_CONV_TRUNC; } -TSDB_CONV_CODE tsdb_double_to_int(int todb, double src, int32_t *dst) { +TSDB_CONV_CODE tsdb_double_to_int(double src, int32_t *dst) { *dst = (int32_t)src; if (srcLONG_MAX) return TSDB_CONV_OOR; @@ -138,7 +197,7 @@ TSDB_CONV_CODE tsdb_double_to_int(int todb, double src, int32_t *dst) { return TSDB_CONV_TRUNC; } -TSDB_CONV_CODE tsdb_double_to_bigint(int todb, double src, int64_t *dst) { +TSDB_CONV_CODE tsdb_double_to_bigint(double src, int64_t *dst) { *dst = (int64_t)src; if (srcLLONG_MAX) return TSDB_CONV_OOR; @@ -150,8 +209,8 @@ TSDB_CONV_CODE tsdb_double_to_bigint(int todb, double src, int64_t *dst) { return TSDB_CONV_TRUNC; } -TSDB_CONV_CODE tsdb_double_to_ts(int todb, double src, int64_t *dst) { - TSDB_CONV_CODE code = tsdb_double_to_bigint(todb, src, dst); +TSDB_CONV_CODE tsdb_double_to_ts(double src, int64_t *dst) { + TSDB_CONV_CODE code = tsdb_double_to_bigint(src, dst); if (code==TSDB_CONV_OK || code==TSDB_CONV_TRUNC_FRACTION) { int64_t v = (int64_t)src; @@ -165,8 +224,29 @@ TSDB_CONV_CODE tsdb_double_to_ts(int todb, double src, int64_t *dst) { return code; } +TSDB_CONV_CODE tsdb_double_to_char(double src, char *dst, size_t dlen) { + int n = snprintf(dst, dlen, "%lg", src); + + if (n=19) return TSDB_CONV_TRUNC_FRACTION; + + return TSDB_CONV_TRUNC; +} + // src: chars -TSDB_CONV_CODE tsdb_chars_to_bit(int todb, const char *src, int8_t *dst) { +TSDB_CONV_CODE tsdb_chars_to_bit(const char *src, size_t smax, int8_t *dst) { if (strcmp(src, "0")==0) { *dst = 0; return TSDB_CONV_OK; @@ -189,11 +269,11 @@ TSDB_CONV_CODE tsdb_chars_to_bit(int todb, const char *src, int8_t *dst) { return TSDB_CONV_TRUNC_FRACTION; } -TSDB_CONV_CODE tsdb_chars_to_tinyint(int todb, const char *src, int8_t *dst) { +TSDB_CONV_CODE tsdb_chars_to_tinyint(const char *src, size_t smax, int8_t *dst) { int64_t v; - TSDB_CONV_CODE code = tsdb_chars_to_bigint(todb, src, &v); + TSDB_CONV_CODE code = tsdb_chars_to_bigint(src, smax, &v); if (code!=TSDB_CONV_OK) return code; - + *dst = (int8_t)v; if (v==*dst) return TSDB_CONV_OK; @@ -201,11 +281,11 @@ TSDB_CONV_CODE tsdb_chars_to_tinyint(int todb, const char *src, int8_t *dst) { return TSDB_CONV_OOR; } -TSDB_CONV_CODE tsdb_chars_to_smallint(int todb, const char *src, int16_t *dst) { +TSDB_CONV_CODE tsdb_chars_to_smallint(const char *src, size_t smax, int16_t *dst) { int64_t v; - TSDB_CONV_CODE code = tsdb_chars_to_bigint(todb, src, &v); + TSDB_CONV_CODE code = tsdb_chars_to_bigint(src, smax, &v); if (code!=TSDB_CONV_OK) return code; - + *dst = (int16_t)v; if (v==*dst) return TSDB_CONV_OK; @@ -213,11 +293,11 @@ TSDB_CONV_CODE tsdb_chars_to_smallint(int todb, const char *src, int16_t *dst) { return TSDB_CONV_OOR; } -TSDB_CONV_CODE tsdb_chars_to_int(int todb, const char *src, int32_t *dst) { +TSDB_CONV_CODE tsdb_chars_to_int(const char *src, size_t smax, int32_t *dst) { int64_t v; - TSDB_CONV_CODE code = tsdb_chars_to_bigint(todb, src, &v); + TSDB_CONV_CODE code = tsdb_chars_to_bigint(src, smax, &v); if (code!=TSDB_CONV_OK) return code; - + *dst = (int32_t)v; if (v==*dst) return TSDB_CONV_OK; @@ -225,7 +305,7 @@ TSDB_CONV_CODE tsdb_chars_to_int(int todb, const char *src, int32_t *dst) { return TSDB_CONV_OOR; } -TSDB_CONV_CODE tsdb_chars_to_bigint(int todb, const char *src, int64_t *dst) { +TSDB_CONV_CODE tsdb_chars_to_bigint(const char *src, size_t smax, int64_t *dst) { int bytes; int n = sscanf(src, "%" PRId64 "%n", dst, &bytes); @@ -244,11 +324,11 @@ TSDB_CONV_CODE tsdb_chars_to_bigint(int todb, const char *src, int64_t *dst) { return TSDB_CONV_OK; } -TSDB_CONV_CODE tsdb_chars_to_ts(int todb, const char *src, int64_t *dst) { +TSDB_CONV_CODE tsdb_chars_to_ts(const char *src, size_t smax, int64_t *dst) { int64_t v; - TSDB_CONV_CODE code = tsdb_chars_to_bigint(todb, src, &v); + TSDB_CONV_CODE code = tsdb_chars_to_bigint(src, smax, &v); if (code!=TSDB_CONV_OK) return code; - + *dst = v; if (v==*dst) { @@ -260,7 +340,7 @@ TSDB_CONV_CODE tsdb_chars_to_ts(int todb, const char *src, int64_t *dst) { return TSDB_CONV_OOR; } -TSDB_CONV_CODE tsdb_chars_to_float(int todb, const char *src, float *dst) { +TSDB_CONV_CODE tsdb_chars_to_float(const char *src, size_t smax, float *dst) { int bytes; int n = sscanf(src, "%g%n", dst, &bytes); @@ -271,7 +351,7 @@ TSDB_CONV_CODE tsdb_chars_to_float(int todb, const char *src, float *dst) { return TSDB_CONV_CHAR_NOT_NUM; } -TSDB_CONV_CODE tsdb_chars_to_double(int todb, const char *src, double *dst) { +TSDB_CONV_CODE tsdb_chars_to_double(const char *src, size_t smax, double *dst) { int bytes; int n = sscanf(src, "%lg%n", dst, &bytes); @@ -282,82 +362,155 @@ TSDB_CONV_CODE tsdb_chars_to_double(int todb, const char *src, double *dst) { return TSDB_CONV_CHAR_NOT_NUM; } -TSDB_CONV_CODE tsdb_chars_to_char(int todb, const char *src, char *dst, size_t dlen) { - int n = snprintf(dst, dlen, "%s", src); - if (n= sizeof(buf)) { - plen = slen * 2 + 1; - p = (char*)malloc(plen); - if (!p) return TSDB_CONV_OOM; +TSDB_CONV_CODE tsdb_wchars_to_bit(iconv_t cnv, const unsigned char *src, size_t smax, int8_t *dst) { + if(cnv == (iconv_t)-1) return TSDB_CONV_GENERAL; + + size_t len = smax * 2; + buf_t buf; + buf_init(&buf, len+1); + if (!buf.ptr) return TSDB_CONV_OOM; + + size_t dmax = len + 1; + TSDB_CONV_CODE code = tsdb_iconv_conv(cnv, src, &smax, (unsigned char*)buf.ptr, &dmax); + if (code==TSDB_CONV_OK) { + code = tsdb_chars_to_bit(buf.ptr, len+1-dmax, dst); + } + + buf_clean(&buf); + + return code; +} + +TSDB_CONV_CODE tsdb_wchars_to_tinyint(iconv_t cnv, const unsigned char *src, size_t smax, int8_t *dst) { + if(cnv == (iconv_t)-1) return TSDB_CONV_GENERAL; + + size_t len = smax * 2; + buf_t buf; + buf_init(&buf, len+1); + if (!buf.ptr) return TSDB_CONV_OOM; + + size_t dmax = len + 1; + TSDB_CONV_CODE code = tsdb_iconv_conv(cnv, src, &smax, (unsigned char*)buf.ptr, &dmax); + if (code==TSDB_CONV_OK) { + code = tsdb_chars_to_tinyint(buf.ptr, len+1-dmax, dst); + } + + buf_clean(&buf); + + return code; +} + +TSDB_CONV_CODE tsdb_wchars_to_smallint(iconv_t cnv, const unsigned char *src, size_t smax, int16_t *dst) { + if(cnv == (iconv_t)-1) return TSDB_CONV_GENERAL; + + size_t len = smax * 2; + buf_t buf; + buf_init(&buf, len+1); + if (!buf.ptr) return TSDB_CONV_OOM; + + size_t dmax = len + 1; + TSDB_CONV_CODE code = tsdb_iconv_conv(cnv, src, &smax, (unsigned char*)buf.ptr, &dmax); + if (code==TSDB_CONV_OK) { + code = tsdb_chars_to_smallint(buf.ptr, len+1-dmax, dst); + } + + buf_clean(&buf); + + return code; +} + +TSDB_CONV_CODE tsdb_wchars_to_int(iconv_t cnv, const unsigned char *src, size_t smax, int32_t *dst) { + if(cnv == (iconv_t)-1) return TSDB_CONV_GENERAL; + + size_t len = smax * 2; + buf_t buf; + buf_init(&buf, len+1); + if (!buf.ptr) return TSDB_CONV_OOM; + + size_t dmax = len + 1; + TSDB_CONV_CODE code = tsdb_iconv_conv(cnv, src, &smax, (unsigned char*)buf.ptr, &dmax); + if (code==TSDB_CONV_OK) { + code = tsdb_chars_to_int(buf.ptr, len+1-dmax, dst); } - size_t n = wchars_to_chars2((const SQLWCHAR*)src, slen, (SQLCHAR*)p, plen); - - TSDB_CONV_CODE code = TSDB_CONV_OK; - do { - if (n<0) { - code = TSDB_CONV_CHAR_NOT_NUM; - break; - } - if (n>=plen) { - code = TSDB_CONV_CHAR_NOT_NUM; - break; - } - - p[n] = '\0'; - code = tsdb_chars_to_bit(todb, p, dst); - } while (0); - - if (p!=buf) { - free(p); + buf_clean(&buf); + + return code; +} + +TSDB_CONV_CODE tsdb_wchars_to_bigint(iconv_t cnv, const unsigned char *src, size_t smax, int64_t *dst) { + if(cnv == (iconv_t)-1) return TSDB_CONV_GENERAL; + + size_t len = smax * 2; + buf_t buf; + buf_init(&buf, len+1); + if (!buf.ptr) return TSDB_CONV_OOM; + + size_t dmax = len + 1; + TSDB_CONV_CODE code = tsdb_iconv_conv(cnv, src, &smax, (unsigned char*)buf.ptr, &dmax); + if (code==TSDB_CONV_OK) { + code = tsdb_chars_to_bigint(buf.ptr, len+1-dmax, dst); } + buf_clean(&buf); + return code; } -TSDB_CONV_CODE tsdb_wchars_to_tinyint(int todb, const unsigned char *src, size_t slen, int8_t *dst) { - char buf[4096]; - char *p = buf; - size_t plen = sizeof(buf); - if (slen * 2 + 1 >= sizeof(buf)) { - plen = slen * 2 + 1; - p = (char*)malloc(plen); - if (!p) return TSDB_CONV_OOM; +TSDB_CONV_CODE tsdb_wchars_to_ts(iconv_t cnv, const unsigned char *src, size_t smax, int64_t *dst) { + return tsdb_wchars_to_bigint(cnv, src, smax, dst); +} + +TSDB_CONV_CODE tsdb_wchars_to_float(iconv_t cnv, const unsigned char *src, size_t smax, float *dst) { + if(cnv == (iconv_t)-1) return TSDB_CONV_GENERAL; + + size_t len = smax * 2; + buf_t buf; + buf_init(&buf, len+1); + if (!buf.ptr) return TSDB_CONV_OOM; + + size_t dmax = len + 1; + TSDB_CONV_CODE code = tsdb_iconv_conv(cnv, src, &smax, (unsigned char*)buf.ptr, &dmax); + if (code==TSDB_CONV_OK) { + code = tsdb_chars_to_float(buf.ptr, len+1-dmax, dst); } - size_t n = wchars_to_chars2((const SQLWCHAR*)src, slen, (SQLCHAR*)p, plen); - TSDB_CONV_CODE code = TSDB_CONV_OK; - do { - if (n<0) { - code = TSDB_CONV_CHAR_NOT_NUM; - break; - } - if (n>=sizeof(buf)) { - code = TSDB_CONV_CHAR_NOT_NUM; - break; - } - - buf[n] = '\0'; - code = tsdb_chars_to_tinyint(todb, buf, dst); - } while (0); - - if (p!=buf) { - free(p); + buf_clean(&buf); + + return code; +} + +TSDB_CONV_CODE tsdb_wchars_to_double(iconv_t cnv, const unsigned char *src, size_t smax, double *dst) { + if(cnv == (iconv_t)-1) return TSDB_CONV_GENERAL; + + size_t len = smax * 2; + buf_t buf; + buf_init(&buf, len+1); + if (!buf.ptr) return TSDB_CONV_OOM; + + size_t dmax = len + 1; + TSDB_CONV_CODE code = tsdb_iconv_conv(cnv, src, &smax, (unsigned char*)buf.ptr, &dmax); + if (code==TSDB_CONV_OK) { + code = tsdb_chars_to_double(buf.ptr, len+1-dmax, dst); } + buf_clean(&buf); + return code; } +TSDB_CONV_CODE tsdb_wchars_to_char(iconv_t cnv, const unsigned char *src, size_t smax, char *dst, size_t dmax) { + return tsdb_iconv_conv(cnv, src, &smax, (unsigned char*)dst, &dmax); +} diff --git a/src/connector/odbc/src/todbc_conv.h b/src/connector/odbc/src/todbc_conv.h index 3ff7e24de2..8a247818f1 100644 --- a/src/connector/odbc/src/todbc_conv.h +++ b/src/connector/odbc/src/todbc_conv.h @@ -17,8 +17,12 @@ #define _todbc_conv_h_ #include +#include #include +#include "iconv.h" + + typedef enum { TSDB_CONV_OK = 0, TSDB_CONV_OOM, @@ -26,44 +30,53 @@ typedef enum { TSDB_CONV_TRUNC_FRACTION, TSDB_CONV_TRUNC, TSDB_CONV_CHAR_NOT_NUM, + TSDB_CONV_GENERAL, + TSDB_CONV_BAD_CHAR, } TSDB_CONV_CODE; -TSDB_CONV_CODE tsdb_int64_to_bit(int todb, int64_t src, int8_t *dst); -TSDB_CONV_CODE tsdb_int64_to_tinyint(int todb, int64_t src, int8_t *dst); -TSDB_CONV_CODE tsdb_int64_to_smallint(int todb, int64_t src, int16_t *dst); -TSDB_CONV_CODE tsdb_int64_to_int(int todb, int64_t src, int32_t *dst); -TSDB_CONV_CODE tsdb_int64_to_bigint(int todb, int64_t src, int64_t *dst); -TSDB_CONV_CODE tsdb_int64_to_ts(int todb, int64_t src, int64_t *dst); -TSDB_CONV_CODE tsdb_int64_to_float(int todb, int64_t src, float *dst); -TSDB_CONV_CODE tsdb_int64_to_double(int todb, int64_t src, double *dst); -TSDB_CONV_CODE tsdb_int64_to_char(int todb, int64_t src, char *dst, size_t dlen); +TSDB_CONV_CODE tsdb_iconv_conv(iconv_t cnv, const unsigned char *src, size_t *slen, unsigned char *dst, size_t *dlen); + + + +TSDB_CONV_CODE tsdb_int64_to_bit(int64_t src, int8_t *dst); +TSDB_CONV_CODE tsdb_int64_to_tinyint(int64_t src, int8_t *dst); +TSDB_CONV_CODE tsdb_int64_to_smallint(int64_t src, int16_t *dst); +TSDB_CONV_CODE tsdb_int64_to_int(int64_t src, int32_t *dst); +TSDB_CONV_CODE tsdb_int64_to_bigint(int64_t src, int64_t *dst); +TSDB_CONV_CODE tsdb_int64_to_ts(int64_t src, int64_t *dst); +TSDB_CONV_CODE tsdb_int64_to_float(int64_t src, float *dst); +TSDB_CONV_CODE tsdb_int64_to_double(int64_t src, double *dst); +TSDB_CONV_CODE tsdb_int64_to_char(int64_t src, char *dst, size_t dlen); + +TSDB_CONV_CODE tsdb_double_to_bit(double src, int8_t *dst); +TSDB_CONV_CODE tsdb_double_to_tinyint(double src, int8_t *dst); +TSDB_CONV_CODE tsdb_double_to_smallint(double src, int16_t *dst); +TSDB_CONV_CODE tsdb_double_to_int(double src, int32_t *dst); +TSDB_CONV_CODE tsdb_double_to_bigint(double src, int64_t *dst); +TSDB_CONV_CODE tsdb_double_to_ts(double src, int64_t *dst); +TSDB_CONV_CODE tsdb_double_to_char(double src, char *dst, size_t dlen); -TSDB_CONV_CODE tsdb_double_to_bit(int todb, double src, int8_t *dst); -TSDB_CONV_CODE tsdb_double_to_tinyint(int todb, double src, int8_t *dst); -TSDB_CONV_CODE tsdb_double_to_smallint(int todb, double src, int16_t *dst); -TSDB_CONV_CODE tsdb_double_to_int(int todb, double src, int32_t *dst); -TSDB_CONV_CODE tsdb_double_to_bigint(int todb, double src, int64_t *dst); -TSDB_CONV_CODE tsdb_double_to_ts(int todb, double src, int64_t *dst); +TSDB_CONV_CODE tsdb_timestamp_to_char(SQL_TIMESTAMP_STRUCT src, char *dst, size_t dlen); -TSDB_CONV_CODE tsdb_chars_to_bit(int todb, const char *src, int8_t *dst); -TSDB_CONV_CODE tsdb_chars_to_tinyint(int todb, const char *src, int8_t *dst); -TSDB_CONV_CODE tsdb_chars_to_smallint(int todb, const char *src, int16_t *dst); -TSDB_CONV_CODE tsdb_chars_to_int(int todb, const char *src, int32_t *dst); -TSDB_CONV_CODE tsdb_chars_to_bigint(int todb, const char *src, int64_t *dst); -TSDB_CONV_CODE tsdb_chars_to_ts(int todb, const char *src, int64_t *dst); -TSDB_CONV_CODE tsdb_chars_to_float(int todb, const char *src, float *dst); -TSDB_CONV_CODE tsdb_chars_to_double(int todb, const char *src, double *dst); -TSDB_CONV_CODE tsdb_chars_to_char(int todb, const char *src, char *dst, size_t dlen); +TSDB_CONV_CODE tsdb_chars_to_bit(const char *src, size_t smax, int8_t *dst); +TSDB_CONV_CODE tsdb_chars_to_tinyint(const char *src, size_t smax, int8_t *dst); +TSDB_CONV_CODE tsdb_chars_to_smallint(const char *src, size_t smax, int16_t *dst); +TSDB_CONV_CODE tsdb_chars_to_int(const char *src, size_t smax, int32_t *dst); +TSDB_CONV_CODE tsdb_chars_to_bigint(const char *src, size_t smax, int64_t *dst); +TSDB_CONV_CODE tsdb_chars_to_ts(const char *src, size_t smax, int64_t *dst); +TSDB_CONV_CODE tsdb_chars_to_float(const char *src, size_t smax, float *dst); +TSDB_CONV_CODE tsdb_chars_to_double(const char *src, size_t smax, double *dst); +TSDB_CONV_CODE tsdb_chars_to_char(const char *src, size_t smax, char *dst, size_t dmax); -TSDB_CONV_CODE tsdb_wchars_to_bit(int todb, const unsigned char *src, size_t slen, int8_t *dst); -TSDB_CONV_CODE tsdb_wchars_to_tinyint(int todb, const unsigned char *src, size_t slen, int8_t *dst); -TSDB_CONV_CODE tsdb_wchars_to_smallint(int todb, const unsigned char *src, size_t slen, int16_t *dst); -TSDB_CONV_CODE tsdb_wchars_to_int(int todb, const unsigned char *src, size_t slen, int32_t *dst); -TSDB_CONV_CODE tsdb_wchars_to_bigint(int todb, const unsigned char *src, size_t slen, int64_t *dst); -TSDB_CONV_CODE tsdb_wchars_to_ts(int todb, const unsigned char *src, size_t slen, int64_t *dst); -TSDB_CONV_CODE tsdb_wchars_to_float(int todb, const unsigned char *src, size_t slen, float *dst); -TSDB_CONV_CODE tsdb_wchars_to_double(int todb, const unsigned char *src, size_t slen, double *dst); -TSDB_CONV_CODE tsdb_wchars_to_char(int todb, const unsigned char *src, size_t slen, char *dst, size_t dlen); +TSDB_CONV_CODE tsdb_wchars_to_bit(iconv_t cnv, const unsigned char *src, size_t smax, int8_t *dst); +TSDB_CONV_CODE tsdb_wchars_to_tinyint(iconv_t cnv, const unsigned char *src, size_t smax, int8_t *dst); +TSDB_CONV_CODE tsdb_wchars_to_smallint(iconv_t cnv, const unsigned char *src, size_t smax, int16_t *dst); +TSDB_CONV_CODE tsdb_wchars_to_int(iconv_t cnv, const unsigned char *src, size_t smax, int32_t *dst); +TSDB_CONV_CODE tsdb_wchars_to_bigint(iconv_t cnv, const unsigned char *src, size_t smax, int64_t *dst); +TSDB_CONV_CODE tsdb_wchars_to_ts(iconv_t cnv, const unsigned char *src, size_t smax, int64_t *dst); +TSDB_CONV_CODE tsdb_wchars_to_float(iconv_t cnv, const unsigned char *src, size_t smax, float *dst); +TSDB_CONV_CODE tsdb_wchars_to_double(iconv_t cnv, const unsigned char *src, size_t smax, double *dst); +TSDB_CONV_CODE tsdb_wchars_to_char(iconv_t cnv, const unsigned char *src, size_t smax, char *dst, size_t dmax); #endif // _todbc_conv_h_ diff --git a/src/connector/odbc/src/todbc_util.h b/src/connector/odbc/src/todbc_util.h index b3c307b85f..53a1300f86 100644 --- a/src/connector/odbc/src/todbc_util.h +++ b/src/connector/odbc/src/todbc_util.h @@ -42,8 +42,6 @@ do { \ abort(); \ } while (0) - - const char* sql_sql_type(int type); const char* sql_c_type(int type); diff --git a/src/connector/odbc/tests/odbc.py b/src/connector/odbc/tests/odbc.py index 5218957fb9..207523e521 100644 --- a/src/connector/odbc/tests/odbc.py +++ b/src/connector/odbc/tests/odbc.py @@ -119,10 +119,10 @@ while row: cursor.close() cursor = cnxn.cursor() -cursor.execute("create table db.f (ts timestamp, v1 bool)") +cursor.execute("create table db.f (ts timestamp, v1 float)") cursor.close() -params = [ ('2020-10-20 00:00:00', 'acb') ] +params = [ ('2020-10-20 00:00:10', '123.3') ] cursor = cnxn.cursor() cursor.fast_executemany = True cursor.executemany("insert into db.f values (?, ?)", params) -- GitLab