diff --git a/include/client/taos.h b/include/client/taos.h index a529cf8d15..7d82b258f3 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -65,22 +65,14 @@ typedef enum { } TSDB_OPTION; typedef enum { - TSDB_OPTION_CONNECTION_CLEAR = -1, // clear all option in this connection + TSDB_OPTION_CONNECTION_CLEAR = -1, // means clear all option in this connection TSDB_OPTION_CONNECTION_CHARSET, // charset, Same as the scope supported by the system TSDB_OPTION_CONNECTION_TIMEZONE, // timezone, Same as the scope supported by the system TSDB_OPTION_CONNECTION_USER_IP, // user ip - TSDB_OPTION_CONNECTION_USER_APP, // user app + TSDB_OPTION_CONNECTION_USER_APP, // user app, max lengthe is 23, truncated if longer than 23 TSDB_MAX_OPTIONS_CONNECTION } TSDB_OPTION_CONNECTION; -typedef enum { - TSDB_OPTION_CONNECT_CHARSET, - TSDB_OPTION_CONNECT_TIMEZONE, - TSDB_OPTION_CONNECT_IP, - TSDB_OPTION_CONNECT_APP_NAME, - TSDB_MAX_CONNECT_OPTIONS -} TSDB_OPTION_CONNECT; - typedef enum { TSDB_SML_UNKNOWN_PROTOCOL = 0, TSDB_SML_LINE_PROTOCOL = 1, @@ -189,9 +181,26 @@ typedef struct TAOS_STMT_OPTIONS { bool singleTableBindOnce; } TAOS_STMT_OPTIONS; + +/* + description: + taos_options_connection use to set extra connect options and affect behavior for a connection. + This function may be called multiple times to set several options. + Call taos_options_connection() after taos_connect() or taos_connect_auth(). + The option argument is the option that you want to set; the arg argument is the value for the option. + If you want to reset the option, set arg to NULL. + input: + taos: returned by taos_connect + option: option name + arg: option value(string) + output: + 0: success + others: fail, error msg can be got by taos_errstr(NULL) +*/ +DLL_EXPORT int taos_options_connection(TAOS *taos, TSDB_OPTION_CONNECTION option, const void *arg, ...); + DLL_EXPORT void taos_cleanup(void); DLL_EXPORT int taos_options(TSDB_OPTION option, const void *arg, ...); -DLL_EXPORT int taos_options_connection(TAOS *taos, TSDB_OPTION_CONNECTION option, const void *arg, ...); DLL_EXPORT setConfRet taos_set_config(const char *config); DLL_EXPORT int taos_init(void); DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port); diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 9af98898a6..626df01032 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -3420,7 +3420,6 @@ typedef struct { SAppHbReq app; SQueryHbReqBasic* query; SHashObj* info; // hash - char name[TSDB_APP_NAME_LEN]; char userApp[TSDB_APP_NAME_LEN]; uint32_t userIp; } SClientHbReq; diff --git a/include/util/tencode.h b/include/util/tencode.h index b66e79fa60..efe3883d16 100644 --- a/include/util/tencode.h +++ b/include/util/tencode.h @@ -413,7 +413,9 @@ static FORCE_INLINE int32_t tDecodeBinary(SDecoder* pCoder, uint8_t** val, uint3 static FORCE_INLINE int32_t tDecodeCStrAndLen(SDecoder* pCoder, char** val, uint32_t* len) { TAOS_CHECK_RETURN(tDecodeBinary(pCoder, (uint8_t**)val, len)); - (*len) -= 1; + if (*len > 0) { + (*len) -= 1; + } return 0; } @@ -427,7 +429,10 @@ static int32_t tDecodeCStrTo(SDecoder* pCoder, char* val) { uint32_t len; TAOS_CHECK_RETURN(tDecodeCStrAndLen(pCoder, &pStr, &len)); - TAOS_MEMCPY(val, pStr, len + 1); + if (pCoder->pos + 1 < pCoder->size) { + TAOS_MEMCPY(val, pStr, len + 1); + } + return 0; } diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index ca9bd4b2ee..65edf4058d 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -76,7 +76,6 @@ static timezone_t setConnnectionTz(const char* val){ if (pTimezoneMap == NULL){ pTimezoneMap = taosHashInit(0, MurmurHash3_32, false, HASH_ENTRY_LOCK); if (pTimezoneMap == NULL) { - atomic_store_32(&lock_c, 0); goto END; } taosHashSetFreeFp(pTimezoneMap, freeTz); @@ -85,7 +84,6 @@ static timezone_t setConnnectionTz(const char* val){ if (pTimezoneNameMap == NULL){ pTimezoneNameMap = taosHashInit(0, taosIntHash_64, false, HASH_ENTRY_LOCK); if (pTimezoneNameMap == NULL) { - atomic_store_32(&lock_c, 0); goto END; } } diff --git a/source/client/test/connectOptionsTest.cpp b/source/client/test/connectOptionsTest.cpp index 95129b5aac..bf4e402f28 100644 --- a/source/client/test/connectOptionsTest.cpp +++ b/source/client/test/connectOptionsTest.cpp @@ -474,6 +474,8 @@ TEST(charsetCase, alter_charset_Test) { execQueryFail(pConn, "alter dnode 1 'charset gbk'"); execQueryFail(pConn, "local 'charset gbk'"); + + taos_close(pConn); } #ifndef WINDOWS @@ -493,6 +495,8 @@ TEST(timezoneCase, alter_timezone_Test) { check_timezone(pConn, "show local variables", "Asia/Shanghai"); execQueryFail(pConn, "alter dnode 1 'timezone Asia/Kolkata'"); + + taos_close(pConn); } char *tz_test[] = { diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index 3fac8d2718..1da9a8f123 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -584,7 +584,7 @@ static bool isCharStart(char c) { static int32_t trimHelper(char *orgStr, char* remStr, int32_t orgLen, int32_t remLen, bool trimLeft, bool isNchar) { if (trimLeft) { int32_t pos = 0; - for (int32_t i = 0; i < orgLen; i += remLen) { + for (int32_t i = 0; i < orgLen - remLen; i += remLen) { if (memcmp(orgStr + i, remStr, remLen) == 0) { if (isCharStart(orgStr[i + remLen]) || isNchar) { pos = i + remLen;