diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index 054b2894c5cff77b63f57b16b069aaf60e150ecc..9657912716fe019b8d92abd4fc4232cf3a133301 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -468,7 +468,6 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo); extern void * pVnodeConn; extern void * pTscMgmtConn; extern void * tscCacheHandle; -extern int32_t globalCode; extern int slaveIndex; extern void * tscTmr; extern void * tscQhandle; diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c index 99104ed68cae4526ba2ef6b1c9a4c52c56885e4d..36cd42332b0d84b09798138080da33a856f26a21 100644 --- a/src/client/src/tscAsync.c +++ b/src/client/src/tscAsync.c @@ -200,7 +200,6 @@ void taos_fetch_rows_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, int), voi SSqlObj *pSql = (SSqlObj *)taosa; if (pSql == NULL || pSql->signature != pSql) { tscError("sql object is NULL"); -// globalCode = TSDB_CODE_DISCONNECTED; tscQueueAsyncError(fp, param, TSDB_CODE_DISCONNECTED); return; } @@ -232,7 +231,6 @@ void taos_fetch_row_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, TAOS_ROW), SSqlObj *pSql = (SSqlObj *)taosa; if (pSql == NULL || pSql->signature != pSql) { tscError("sql object is NULL"); -// globalCode = TSDB_CODE_DISCONNECTED; tscQueueAsyncError(fp, param, TSDB_CODE_DISCONNECTED); return; } diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 8b065fcf51e3115792a6312ea74e4e0a130206a9..caa14d082bc144be7614fa3290908ca3108fa58f 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -467,14 +467,14 @@ static int insertStmtExecute(STscStmt* stmt) { TAOS_STMT* taos_stmt_init(TAOS* taos) { STscObj* pObj = (STscObj*)taos; if (pObj == NULL || pObj->signature != pObj) { - globalCode = TSDB_CODE_DISCONNECTED; + terrno = TSDB_CODE_DISCONNECTED; tscError("connection disconnected"); return NULL; } STscStmt* pStmt = calloc(1, sizeof(STscStmt)); if (pStmt == NULL) { - globalCode = TSDB_CODE_CLI_OUT_OF_MEMORY; + terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; tscError("failed to allocate memory for statement"); return NULL; } @@ -482,7 +482,7 @@ TAOS_STMT* taos_stmt_init(TAOS* taos) { SSqlObj* pSql = calloc(1, sizeof(SSqlObj)); if (pSql == NULL) { free(pStmt); - globalCode = TSDB_CODE_CLI_OUT_OF_MEMORY; + terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; tscError("failed to allocate memory for statement"); return NULL; } diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index bbfd8645bd81c4668dee2ee2a411615c9dcb0ad5..f6c1fee633308260da4c8c9ce8c5e327c67338fb 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -57,17 +57,17 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con taos_init(); if (!validUserName(user)) { - globalCode = TSDB_CODE_INVALID_ACCT; + terrno = TSDB_CODE_INVALID_ACCT; return NULL; } if (!validPassword(pass)) { - globalCode = TSDB_CODE_INVALID_PASS; + terrno = TSDB_CODE_INVALID_PASS; return NULL; } if (tscInitRpc(user, pass) != 0) { - globalCode = TSDB_CODE_NETWORK_UNAVAIL; + terrno = TSDB_CODE_NETWORK_UNAVAIL; return NULL; } @@ -92,7 +92,7 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con STscObj *pObj = (STscObj *)calloc(1, sizeof(STscObj)); if (NULL == pObj) { - globalCode = TSDB_CODE_CLI_OUT_OF_MEMORY; + terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; return NULL; } @@ -107,7 +107,7 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con /* db name is too long */ if (len > TSDB_DB_NAME_LEN) { free(pObj); - globalCode = TSDB_CODE_INVALID_DB; + terrno = TSDB_CODE_INVALID_DB; return NULL; } @@ -122,7 +122,7 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj)); if (NULL == pSql) { - globalCode = TSDB_CODE_CLI_OUT_OF_MEMORY; + terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; free(pObj); return NULL; } @@ -140,7 +140,7 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con pSql->cmd.command = TSDB_SQL_CONNECT; if (TSDB_CODE_SUCCESS != tscAllocPayload(&pSql->cmd, TSDB_DEFAULT_PAYLOAD_SIZE)) { - globalCode = TSDB_CODE_CLI_OUT_OF_MEMORY; + terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; free(pSql); free(pObj); return NULL; @@ -303,7 +303,7 @@ int taos_query(TAOS *taos, const char *sqlstr) { TAOS_RES *taos_use_result(TAOS *taos) { STscObj *pObj = (STscObj *)taos; if (pObj == NULL || pObj->signature != pObj) { - globalCode = TSDB_CODE_DISCONNECTED; + terrno = TSDB_CODE_DISCONNECTED; return NULL; } @@ -662,7 +662,7 @@ static void waitForRetrieveRsp(void *param, TAOS_RES *tres, int numOfRows) { TAOS_ROW taos_fetch_row(TAOS_RES *res) { SSqlObj *pSql = (SSqlObj *)res; if (pSql == NULL || pSql->signature != pSql) { - globalCode = TSDB_CODE_DISCONNECTED; + terrno = TSDB_CODE_DISCONNECTED; return NULL; } @@ -694,7 +694,7 @@ int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) { int nRows = 0; if (pSql == NULL || pSql->signature != pSql) { - globalCode = TSDB_CODE_DISCONNECTED; + terrno = TSDB_CODE_DISCONNECTED; *rows = NULL; return 0; } @@ -733,7 +733,7 @@ int taos_select_db(TAOS *taos, const char *db) { STscObj *pObj = (STscObj *)taos; if (pObj == NULL || pObj->signature != pObj) { - globalCode = TSDB_CODE_DISCONNECTED; + terrno = TSDB_CODE_DISCONNECTED; return TSDB_CODE_DISCONNECTED; } @@ -1011,7 +1011,7 @@ int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields) int taos_validate_sql(TAOS *taos, const char *sql) { STscObj *pObj = (STscObj *)taos; if (pObj == NULL || pObj->signature != pObj) { - globalCode = TSDB_CODE_DISCONNECTED; + terrno = TSDB_CODE_DISCONNECTED; return TSDB_CODE_DISCONNECTED; } @@ -1143,7 +1143,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { STscObj *pObj = (STscObj *)taos; if (pObj == NULL || pObj->signature != pObj) { - globalCode = TSDB_CODE_DISCONNECTED; + terrno = TSDB_CODE_DISCONNECTED; return TSDB_CODE_DISCONNECTED; } diff --git a/src/client/src/tscSub.c b/src/client/src/tscSub.c index 9d172d4ea5279c648b636df0d8895c1a20bda7cd..fd457a12dd26ac8bba28890db971b311f04b12a3 100644 --- a/src/client/src/tscSub.c +++ b/src/client/src/tscSub.c @@ -99,14 +99,14 @@ void tscUpdateSubscriptionProgress(void* sub, int64_t uid, TSKEY ts) { static SSub* tscCreateSubscription(STscObj* pObj, const char* topic, const char* sql) { SSub* pSub = calloc(1, sizeof(SSub)); if (pSub == NULL) { - globalCode = TSDB_CODE_CLI_OUT_OF_MEMORY; + terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; tscError("failed to allocate memory for subscription"); return NULL; } SSqlObj* pSql = calloc(1, sizeof(SSqlObj)); if (pSql == NULL) { - globalCode = TSDB_CODE_CLI_OUT_OF_MEMORY; + terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; tscError("failed to allocate SSqlObj for subscription"); goto failed; } @@ -309,7 +309,7 @@ void tscSaveSubscriptionProgress(void* sub) { TAOS_SUB *taos_subscribe(TAOS *taos, int restart, const char* topic, const char *sql, TAOS_SUBSCRIBE_CALLBACK fp, void *param, int interval) { STscObj* pObj = (STscObj*)taos; if (pObj == NULL || pObj->signature != pObj) { - globalCode = TSDB_CODE_DISCONNECTED; + terrno = TSDB_CODE_DISCONNECTED; tscError("connection disconnected"); return NULL; } diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index ead8c09dec3062b74745318b29c6eb3af11b96f8..ea4cf12f9de399b7ff934ff189fa600930bb6374 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -33,7 +33,6 @@ void * pVMeterConn; void * pTscMgmtConn; void * pSlaveConn; void * tscCacheHandle; -int32_t globalCode = 0; int slaveIndex; void * tscTmr; void * tscQhandle; diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 9b1771164d8b1cf4556d7de1013576f90cf578b5..0294120ccb718633af35de4472ec303f61faca9e 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -819,7 +819,7 @@ void tscCloseTscObj(STscObj* pObj) { pObj->signature = NULL; SSqlObj* pSql = pObj->pSql; if (pSql) { - globalCode = pSql->res.code; + terrno = pSql->res.code; } taosTmrStopA(&(pObj->pTimer)); @@ -2153,7 +2153,7 @@ int16_t tscGetJoinTagColIndexByUid(STagCond* pTagCond, uint64_t uid) { bool tscIsUpdateQuery(STscObj* pObj) { if (pObj == NULL || pObj->signature != pObj) { - globalCode = TSDB_CODE_DISCONNECTED; + terrno = TSDB_CODE_DISCONNECTED; return TSDB_CODE_DISCONNECTED; } diff --git a/src/query/tests/astTest.cpp b/src/query/tests/astTest.cpp index ac10cd2429ea5a7634fe226d4bc9f80f17e44e28..3b1f36e90f9fc4001fcf11d5dbcf105985787205 100644 --- a/src/query/tests/astTest.cpp +++ b/src/query/tests/astTest.cpp @@ -9,6 +9,9 @@ #include "tsdb.h" #include "tskiplist.h" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wwrite-strings" + typedef struct ResultObj { int32_t numOfResult; char * resultName[64]; diff --git a/src/query/tests/tsBufTest.cpp b/src/query/tests/tsBufTest.cpp index 2392bd00b53c52126585d5bf1e795fe8db15f106..ff58e2a97446da04f96cc23fe224632fa7f7ad49 100644 --- a/src/query/tests/tsBufTest.cpp +++ b/src/query/tests/tsBufTest.cpp @@ -158,7 +158,7 @@ void loadDataTest() { for (int32_t i = 0; i < numOfTags; ++i) { int64_t* list = createTsList(num, start, step); tsBufAppend(pTSBuf, j, i, (const char*)list, num * sizeof(int64_t)); - printf("%d - %lld\n", i, list[0]); + printf("%d - %" PRIu64 "\n", i, list[0]); free(list); start += step * num; @@ -195,7 +195,7 @@ void loadDataTest() { tsBufResetPos(pNewBuf); int64_t s = taosGetTimestampUs(); - printf("start:%lld\n", s); + printf("start:%" PRIu64 "\n", s); int32_t x = 0; while (tsBufNextPos(pNewBuf)) { @@ -204,11 +204,11 @@ void loadDataTest() { break; } - // printf("%d-%lld-%lld\n", elem.vnode, elem.tag, elem.ts); + // printf("%d-%" PRIu64 "-%" PRIu64 "\n", elem.vnode, elem.tag, elem.ts); } int64_t e = taosGetTimestampUs(); - printf("end:%lld, elapsed:%lld, total obj:%d\n", e, e - s, x); + printf("end:%" PRIu64 ", elapsed:%" PRIu64 ", total obj:%d\n", e, e - s, x); } void randomIncTsTest() {} @@ -229,14 +229,14 @@ void TSTraverse() { for (int32_t i = 0; i < numOfTags; ++i) { int64_t* list = createTsList(num, start, step); tsBufAppend(pTSBuf, j, i, (const char*)list, num * sizeof(int64_t)); - printf("%d - %d - %lld, %lld\n", j, i, list[0], list[num - 1]); + printf("%d - %d - %" PRIu64 ", %" PRIu64 "\n", j, i, list[0], list[num - 1]); free(list); start += step * num; list = createTsList(num, start, step); tsBufAppend(pTSBuf, j, i, (const char*)list, num * sizeof(int64_t)); - printf("%d - %d - %lld, %lld\n", j, i, list[0], list[num - 1]); + printf("%d - %d - %" PRIu64 ", %" PRIu64 "\n", j, i, list[0], list[num - 1]); free(list); start += step * num; @@ -250,7 +250,7 @@ void TSTraverse() { //////////////////////////////////////////////////////////////////////////////////////// // reverse traverse int64_t s = taosGetTimestampUs(); - printf("start:%lld\n", s); + printf("start:%" PRIu64 "\n", s); pTSBuf->cur.order = TSQL_SO_DESC; @@ -258,7 +258,7 @@ void TSTraverse() { int32_t x = 0; while (tsBufNextPos(pTSBuf)) { STSElem elem = tsBufGetElem(pTSBuf); - // printf("%d-%lld-%lld\n", elem.vnode, elem.tag, elem.ts); + // printf("%d-%" PRIu64 "-%" PRIu64 "\n", elem.vnode, elem.tag, elem.ts); } // specify the data block with vnode and tags value @@ -273,7 +273,7 @@ void TSTraverse() { int32_t totalOutput = 10; while (1) { STSElem elem = tsBufGetElem(pTSBuf); - printf("%d-%lld-%lld\n", elem.vnode, elem.tag, elem.ts); + printf("%d-%" PRIu64 "-%" PRIu64 "\n", elem.vnode, elem.tag, elem.ts); if (!tsBufNextPos(pTSBuf)) { break; @@ -303,7 +303,7 @@ void TSTraverse() { // complete forwards traverse while (tsBufNextPos(pTSBuf)) { STSElem elem = tsBufGetElem(pTSBuf); - // printf("%d-%lld-%lld\n", elem.vnode, elem.tag, elem.ts); + // printf("%d-%" PRIu64 "-%" PRIu64 "\n", elem.vnode, elem.tag, elem.ts); } // specify the data block with vnode and tags value @@ -318,7 +318,7 @@ void TSTraverse() { totalOutput = 10; while (1) { STSElem elem = tsBufGetElem(pTSBuf); - printf("%d-%lld-%lld\n", elem.vnode, elem.tag, elem.ts); + printf("%d-%" PRIu64 "-%" PRIu64 "\n", elem.vnode, elem.tag, elem.ts); if (!tsBufNextPos(pTSBuf)) { break; @@ -429,7 +429,7 @@ void mergeIdenticalVnodeBufferTest() { STSElem elem = tsBufGetElem(pTSBuf1); EXPECT_EQ(elem.vnode, 12); - printf("%d-%lld-%lld\n", elem.vnode, elem.tag, elem.ts); + printf("%d-%" PRIu64 "-%" PRIu64 "\n", elem.vnode, elem.tag, elem.ts); } tsBufDestory(pTSBuf1); diff --git a/src/query/tests/unitTest.cpp b/src/query/tests/unitTest.cpp index c7520c90f9fbdb818d85d8f3b321c49820441f2d..df28a3e4d11168b915781ec9f13bda768be36e6b 100644 --- a/src/query/tests/unitTest.cpp +++ b/src/query/tests/unitTest.cpp @@ -11,6 +11,9 @@ #include "tvariant.h" #include "ttokendef.h" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wwrite-strings" + namespace { int32_t testValidateName(char* name) { SSQLToken token = {0}; diff --git a/src/util/inc/tcache.h b/src/util/inc/tcache.h index 36635fff30f32f3ad3a993e2e0c5139f35eec1a6..a29e720e67904b5ffbc32a575ccb86dd0ccdbabb 100644 --- a/src/util/inc/tcache.h +++ b/src/util/inc/tcache.h @@ -98,7 +98,7 @@ SCacheObj *taosCacheInit(void *tmrCtrl, int64_t refreshTimeInSeconds); * @param keepTime survival time in second * @return cached element */ -void *taosCachePut(SCacheObj *pCacheObj, char *key, void *pData, size_t dataSize, int keepTimeInSeconds); +void *taosCachePut(SCacheObj *pCacheObj, const char *key, const void *pData, size_t dataSize, int keepTimeInSeconds); /** * get data from cache diff --git a/src/util/src/tcache.c b/src/util/src/tcache.c index 5f04765f010416eb06c0016764af08c4e88496bf..8bfec97032478251b0c83078c1559ecdb6a27e4d 100644 --- a/src/util/src/tcache.c +++ b/src/util/src/tcache.c @@ -233,8 +233,8 @@ static FORCE_INLINE void taosCacheMoveToTrash(SCacheObj *pCacheObj, SCacheDataNo * @param dataSize * @return */ -static SCacheDataNode *taosUpdateCacheImpl(SCacheObj *pCacheObj, SCacheDataNode *pNode, char *key, int32_t keyLen, - void *pData, uint32_t dataSize, uint64_t duration) { +static SCacheDataNode *taosUpdateCacheImpl(SCacheObj *pCacheObj, SCacheDataNode *pNode, const char *key, int32_t keyLen, + const void *pData, uint32_t dataSize, uint64_t duration) { SCacheDataNode *pNewNode = NULL; // only a node is not referenced by any other object, in-place update it @@ -288,7 +288,7 @@ static SCacheDataNode *taosUpdateCacheImpl(SCacheObj *pCacheObj, SCacheDataNode * @param pNode * @return */ -static FORCE_INLINE SCacheDataNode *taosAddToCacheImpl(SCacheObj *pCacheObj, char *key, size_t keyLen, const void *pData, +static FORCE_INLINE SCacheDataNode *taosAddToCacheImpl(SCacheObj *pCacheObj, const char *key, size_t keyLen, const void *pData, size_t dataSize, uint64_t duration) { SCacheDataNode *pNode = taosCreateHashNode(key, keyLen, pData, dataSize, duration); if (pNode == NULL) { @@ -401,7 +401,7 @@ SCacheObj *taosCacheInit(void *tmrCtrl, int64_t refreshTime) { return pCacheObj; } -void *taosCachePut(SCacheObj *pCacheObj, char *key, void *pData, size_t dataSize, int duration) { +void *taosCachePut(SCacheObj *pCacheObj, const char *key, const void *pData, size_t dataSize, int duration) { SCacheDataNode *pNode; if (pCacheObj == NULL || pCacheObj->pHashTable == NULL) { diff --git a/src/util/tests/cacheTest.cpp b/src/util/tests/cacheTest.cpp index 1902fef4b64d0b796a85d9f58e1f422fe0df59e8..13fb7d7afbdcd669bf107f5869ff7842b34ceee0 100644 --- a/src/util/tests/cacheTest.cpp +++ b/src/util/tests/cacheTest.cpp @@ -22,15 +22,15 @@ TEST(testCase, client_cache_test) { void* tscTmr = taosTmrInit (tsMaxMgmtConnections*2, 200, 6000, "TSC"); SCacheObj* tscCacheHandle = taosCacheInit(tscTmr, REFRESH_TIME_IN_SEC); - char* key1 = "test1"; - char* data1 = "test11"; + const char* key1 = "test1"; + char data1[] = "test11"; char* cachedObj = (char*) taosCachePut(tscCacheHandle, key1, data1, strlen(data1), 1); sleep(REFRESH_TIME_IN_SEC+1); printf("obj is still valid: %s\n", cachedObj); - char* data2 = "test22"; + char data2[] = "test22"; taosCacheRelease(tscCacheHandle, (void**) &cachedObj, false); /* the object is cleared by cache clean operation */ @@ -43,8 +43,8 @@ TEST(testCase, client_cache_test) { getchar(); - char* key3 = "test2"; - char* data3 = "kkkkkkk"; + const char* key3 = "test2"; + const char* data3 = "kkkkkkk"; char* cachedObj2 = (char*) taosCachePut(tscCacheHandle, key3, data3, strlen(data3), 1); printf("%s\n", cachedObj2); @@ -55,11 +55,11 @@ TEST(testCase, client_cache_test) { char* d = (char*) taosCacheAcquireByName(tscCacheHandle, key3); // assert(d == NULL); - char* key5 = "test5"; - char* data5 = "data5kkkkk"; + char key5[] = "test5"; + char data5[] = "data5kkkkk"; cachedObj2 = (char*) taosCachePut(tscCacheHandle, key5, data5, strlen(data5), 20); - char* data6= "new Data after updated"; + const char* data6= "new Data after updated"; taosCacheRelease(tscCacheHandle, (void**) &cachedObj2, false); cachedObj2 = (char*) taosCachePut(tscCacheHandle, key5, data6, strlen(data6), 20); @@ -67,7 +67,7 @@ TEST(testCase, client_cache_test) { taosCacheRelease(tscCacheHandle, (void**) &cachedObj2, true); - char* data7 = "add call update procedure"; + const char* data7 = "add call update procedure"; cachedObj2 = (char*) taosCachePut(tscCacheHandle, key5, data7, strlen(data7), 20); printf("%s\n=======================================\n\n", cachedObj2); @@ -76,8 +76,8 @@ TEST(testCase, client_cache_test) { taosCacheRelease(tscCacheHandle, (void**) &cachedObj2, true); taosCacheRelease(tscCacheHandle, (void**) &cc, false); - char* data8 = "ttft"; - char* key6 = "key6"; + const char* data8 = "ttft"; + const char* key6 = "key6"; char* ft = (char*) taosCachePut(tscCacheHandle, key6, data8, strlen(data8), 20); taosCacheRelease(tscCacheHandle, (void**) &ft, false); @@ -86,7 +86,7 @@ TEST(testCase, client_cache_test) { * 140ns */ uint64_t startTime = taosGetTimestampUs(); - printf("Cache Performance Test\nstart time:%lld\n", startTime); + printf("Cache Performance Test\nstart time:%" PRIu64 "\n", startTime); for(int32_t i=0; i<1000; ++i) { char* dd = (char*) taosCacheAcquireByName(tscCacheHandle, key6); if (dd != NULL) { @@ -101,7 +101,7 @@ TEST(testCase, client_cache_test) { uint64_t endTime = taosGetTimestampUs(); int64_t el = endTime - startTime; - printf("End of Test, %lld\nTotal Elapsed Time:%lld us.avg:%f us\n", endTime, el, el/1000.0); + printf("End of Test, %" PRIu64 "\nTotal Elapsed Time:%" PRIu64 " us.avg:%f us\n", endTime, el, el/1000.0); taosCacheCleanup(tscCacheHandle); } @@ -125,7 +125,7 @@ TEST(testCase, cache_resize_test) { } uint64_t endTime = taosGetTimestampUs(); - printf("add %d object cost:%lld us, avg:%f us\n", num, endTime - startTime, (endTime-startTime)/(double)num); + printf("add %d object cost:%" PRIu64 " us, avg:%f us\n", num, endTime - startTime, (endTime-startTime)/(double)num); startTime = taosGetTimestampUs(); for(int32_t i = 0; i < num; ++i) { @@ -134,7 +134,7 @@ TEST(testCase, cache_resize_test) { assert(k != 0); } endTime = taosGetTimestampUs(); - printf("retrieve %d object cost:%lld us,avg:%f\n", num, endTime - startTime, (endTime - startTime)/(double)num); + printf("retrieve %d object cost:%" PRIu64 " us,avg:%f\n", num, endTime - startTime, (endTime - startTime)/(double)num); taosCacheCleanup(pCache); taosMsleep(20000); diff --git a/src/util/tests/skiplistTest.cpp b/src/util/tests/skiplistTest.cpp index c009231874de94530ffa18d15f745531c4daa94c..9e690c3924062e67aea47974d0e2d08d78fa46b7 100644 --- a/src/util/tests/skiplistTest.cpp +++ b/src/util/tests/skiplistTest.cpp @@ -175,7 +175,7 @@ void stringKeySkiplistTest() { } int64_t e = taosGetTimestampUs(); - printf("elapsed time:%lld us to insert %d data, avg:%f us\n", (e - s), total, (double)(e - s) / total); + printf("elapsed time:%" PRIu64 " us to insert %d data, avg:%f us\n", (e - s), total, (double)(e - s) / total); printf("level two------------------\n"); tSkipListPrint(pSkipList, 1); @@ -237,13 +237,13 @@ void skiplistPerformanceTest() { int64_t cur = taosGetTimestampMs(); int64_t elapsed = cur - prev; - printf("add %d, elapsed time: %lld ms, avg elapsed:%f ms, total:%d\n", 100000, elapsed, elapsed / 100000.0, i); + printf("add %d, elapsed time: %" PRIu64 " ms, avg elapsed:%f ms, total:%d\n", 100000, elapsed, elapsed / 100000.0, i); prev = cur; } } int64_t e = taosGetTimestampMs(); - printf("total:%lld ms, avg:%f\n", e - s, (e - s) / (double)size); + printf("total:%" PRIu64 " ms, avg:%f\n", e - s, (e - s) / (double)size); printf("max level of skiplist:%d, actually level:%d\n ", pSkipList->maxLevel, pSkipList->level); assert(tSkipListGetSize(pSkipList) == size); diff --git a/src/vnode/tsdb/src/tsdbRead.c b/src/vnode/tsdb/src/tsdbRead.c index cf75f21a4581e6660464ee9a5a713afed57f1856..30d0e949507b997fa1cbee4cfcac338fe3c16f7e 100644 --- a/src/vnode/tsdb/src/tsdbRead.c +++ b/src/vnode/tsdb/src/tsdbRead.c @@ -1053,7 +1053,7 @@ typedef struct SSyntaxTreeFilterSupporter { * convert the result pointer to STabObj instead of tSkipListNode * @param pRes */ -static void tansformQueryResult(SArray* pRes) { +static UNUSED_FUNC void tansformQueryResult(SArray* pRes) { if (pRes == NULL || taosArrayGetSize(pRes) == 0) { return; } @@ -1305,10 +1305,10 @@ bool tSkipListNodeFilterCallback(const void* pNode, void* param) { } static int32_t doQueryTableList(STable* pSTable, SArray* pRes, const char* pCond) { - STColumn* stcol = schemaColAt(pSTable->tagSchema, 0); +// STColumn* stcol = schemaColAt(pSTable->tagSchema, 0); tExprNode* pExpr = NULL; - tSQLBinaryExprFromString(&pExpr, stcol, schemaNCols(pSTable->tagSchema), (char*) pCond, strlen(pCond)); +// tSQLBinaryExprFromString(&pExpr, stcol, schemaNCols(pSTable->tagSchema), (char*) pCond, strlen(pCond)); // failed to build expression, no result, return immediately if (pExpr == NULL) { @@ -1319,18 +1319,18 @@ static int32_t doQueryTableList(STable* pSTable, SArray* pRes, const char* pCond } // query according to the binary expression - SSyntaxTreeFilterSupporter s = {.pTagSchema = stcol, .numOfTags = schemaNCols(pSTable->tagSchema)}; - - SBinaryFilterSupp supp = { - .fp = (__result_filter_fn_t)tSkipListNodeFilterCallback, - .setupInfoFn = (__do_filter_suppl_fn_t)filterPrepare, - .pExtInfo = &s - }; - - tSQLBinaryExprTraverse(pExpr, pSTable->pIndex, pRes, &supp); - tExprTreeDestroy(&pExpr, tSQLListTraverseDestroyInfo); - - tansformQueryResult(pRes); +// SSyntaxTreeFilterSupporter s = {.pTagSchema = stcol, .numOfTags = schemaNCols(pSTable->tagSchema)}; +// +// SBinaryFilterSupp supp = { +// .fp = (__result_filter_fn_t)tSkipListNodeFilterCallback, +// .setupInfoFn = (__do_filter_suppl_fn_t)filterPrepare, +// .pExtInfo = &s +// }; +// +// tSQLBinaryExprTraverse(pExpr, pSTable->pIndex, pRes, &supp); +// tExprTreeDestroy(&pExpr, tSQLListTraverseDestroyInfo); +// +// tansformQueryResult(pRes); return TSDB_CODE_SUCCESS; } diff --git a/tests/examples/c/demo.c b/tests/examples/c/demo.c index ddca1ac05d97617cdf718e5f0a2e5ed9e8c035a7..853a949162e10ae64677734d77ad7ffeec2eb3bb 100644 --- a/tests/examples/c/demo.c +++ b/tests/examples/c/demo.c @@ -24,44 +24,20 @@ void taosMsleep(int mseconds); -static int32_t doQuery(TAOS* taos, const char* sql) { - int32_t code = taos_query(taos, sql); - if (code != 0) { - printf("failed to execute query, reason:%s\n", taos_errstr(taos)); - return -1; - } - - TAOS_RES* res = taos_use_result(taos); - TAOS_ROW row = NULL; - char buf[512] = {0}; - - int32_t numOfFields = taos_num_fields(res); - TAOS_FIELD* pFields = taos_fetch_fields(res); - - while((row = taos_fetch_row(res)) != NULL) { - taos_print_row(buf, row, pFields, numOfFields); - printf("%s\n", buf); - memset(buf, 0, 512); - } - - taos_free_result(res); -} - int main(int argc, char *argv[]) { TAOS * taos; char qstr[1024]; TAOS_RES *result; - + // connect to server if (argc < 2) { printf("please input server-ip \n"); return 0; } - - taos_options(TSDB_OPTION_CONFIGDIR, "~/sec/cfg"); + // init TAOS taos_init(); - + taos = taos_connect(argv[1], "root", "taosdata", NULL, 0); if (taos == NULL) { printf("failed to connect to server, reason:%s\n", taos_errstr(taos)); @@ -69,20 +45,6 @@ int main(int argc, char *argv[]) { } printf("success to connect to server\n"); - doQuery(taos, "create database if not exists test"); - doQuery(taos, "use test"); - doQuery(taos, "create table if not exists tm0 (ts timestamp, k int);"); - doQuery(taos, "insert into tm0 values(now, 1)(now+1s, 2)(now+2s, 3)(now+3s, 4);"); - doQuery(taos, "select * from tm0;"); -// doQuery(taos, "insert into tm01 values(now, 1)(now+1s, 2)(now+2s, 3)(now+3s, 4);"); -// doQuery(taos, "insert into tm0 values(now, 1)(now+1s, 2)(now+2s, 3)(now+3s, 4);"); -// doQuery(taos, "insert into tm0 values(now, 1)(now+1s, 2)(now+2s, 3)(now+3s, 4);"); -// doQuery(taos, "insert into tm0 values(now, 1)(now+1s, 2)(now+2s, 3)(now+3s, 4);"); - - taos_close(taos); - - getchar(); - return 0; taos_query(taos, "drop database demo"); if (taos_query(taos, "create database demo") != 0) { @@ -90,19 +52,19 @@ int main(int argc, char *argv[]) { exit(1); } printf("success to create database\n"); - + taos_query(taos, "use demo"); - + // create table if (taos_query(taos, "create table m1 (ts timestamp, speed int)") != 0) { printf("failed to create table, reason:%s\n", taos_errstr(taos)); exit(1); } printf("success to create table\n"); - + // sleep for one second to make sure table is created on data node // taosMsleep(1000); - + // insert 10 records int i = 0; for (i = 0; i < 10; ++i) { @@ -113,28 +75,35 @@ int main(int argc, char *argv[]) { //sleep(1); } printf("success to insert rows, total %d rows\n", i); - + // query the records sprintf(qstr, "SELECT * FROM m1"); if (taos_query(taos, qstr) != 0) { printf("failed to select, reason:%s\n", taos_errstr(taos)); exit(1); } - + result = taos_use_result(taos); - + if (result == NULL) { printf("failed to get result, reason:%s\n", taos_errstr(taos)); exit(1); } - -// TAOS_ROW row; + + TAOS_ROW row; int rows = 0; int num_fields = taos_field_count(taos); TAOS_FIELD *fields = taos_fetch_fields(result); char temp[256]; - + printf("select * from table, result:\n"); + // fetch the records row by row + while ((row = taos_fetch_row(result))) { + rows++; + taos_print_row(temp, row, fields, num_fields); + printf("%s\n", temp); + } + taos_free_result(result); printf("====demo end====\n\n"); return getchar();