diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index d352567b01..130c4f54cd 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -78,7 +78,15 @@ static void concatStrings(SArray *list, char* buf, int size){ int len = 0; for(int i = 0; i < taosArrayGetSize(list); i++){ char* db = taosArrayGet(list, i); - int ret = snprintf(buf, size - len, "%s,", db); + char* dot = strchr(db, '.'); + if (dot != NULL) { + db = dot + 1; + } + if (i != 0){ + strcat(buf, ","); + len += 1; + } + int ret = snprintf(buf + len, size - len, "%s,", db); if (ret < 0) { tscError("snprintf failed, buf:%s, ret:%d", buf, ret); break; @@ -139,7 +147,7 @@ static void generateWriteSlowLog(STscObj *pTscObj, SRequestObj *pRequest, int32_ cJSON_AddItemToObject(json, "process_id", cJSON_CreateString(pid)); char dbList[1024] = {0}; - concatStrings(pRequest->dbList, dbList, sizeof(dbList)); + concatStrings(pRequest->dbList, dbList, sizeof(dbList) - 1); cJSON_AddItemToObject(json, "db", cJSON_CreateString(dbList)); MonitorSlowLogData* slowLogData = taosAllocateQitem(sizeof(MonitorSlowLogData), DEF_QITEM, 0); diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index c13b95afdd..611891e298 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -1539,4 +1539,38 @@ TEST(clientCase, sub_tb_mt_test) { } } +//static void concatStrings(SArray *list, char* buf, int size){ +// int len = 0; +// for(int i = 0; i < taosArrayGetSize(list); i++){ +// char* db = (char*)taosArrayGet(list, i); +// char* dot = strchr(db, '.'); +// if (dot != NULL) { +// db = dot + 1; +// } +// if (i != 0){ +// strcat(buf, ","); +// len += 1; +// } +// int ret = snprintf(buf + len, size - len, "%s", db); +// if (ret < 0) { +// printf("snprintf failed, buf:%s, ret:%d", buf, ret); +// break; +// } +// len += ret; +// if (len >= size){ +// printf("dbList is truncated, buf:%s, len:%d", buf, len); +// break; +// } +// } +//} +// +//TEST(clientCase, concat_string_test) { +// SArray* list = taosArrayInit(10, TSDB_DB_FNAME_LEN); +// taosArrayPush(list, "1.db1"); +// taosArrayPush(list, "2.db2"); +// +// char buf[32] = {0}; +// concatStrings(list, buf, sizeof(buf) - 1); +//} + #pragma GCC diagnostic pop