From a6fee49f0fbe24e53201fe92b1d37a596896d870 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Thu, 26 Aug 2021 11:43:42 +0800 Subject: [PATCH] [TD-6167] support unsigned type in stmt --- src/client/src/tscPrepare.c | 2 +- src/client/src/tscUtil.c | 15 +++++++++++++++ src/util/inc/tstrbuild.h | 1 + src/util/src/tstrbuild.c | 6 ++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 099ee77bc5..36dd60c4fe 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -289,7 +289,7 @@ static char* normalStmtBuildSql(STscStmt* stmt) { case TSDB_DATA_TYPE_USMALLINT: case TSDB_DATA_TYPE_UINT: case TSDB_DATA_TYPE_UBIGINT: - taosStringBuilderAppendInteger(&sb, var->u64); // maybe overflow if u64 is too big + taosStringBuilderAppendUnsignedInteger(&sb, var->u64); break; case TSDB_DATA_TYPE_FLOAT: diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 2be11a406a..ff4d0e43e6 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -60,6 +60,21 @@ int32_t converToStr(char *str, int type, void *buf, int32_t bufSize, int32_t *le case TSDB_DATA_TYPE_TIMESTAMP: n = sprintf(str, "%" PRId64, *(int64_t*)buf); break; + case TSDB_DATA_TYPE_UTINYINT: + n = sprintf(str, "%d", *(uint8_t*)buf); + break; + + case TSDB_DATA_TYPE_USMALLINT: + n = sprintf(str, "%d", *(uint16_t*)buf); + break; + + case TSDB_DATA_TYPE_UINT: + n = sprintf(str, "%d", *(uint32_t*)buf); + break; + + case TSDB_DATA_TYPE_UBIGINT: + n = sprintf(str, "%" PRId64, *(uint64_t*)buf); + break; case TSDB_DATA_TYPE_FLOAT: n = sprintf(str, "%f", GET_FLOAT_VAL(buf)); diff --git a/src/util/inc/tstrbuild.h b/src/util/inc/tstrbuild.h index 68d1914be3..1bfa077e80 100644 --- a/src/util/inc/tstrbuild.h +++ b/src/util/inc/tstrbuild.h @@ -43,6 +43,7 @@ void taosStringBuilderAppendStringLen(SStringBuilder* sb, const char* str, size_ void taosStringBuilderAppendString(SStringBuilder* sb, const char* str); void taosStringBuilderAppendNull(SStringBuilder* sb); void taosStringBuilderAppendInteger(SStringBuilder* sb, int64_t v); +void taosStringBuilderAppendUnsignedInteger(SStringBuilder* sb, uint64_t v) void taosStringBuilderAppendDouble(SStringBuilder* sb, double v); #ifdef __cplusplus diff --git a/src/util/src/tstrbuild.c b/src/util/src/tstrbuild.c index eec21d1835..e3d3159535 100644 --- a/src/util/src/tstrbuild.c +++ b/src/util/src/tstrbuild.c @@ -73,6 +73,12 @@ void taosStringBuilderAppendInteger(SStringBuilder* sb, int64_t v) { taosStringBuilderAppendStringLen(sb, buf, MIN(len, sizeof(buf))); } +void taosStringBuilderAppendUnsignedInteger(SStringBuilder* sb, uint64_t v) { + char buf[64]; + size_t len = snprintf(buf, sizeof(buf), "%" PRId64, v); + taosStringBuilderAppendStringLen(sb, buf, MIN(len, sizeof(buf))); +} + void taosStringBuilderAppendDouble(SStringBuilder* sb, double v) { char buf[512]; size_t len = snprintf(buf, sizeof(buf), "%.9lf", v); -- GitLab