diff --git a/include/os/osSocket.h b/include/os/osSocket.h index ef5b700784..5d95ff308c 100644 --- a/include/os/osSocket.h +++ b/include/os/osSocket.h @@ -27,6 +27,7 @@ #define epoll_ctl EPOLL_CTL_FUNC_TAOS_FORBID #define epoll_wait EPOLL_WAIT_FUNC_TAOS_FORBID #define inet_ntoa INET_NTOA_FUNC_TAOS_FORBID +#define inet_addr INET_ADDR_FUNC_TAOS_FORBID #endif #if defined(WINDOWS) @@ -54,7 +55,6 @@ #define __BIG_ENDIAN BIG_ENDIAN #define __LITTLE_ENDIAN LITTLE_ENDIAN #define __PDP_ENDIAN PDP_ENDIAN -#include #else #include #include @@ -162,9 +162,10 @@ int32_t taosGetSocketName(TdSocketPtr pSocket, struct sockaddr *destAddr, int *a int32_t taosBlockSIGPIPE(); int32_t taosGetIpv4FromFqdn(const char *fqdn, uint32_t *ip); int32_t taosGetFqdn(char *); -void tinet_ntoa(char *ipstr, uint32_t ip); +void taosInetNtoa(char *ipstr, uint32_t ip); +uint32_t taosInetAddr(const char *ipstr); int32_t taosIgnSIGPIPE(); -const char *taosInetNtoa(struct in_addr ipInt, char *dstStr, int32_t len); +const char *taosInetNtop(struct in_addr ipInt, char *dstStr, int32_t len); uint64_t taosHton64(uint64_t val); uint64_t taosNtoh64(uint64_t val); diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 26bef9301e..0bc82d691a 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -2306,7 +2306,8 @@ static int32_t doConvertJson(SReqResultInfo* pResultInfo) { int32_t length = taosUcs4ToMbs((TdUcs4*)varDataVal(jsonInnerData), varDataLen(jsonInnerData), varDataVal(dst) + CHAR_BYTES, pResultInfo->charsetCxt); if (length <= 0) { - tscError("charset:%s to %s. convert failed.", DEFAULT_UNICODE_ENCODEC, tsCharset); + tscError("charset:%s to %s. convert failed.", DEFAULT_UNICODE_ENCODEC, + pResultInfo->charsetCxt != NULL ? ((SConvInfo *)(pResultInfo->charsetCxt))->charset : tsCharset); length = 0; } varDataSetLen(dst, length + CHAR_BYTES * 2); diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 13cf39f924..ca9bd4b2ee 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -203,7 +203,7 @@ static int32_t setConnectionOption(TAOS *taos, TSDB_OPTION_CONNECTION option, co if (option == TSDB_OPTION_CONNECTION_USER_IP || option == TSDB_OPTION_CONNECTION_CLEAR) { if (val != NULL) { - pObj->optionInfo.userIp = inet_addr(val); + pObj->optionInfo.userIp = taosInetAddr(val); if (pObj->optionInfo.userIp == INADDR_NONE){ code = TSDB_CODE_INVALID_PARA; goto END; diff --git a/source/client/test/CMakeLists.txt b/source/client/test/CMakeLists.txt index f869bedef6..210cacc301 100644 --- a/source/client/test/CMakeLists.txt +++ b/source/client/test/CMakeLists.txt @@ -11,9 +11,9 @@ TARGET_LINK_LIBRARIES( os util common transport parser catalog scheduler gtest ${TAOS_LIB_STATIC} qcom executor function ) -ADD_EXECUTABLE(timezoneTest timezoneTest.cpp) +ADD_EXECUTABLE(connectOptionsTest connectOptionsTest.cpp) TARGET_LINK_LIBRARIES( - timezoneTest + connectOptionsTest os util common transport parser catalog scheduler gtest ${TAOS_LIB_STATIC} qcom executor function ) @@ -48,7 +48,7 @@ TARGET_INCLUDE_DIRECTORIES( ) TARGET_INCLUDE_DIRECTORIES( - timezoneTest + connectOptionsTest PUBLIC "${TD_SOURCE_DIR}/include/client/" PRIVATE "${TD_SOURCE_DIR}/source/client/inc" ) @@ -94,6 +94,6 @@ add_test( ) add_test( - NAME timezoneTest - COMMAND timezoneTest + NAME connectOptionsTest + COMMAND connectOptionsTest ) diff --git a/source/client/test/timezoneTest.cpp b/source/client/test/connectOptionsTest.cpp similarity index 89% rename from source/client/test/timezoneTest.cpp rename to source/client/test/connectOptionsTest.cpp index 382b28e275..3e3b8d33df 100644 --- a/source/client/test/timezoneTest.cpp +++ b/source/client/test/connectOptionsTest.cpp @@ -116,7 +116,7 @@ void check_sql_result(TAOS* pConn, const char *sql, const char* result){ ASSERT(taos_errno(pRes) == 0); TAOS_ROW row = NULL; while ((row = taos_fetch_row(pRes)) != NULL) { - ASSERT (strcmp((const char*)row[0], result) == 0); + ASSERT (memcmp((const char*)row[0], result, strlen(result)) == 0); } taos_free_result(pRes); } @@ -195,11 +195,11 @@ void check_set_timezone(TAOS* optionFunc(const char *tz)){ STscObj* pObj = acquireTscObj(*(int64_t*)taos); \ ASSERT(pObj != nullptr); \ char ip[TD_IP_LEN] = {0}; \ - tinet_ntoa(ip, pObj->optionInfo.option); \ + taosInetNtoa(ip, pObj->optionInfo.option); \ ASSERT(strcmp(ip, val) == 0); \ } -TEST(timezoneCase, setConnectionOption_Test) { +TEST(connectionCase, setConnectionOption_Test) { int32_t code = taos_options_connection(NULL, TSDB_OPTION_CONNECTION_CHARSET, NULL); ASSERT(code != 0); TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); @@ -223,6 +223,7 @@ TEST(timezoneCase, setConnectionOption_Test) { ASSERT(code == 0); CHECK_TAOS_OPTION_POINTER(pConn, charsetCxt, false); +#ifndef WINDOWS // test timezone code = taos_options_connection(pConn, TSDB_OPTION_CONNECTION_TIMEZONE, ""); ASSERT(code == 0); @@ -248,6 +249,7 @@ TEST(timezoneCase, setConnectionOption_Test) { ASSERT(code == 0); CHECK_TAOS_OPTION_POINTER(pConn, timezone, false); check_sql_result(pConn, "select timezone()", "adbc (UTC, +0000)"); +#endif // test user APP code = taos_options_connection(pConn, TSDB_OPTION_CONNECTION_USER_APP, ""); @@ -309,14 +311,99 @@ TEST(timezoneCase, setConnectionOption_Test) { code = taos_options_connection(pConn, TSDB_OPTION_CONNECTION_CLEAR, "192.168.0.2"); ASSERT(code == 0); CHECK_TAOS_OPTION_POINTER(pConn, charsetCxt, true); + +#ifndef WINDOWS CHECK_TAOS_OPTION_POINTER(pConn, timezone, true); check_sql_result(pConn, "select timezone()", "Asia/Shanghai (CST, +0800)"); +#endif + CHECK_TAOS_OPTION_APP(pConn, userApp, ""); CHECK_TAOS_OPTION_IP_ERROR(pConn, userIp, INADDR_NONE); taos_close(pConn); } +TEST(charsetCase, charset_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + ASSERT(pConn != nullptr); + + TAOS* pConnUTF8 = taos_connect("localhost", "root", "taosdata", NULL, 0); + ASSERT(pConnUTF8 != nullptr); + + TAOS* pConnDefault = taos_connect("localhost", "root", "taosdata", NULL, 0); + ASSERT(pConnDefault != nullptr); + + int32_t code = taos_options_connection(pConn, TSDB_OPTION_CONNECTION_CHARSET, "gbk"); + ASSERT(code == 0); + CHECK_TAOS_OPTION_POINTER(pConn, charsetCxt, false); + + code = taos_options_connection(pConnUTF8, TSDB_OPTION_CONNECTION_CHARSET, "UTF-8"); + ASSERT(code == 0); + CHECK_TAOS_OPTION_POINTER(pConnUTF8, charsetCxt, false); + + execQuery(pConn, "drop database if exists db1"); + execQuery(pConn, "create database db1"); + execQuery(pConn, "create table db1.stb (ts timestamp, c1 nchar(32), c2 int) tags(t1 timestamp, t2 nchar(32), t3 int)"); + execQueryFail(pConn, "create table db1.ctb1 using db1.stb tags('2023-09-16 17:00:00+05:00', '芬', 1)"); + + // 芬 gbk encode is 0xB7D2, the file charset is UTF-8 + char sqlTag[256] = {0}; + snprintf(sqlTag, sizeof(sqlTag), "create table db1.ctb1 using db1.stb tags('2023-09-16 17:00:00+05:00', '%c%c', 1)", 0xB7, 0xD2); + execQuery(pConn, sqlTag); + + // 中国 gbk encode is 0xD6D0B9FA + execQueryFail(pConn, "insert into db1.ctb1 values(1732178775133, '中国', 1)"); + char sqlCol[256] = {0}; + snprintf(sqlCol, sizeof(sqlCol), "insert into db1.ctb1 values(1732178775133, '%c%c%c%c', 1)", 0xD6, 0xD0, 0xB9, 0xFA); + execQuery(pConn, sqlCol); + + char resTag[8] = {0}; + snprintf(resTag, sizeof(resTag), "%c%c", 0xB7, 0xD2); + check_sql_result(pConn, "select t2 from db1.ctb1", resTag); + + char resCol[8] = {0}; + snprintf(resCol, sizeof(resCol), "%c%c%c%c", 0xD6, 0xD0, 0xB9, 0xFA); + check_sql_result(pConn, "select c1 from db1.ctb1", resCol); + + + check_sql_result(pConnUTF8, "select t2 from db1.ctb1", "芬"); + check_sql_result(pConnUTF8, "select c1 from db1.ctb1", "中国"); + + + execQuery(pConnDefault, "insert into db1.ctb1 values(1732178775134, '中国', 1)"); + check_sql_result(pConnDefault, "select c1 from db1.ctb1 where ts = 1732178775134", "中国"); + + execQuery(pConnUTF8, "create table db1.jsta (ts timestamp, c1 nchar(32), c2 int) tags(t1 json)"); + execQuery(pConnUTF8, "create table db1.jsta1 using db1.jsta tags('{\"k\":\"芬\"}')"); + execQuery(pConnUTF8, "insert into db1.jsta1 values(1732178775133, '中国', 1)"); + char resJsonTag[32] = {0}; + snprintf(resJsonTag, sizeof(resJsonTag), "{\"k\":\"%c%c\"}", 0xB7, 0xD2); + check_sql_result(pConn, "select t1 from db1.jsta1", resJsonTag); + + //reset charset to default(utf-8 + code = taos_options_connection(pConn, TSDB_OPTION_CONNECTION_CHARSET, NULL); + ASSERT(code == 0); + CHECK_TAOS_OPTION_POINTER(pConn, charsetCxt, true); + check_sql_result(pConn, "select t2 from db1.ctb1 where ts = 1732178775134", "芬"); + check_sql_result(pConn, "select c1 from db1.ctb1 where ts = 1732178775134", "中国"); + + + + taos_close(pConn); + taos_close(pConnUTF8); + taos_close(pConnDefault); + +} + +TEST(charsetCase, alter_charset_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + ASSERT(pConn != nullptr); + + execQueryFail(pConn, "alter dnode 1 'charset gbk'"); + execQueryFail(pConn, "local 'charset gbk'"); +} + +#ifndef WINDOWS TEST(timezoneCase, set_timezone_Test) { check_set_timezone(getConnWithGlobalOption); check_set_timezone(getConnWithOption); @@ -767,6 +854,6 @@ TEST(timezoneCase, localtime_performance_Test) { printf("average: localtime cost:%" PRId64 " ns, localtime_rz cost:%" PRId64 " ns", time_localtime/times, time_localtime_rz/times); tzfree(sp); } - +#endif #pragma GCC diagnostic pop diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index 338f71856a..9eefaf6a20 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -253,7 +253,7 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) { goto _OVER; } - tinet_ntoa(ip, pReq->info.conn.clientIp); + taosInetNtoa(ip, pReq->info.conn.clientIp); if ((code = mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CONNECT)) != 0) { mGError("user:%s, failed to login from %s since %s", pReq->info.conn.user, ip, tstrerror(code)); goto _OVER; @@ -907,7 +907,7 @@ static int32_t mndRetrieveConns(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl } char endpoint[TD_IP_LEN + 6 + VARSTR_HEADER_SIZE] = {0}; - tinet_ntoa(varDataVal(endpoint), pConn->ip); + taosInetNtoa(varDataVal(endpoint), pConn->ip); (void)sprintf(varDataVal(endpoint) + strlen(varDataVal(endpoint)), ":%d", pConn->port); varDataLen(endpoint) = strlen(varDataVal(endpoint)); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); @@ -942,7 +942,7 @@ static int32_t mndRetrieveConns(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl char userIp[TD_IP_LEN + 6 + VARSTR_HEADER_SIZE] = {0}; if (pConn->userIp != 0 && pConn->userIp != INADDR_NONE){ - tinet_ntoa(varDataVal(userIp), pConn->userIp); + taosInetNtoa(varDataVal(userIp), pConn->userIp); varDataLen(userIp) = strlen(varDataVal(userIp)); } pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); @@ -1039,7 +1039,7 @@ static int32_t packQueriesIntoBlock(SShowObj *pShow, SConnObj *pConn, SSDataBloc } char endpoint[TD_IP_LEN + 6 + VARSTR_HEADER_SIZE] = {0}; - tinet_ntoa(varDataVal(endpoint), pConn->ip); + taosInetNtoa(varDataVal(endpoint), pConn->ip); (void)sprintf(varDataVal(endpoint) + strlen(varDataVal(endpoint)), ":%d", pConn->port); varDataLen(endpoint) = strlen(&endpoint[VARSTR_HEADER_SIZE]); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); @@ -1136,7 +1136,7 @@ static int32_t packQueriesIntoBlock(SShowObj *pShow, SConnObj *pConn, SSDataBloc char userIp[TD_IP_LEN + 6 + VARSTR_HEADER_SIZE] = {0}; if (pConn->userIp != 0 && pConn->userIp != INADDR_NONE){ - tinet_ntoa(varDataVal(userIp), pConn->userIp); + taosInetNtoa(varDataVal(userIp), pConn->userIp); varDataLen(userIp) = strlen(varDataVal(userIp)); } pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); @@ -1222,7 +1222,7 @@ static int32_t mndRetrieveApps(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlo } char ip[TD_IP_LEN + VARSTR_HEADER_SIZE] = {0}; - tinet_ntoa(varDataVal(ip), pApp->ip); + taosInetNtoa(varDataVal(ip), pApp->ip); varDataLen(ip) = strlen(varDataVal(ip)); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); code = colDataSetVal(pColInfo, numOfRows, (const char *)ip, false); diff --git a/source/libs/parser/src/parInsertSql.c b/source/libs/parser/src/parInsertSql.c index a7d1351aa0..bb28cb3135 100644 --- a/source/libs/parser/src/parInsertSql.c +++ b/source/libs/parser/src/parInsertSql.c @@ -691,7 +691,7 @@ static int32_t parseTagToken(const char** end, SToken* pToken, SSchema* pSchema, return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name); } char buf[512] = {0}; - snprintf(buf, tListLen(buf), " taosMbsToUcs4 error:%s", strerror(terrno)); + snprintf(buf, tListLen(buf), " taosMbsToUcs4 error:%s %d %d", strerror(terrno), errno, EILSEQ); taosMemoryFree(p); return buildSyntaxErrMsg(pMsgBuf, buf, pToken->z); } diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index 07ea54c44f..6ebf767eed 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -472,7 +472,8 @@ int32_t parseJsontoTagData(const char* json, SArray* pTagVals, STag** ppTag, voi } val.type = TSDB_DATA_TYPE_NCHAR; if (valLen > 0 && !taosMbsToUcs4(jsonValue, valLen, (TdUcs4*)tmp, (int32_t)(valLen * TSDB_NCHAR_SIZE), &valLen, charsetCxt)) { - uError("charset:%s to %s. val:%s, errno:%s, convert failed.", DEFAULT_UNICODE_ENCODEC, tsCharset, jsonValue, + uError("charset:%s to %s. val:%s, errno:%s, convert failed.", DEFAULT_UNICODE_ENCODEC, + charsetCxt != NULL ? ((SConvInfo *)(charsetCxt))->charset : tsCharset, jsonValue, strerror(terrno)); retCode = buildSyntaxErrMsg(pMsgBuf, "charset convert json error", jsonValue); taosMemoryFree(tmp); diff --git a/source/libs/qcom/src/queryUtil.c b/source/libs/qcom/src/queryUtil.c index 9b59e321a3..22141c33ee 100644 --- a/source/libs/qcom/src/queryUtil.c +++ b/source/libs/qcom/src/queryUtil.c @@ -477,7 +477,8 @@ void parseTagDatatoJson(void* p, char** jsonStr, void *charsetCxt) { } int32_t length = taosUcs4ToMbs((TdUcs4*)pTagVal->pData, pTagVal->nData, tagJsonValue, charsetCxt); if (length < 0) { - qError("charset:%s to %s. val:%s convert json value failed.", DEFAULT_UNICODE_ENCODEC, tsCharset, + qError("charset:%s to %s. val:%s convert json value failed.", DEFAULT_UNICODE_ENCODEC, + charsetCxt != NULL ? ((SConvInfo *)(charsetCxt))->charset : tsCharset, pTagVal->pData); taosMemoryFree(tagJsonValue); goto end; diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index c46419213f..1f351b77c7 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -598,12 +598,13 @@ int32_t ncharTobinary(void *buf, void **out, void* charsetCxt) { // todo need t *out = taosMemoryCalloc(1, inputLen); if (NULL == *out) { sclError("charset:%s to %s. val:%s convert ncharTobinary failed, since memory alloc failed.", - DEFAULT_UNICODE_ENCODEC, tsCharset, (char *)varDataVal(buf)); + DEFAULT_UNICODE_ENCODEC, charsetCxt != NULL ? ((SConvInfo *)(charsetCxt))->charset : tsCharset, (char *)varDataVal(buf)); SCL_ERR_RET(terrno); } int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(buf), varDataLen(buf), varDataVal(*out), charsetCxt); if (len < 0) { - sclError("charset:%s to %s. val:%s convert ncharTobinary failed.", DEFAULT_UNICODE_ENCODEC, tsCharset, + sclError("charset:%s to %s. val:%s convert ncharTobinary failed.", DEFAULT_UNICODE_ENCODEC, + charsetCxt != NULL ? ((SConvInfo *)(charsetCxt))->charset : tsCharset, (char *)varDataVal(buf)); taosMemoryFree(*out); SCL_ERR_RET(TSDB_CODE_SCALAR_CONVERT_ERROR); diff --git a/source/libs/sync/src/syncUtil.c b/source/libs/sync/src/syncUtil.c index 65c7f9761e..0fedd96e4c 100644 --- a/source/libs/sync/src/syncUtil.c +++ b/source/libs/sync/src/syncUtil.c @@ -62,7 +62,7 @@ bool syncUtilNodeInfo2RaftId(const SNodeInfo* pInfo, SyncGroupId vgId, SRaftId* } char ipbuf[TD_IP_LEN] = {0}; - tinet_ntoa(ipbuf, ipv4); + taosInetNtoa(ipbuf, ipv4); raftId->addr = SYNC_ADDR(pInfo); raftId->vgId = vgId; diff --git a/source/libs/sync/test/sync_test_lib/src/syncIO.c b/source/libs/sync/test/sync_test_lib/src/syncIO.c index f5a32b98d9..088a82a009 100644 --- a/source/libs/sync/test/sync_test_lib/src/syncIO.c +++ b/source/libs/sync/test/sync_test_lib/src/syncIO.c @@ -520,7 +520,7 @@ void syncUtilU642Addr(uint64_t u64, char *host, int64_t len, uint16_t *port) { uint32_t hostU32 = (uint32_t)((u64 >> 32) & 0x00000000FFFFFFFF); struct in_addr addr = {.s_addr = hostU32}; - taosInetNtoa(addr, host, len); + taosInetNtop(addr, host, len); *port = (uint16_t)((u64 & 0x00000000FFFF0000) >> 16); } diff --git a/source/libs/transport/src/thttp.c b/source/libs/transport/src/thttp.c index bdcbfeb1cd..0c0f723b8b 100644 --- a/source/libs/transport/src/thttp.c +++ b/source/libs/transport/src/thttp.c @@ -224,7 +224,7 @@ static FORCE_INLINE int32_t taosBuildDstAddr(const char* server, uint16_t port, return TSDB_CODE_RPC_FQDN_ERROR; } char buf[TD_IP_LEN] = {0}; - tinet_ntoa(buf, ip); + taosInetNtoa(buf, ip); int ret = uv_ip4_addr(buf, port, dest); if (ret != 0) { tError("http-report failed to get addr, reason:%s", uv_err_name(ret)); diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 8377a1456d..dffda3c67c 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -1856,8 +1856,8 @@ static FORCE_INLINE int32_t cliUpdateFqdnCache(SHashObj* cache, char* fqdn) { if (v != NULL) { if (addr != *v) { char old[TSDB_FQDN_LEN] = {0}, new[TSDB_FQDN_LEN] = {0}; - tinet_ntoa(old, *v); - tinet_ntoa(new, addr); + taosInetNtoa(old, *v); + taosInetNtoa(new, addr); tWarn("update ip of fqdn:%s, old: %s, new: %s", fqdn, old, new); code = taosHashPut(cache, fqdn, len, &addr, sizeof(addr)); } diff --git a/source/os/src/osSocket.c b/source/os/src/osSocket.c index 0a24daef95..28072f334a 100644 --- a/source/os/src/osSocket.c +++ b/source/os/src/osSocket.c @@ -150,7 +150,7 @@ int32_t taosSetSockOpt(TdSocketPtr pSocket, int32_t level, int32_t optname, void #endif } -const char *taosInetNtoa(struct in_addr ipInt, char *dstStr, int32_t len) { +const char *taosInetNtop(struct in_addr ipInt, char *dstStr, int32_t len) { const char *r = inet_ntop(AF_INET, &ipInt, dstStr, len); if (NULL == r) { terrno = TAOS_SYSTEM_ERROR(errno); @@ -386,7 +386,7 @@ int32_t taosGetFqdn(char *fqdn) { return 0; } -void tinet_ntoa(char *ipstr, uint32_t ip) { +void taosInetNtoa(char *ipstr, uint32_t ip) { if (ipstr == NULL) { return; } @@ -394,6 +394,13 @@ void tinet_ntoa(char *ipstr, uint32_t ip) { (void)snprintf(ipstr, TD_IP_LEN, "%d.%d.%d.%d", bytes[0], bytes[1], bytes[2], bytes[3]); } +uint32_t taosInetAddr(const char *ipstr){ + if (ipstr == NULL) { + return 0; + } + return inet_addr(ipstr); +} + int32_t taosIgnSIGPIPE() { sighandler_t h = signal(SIGPIPE, SIG_IGN); if (SIG_ERR == h) { diff --git a/source/os/src/osString.c b/source/os/src/osString.c index d8109bab0c..1ae8ac2a28 100644 --- a/source/os/src/osString.c +++ b/source/os/src/osString.c @@ -326,6 +326,8 @@ bool taosMbsToUcs4(const char *mbs, size_t mbsLength, TdUcs4 *ucs4, int32_t ucs4 size_t ucs4_input_len = mbsLength; size_t outLeft = ucs4_max_len; if (iconv(conv, (char **)&mbs, &ucs4_input_len, (char **)&ucs4, &outLeft) == -1) { + char buf[512] = {0}; + snprintf(buf, tListLen(buf), " taosMbsToUcs4 error:%s %d %d", strerror(terrno), errno, EILSEQ); terrno = TAOS_SYSTEM_ERROR(errno); taosReleaseConv(idx, conv, M2C, charsetCxt); return false; diff --git a/tests/system-test/2-query/timezone.py b/tests/system-test/2-query/timezone.py index e08e85dcf5..dbb4d2187e 100644 --- a/tests/system-test/2-query/timezone.py +++ b/tests/system-test/2-query/timezone.py @@ -188,10 +188,20 @@ class TDTestCase: for i in range(rows): if tdSql.getData(i, 0) == "timezone" : if tdSql.getData(i, 1).find(timezone) == -1: - tdLog.exit("show timezone:%s != %s"%(tdSql.getData(i, 1),timezone)) + tdLog.exit("show timezone:%s != %s"%(tdSql.getData(i, 1), timezone)) + + def charset_check(self, sql, charset): + tdSql.query(sql) + rows = tdSql.getRows() + for i in range(rows): + if tdSql.getData(i, 0) == "charset" : + if tdSql.getData(i, 1).find(charset) == -1: + tdLog.exit("show charset:%s != %s"%(tdSql.getData(i, 1), charset)) def run(self): # sourcery skip: extract-duplicate-method timezone = self.get_system_timezone() # timezone = "Asia/Shanghai" + self.charset_check("show local variables", "UTF-8") + self.timezone_check("show dnode 1 variables", "UTF-8") self.timezone_check("show local variables", timezone) self.timezone_check("show dnode 1 variables", timezone) diff --git a/tests/system-test/2-query/timezone_conf.py b/tests/system-test/2-query/timezone_conf.py index 2a54114a6b..da45e2c5bd 100644 --- a/tests/system-test/2-query/timezone_conf.py +++ b/tests/system-test/2-query/timezone_conf.py @@ -6,23 +6,33 @@ from util.sqlset import * from util.cluster import * class TDTestCase: - updateCfgDict = {"clientCfg" : {'timezone': 'UTC'} , 'timezone': 'UTC-8'} - + updatecfgDict = {"clientCfg" : {'timezone': 'UTC', 'charset': 'gbk'}, 'timezone': 'UTC-8', 'charset': 'gbk'} def init(self, conn, logSql, replicaVar=1): self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) def timezone_check(self, timezone, sql): - tdSql.execute(sql) + tdSql.query(sql) rows = tdSql.getRows() for i in range(rows): if tdSql.getData(i, 0) == "timezone" : if tdSql.getData(i, 1).find(timezone) == -1: - tdLog.exit("show timezone:%s != %s"%(tdSql.getData(i, 1),timezone)) + tdLog.exit("show timezone:%s != %s"%(tdSql.getData(i, 1), timezone)) + + def charset_check(self, charset, sql): + tdSql.query(sql) + rows = tdSql.getRows() + for i in range(rows): + if tdSql.getData(i, 0) == "charset" : + if tdSql.getData(i, 1).find(charset) == -1: + tdLog.exit("show charset:%s != %s"%(tdSql.getData(i, 1), charset)) def run(self): + self.charset_check('gbk', "show local variables") + self.charset_check('gbk', "show dnode 1 variables") self.timezone_check('UTC', "show local variables") + # time.sleep(50) self.timezone_check('UTC-8', "show dnode 1 variables") def stop(self):