提交 a3af16e8 编写于 作者: H hjxilinx

[TD-98] suppress compiler warnings.

上级 d88df895
...@@ -468,7 +468,6 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo); ...@@ -468,7 +468,6 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo);
extern void * pVnodeConn; extern void * pVnodeConn;
extern void * pTscMgmtConn; extern void * pTscMgmtConn;
extern void * tscCacheHandle; extern void * tscCacheHandle;
extern int32_t globalCode;
extern int slaveIndex; extern int slaveIndex;
extern void * tscTmr; extern void * tscTmr;
extern void * tscQhandle; extern void * tscQhandle;
......
...@@ -200,7 +200,6 @@ void taos_fetch_rows_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, int), voi ...@@ -200,7 +200,6 @@ void taos_fetch_rows_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, int), voi
SSqlObj *pSql = (SSqlObj *)taosa; SSqlObj *pSql = (SSqlObj *)taosa;
if (pSql == NULL || pSql->signature != pSql) { if (pSql == NULL || pSql->signature != pSql) {
tscError("sql object is NULL"); tscError("sql object is NULL");
// globalCode = TSDB_CODE_DISCONNECTED;
tscQueueAsyncError(fp, param, TSDB_CODE_DISCONNECTED); tscQueueAsyncError(fp, param, TSDB_CODE_DISCONNECTED);
return; return;
} }
...@@ -232,7 +231,6 @@ void taos_fetch_row_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, TAOS_ROW), ...@@ -232,7 +231,6 @@ void taos_fetch_row_a(TAOS_RES *taosa, void (*fp)(void *, TAOS_RES *, TAOS_ROW),
SSqlObj *pSql = (SSqlObj *)taosa; SSqlObj *pSql = (SSqlObj *)taosa;
if (pSql == NULL || pSql->signature != pSql) { if (pSql == NULL || pSql->signature != pSql) {
tscError("sql object is NULL"); tscError("sql object is NULL");
// globalCode = TSDB_CODE_DISCONNECTED;
tscQueueAsyncError(fp, param, TSDB_CODE_DISCONNECTED); tscQueueAsyncError(fp, param, TSDB_CODE_DISCONNECTED);
return; return;
} }
......
...@@ -467,14 +467,14 @@ static int insertStmtExecute(STscStmt* stmt) { ...@@ -467,14 +467,14 @@ static int insertStmtExecute(STscStmt* stmt) {
TAOS_STMT* taos_stmt_init(TAOS* taos) { TAOS_STMT* taos_stmt_init(TAOS* taos) {
STscObj* pObj = (STscObj*)taos; STscObj* pObj = (STscObj*)taos;
if (pObj == NULL || pObj->signature != pObj) { if (pObj == NULL || pObj->signature != pObj) {
globalCode = TSDB_CODE_DISCONNECTED; terrno = TSDB_CODE_DISCONNECTED;
tscError("connection disconnected"); tscError("connection disconnected");
return NULL; return NULL;
} }
STscStmt* pStmt = calloc(1, sizeof(STscStmt)); STscStmt* pStmt = calloc(1, sizeof(STscStmt));
if (pStmt == NULL) { if (pStmt == NULL) {
globalCode = TSDB_CODE_CLI_OUT_OF_MEMORY; terrno = TSDB_CODE_CLI_OUT_OF_MEMORY;
tscError("failed to allocate memory for statement"); tscError("failed to allocate memory for statement");
return NULL; return NULL;
} }
...@@ -482,7 +482,7 @@ TAOS_STMT* taos_stmt_init(TAOS* taos) { ...@@ -482,7 +482,7 @@ TAOS_STMT* taos_stmt_init(TAOS* taos) {
SSqlObj* pSql = calloc(1, sizeof(SSqlObj)); SSqlObj* pSql = calloc(1, sizeof(SSqlObj));
if (pSql == NULL) { if (pSql == NULL) {
free(pStmt); free(pStmt);
globalCode = TSDB_CODE_CLI_OUT_OF_MEMORY; terrno = TSDB_CODE_CLI_OUT_OF_MEMORY;
tscError("failed to allocate memory for statement"); tscError("failed to allocate memory for statement");
return NULL; return NULL;
} }
......
...@@ -57,17 +57,17 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con ...@@ -57,17 +57,17 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con
taos_init(); taos_init();
if (!validUserName(user)) { if (!validUserName(user)) {
globalCode = TSDB_CODE_INVALID_ACCT; terrno = TSDB_CODE_INVALID_ACCT;
return NULL; return NULL;
} }
if (!validPassword(pass)) { if (!validPassword(pass)) {
globalCode = TSDB_CODE_INVALID_PASS; terrno = TSDB_CODE_INVALID_PASS;
return NULL; return NULL;
} }
if (tscInitRpc(user, pass) != 0) { if (tscInitRpc(user, pass) != 0) {
globalCode = TSDB_CODE_NETWORK_UNAVAIL; terrno = TSDB_CODE_NETWORK_UNAVAIL;
return NULL; return NULL;
} }
...@@ -92,7 +92,7 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con ...@@ -92,7 +92,7 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con
STscObj *pObj = (STscObj *)calloc(1, sizeof(STscObj)); STscObj *pObj = (STscObj *)calloc(1, sizeof(STscObj));
if (NULL == pObj) { if (NULL == pObj) {
globalCode = TSDB_CODE_CLI_OUT_OF_MEMORY; terrno = TSDB_CODE_CLI_OUT_OF_MEMORY;
return NULL; return NULL;
} }
...@@ -107,7 +107,7 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con ...@@ -107,7 +107,7 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con
/* db name is too long */ /* db name is too long */
if (len > TSDB_DB_NAME_LEN) { if (len > TSDB_DB_NAME_LEN) {
free(pObj); free(pObj);
globalCode = TSDB_CODE_INVALID_DB; terrno = TSDB_CODE_INVALID_DB;
return NULL; return NULL;
} }
...@@ -122,7 +122,7 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con ...@@ -122,7 +122,7 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con
SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj)); SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj));
if (NULL == pSql) { if (NULL == pSql) {
globalCode = TSDB_CODE_CLI_OUT_OF_MEMORY; terrno = TSDB_CODE_CLI_OUT_OF_MEMORY;
free(pObj); free(pObj);
return NULL; return NULL;
} }
...@@ -140,7 +140,7 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con ...@@ -140,7 +140,7 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con
pSql->cmd.command = TSDB_SQL_CONNECT; pSql->cmd.command = TSDB_SQL_CONNECT;
if (TSDB_CODE_SUCCESS != tscAllocPayload(&pSql->cmd, TSDB_DEFAULT_PAYLOAD_SIZE)) { 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(pSql);
free(pObj); free(pObj);
return NULL; return NULL;
...@@ -303,7 +303,7 @@ int taos_query(TAOS *taos, const char *sqlstr) { ...@@ -303,7 +303,7 @@ int taos_query(TAOS *taos, const char *sqlstr) {
TAOS_RES *taos_use_result(TAOS *taos) { TAOS_RES *taos_use_result(TAOS *taos) {
STscObj *pObj = (STscObj *)taos; STscObj *pObj = (STscObj *)taos;
if (pObj == NULL || pObj->signature != pObj) { if (pObj == NULL || pObj->signature != pObj) {
globalCode = TSDB_CODE_DISCONNECTED; terrno = TSDB_CODE_DISCONNECTED;
return NULL; return NULL;
} }
...@@ -662,7 +662,7 @@ static void waitForRetrieveRsp(void *param, TAOS_RES *tres, int numOfRows) { ...@@ -662,7 +662,7 @@ static void waitForRetrieveRsp(void *param, TAOS_RES *tres, int numOfRows) {
TAOS_ROW taos_fetch_row(TAOS_RES *res) { TAOS_ROW taos_fetch_row(TAOS_RES *res) {
SSqlObj *pSql = (SSqlObj *)res; SSqlObj *pSql = (SSqlObj *)res;
if (pSql == NULL || pSql->signature != pSql) { if (pSql == NULL || pSql->signature != pSql) {
globalCode = TSDB_CODE_DISCONNECTED; terrno = TSDB_CODE_DISCONNECTED;
return NULL; return NULL;
} }
...@@ -694,7 +694,7 @@ int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) { ...@@ -694,7 +694,7 @@ int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) {
int nRows = 0; int nRows = 0;
if (pSql == NULL || pSql->signature != pSql) { if (pSql == NULL || pSql->signature != pSql) {
globalCode = TSDB_CODE_DISCONNECTED; terrno = TSDB_CODE_DISCONNECTED;
*rows = NULL; *rows = NULL;
return 0; return 0;
} }
...@@ -733,7 +733,7 @@ int taos_select_db(TAOS *taos, const char *db) { ...@@ -733,7 +733,7 @@ int taos_select_db(TAOS *taos, const char *db) {
STscObj *pObj = (STscObj *)taos; STscObj *pObj = (STscObj *)taos;
if (pObj == NULL || pObj->signature != pObj) { if (pObj == NULL || pObj->signature != pObj) {
globalCode = TSDB_CODE_DISCONNECTED; terrno = TSDB_CODE_DISCONNECTED;
return 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) ...@@ -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) { int taos_validate_sql(TAOS *taos, const char *sql) {
STscObj *pObj = (STscObj *)taos; STscObj *pObj = (STscObj *)taos;
if (pObj == NULL || pObj->signature != pObj) { if (pObj == NULL || pObj->signature != pObj) {
globalCode = TSDB_CODE_DISCONNECTED; terrno = TSDB_CODE_DISCONNECTED;
return TSDB_CODE_DISCONNECTED; return TSDB_CODE_DISCONNECTED;
} }
...@@ -1143,7 +1143,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { ...@@ -1143,7 +1143,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) {
STscObj *pObj = (STscObj *)taos; STscObj *pObj = (STscObj *)taos;
if (pObj == NULL || pObj->signature != pObj) { if (pObj == NULL || pObj->signature != pObj) {
globalCode = TSDB_CODE_DISCONNECTED; terrno = TSDB_CODE_DISCONNECTED;
return TSDB_CODE_DISCONNECTED; return TSDB_CODE_DISCONNECTED;
} }
......
...@@ -99,14 +99,14 @@ void tscUpdateSubscriptionProgress(void* sub, int64_t uid, TSKEY ts) { ...@@ -99,14 +99,14 @@ void tscUpdateSubscriptionProgress(void* sub, int64_t uid, TSKEY ts) {
static SSub* tscCreateSubscription(STscObj* pObj, const char* topic, const char* sql) { static SSub* tscCreateSubscription(STscObj* pObj, const char* topic, const char* sql) {
SSub* pSub = calloc(1, sizeof(SSub)); SSub* pSub = calloc(1, sizeof(SSub));
if (pSub == NULL) { if (pSub == NULL) {
globalCode = TSDB_CODE_CLI_OUT_OF_MEMORY; terrno = TSDB_CODE_CLI_OUT_OF_MEMORY;
tscError("failed to allocate memory for subscription"); tscError("failed to allocate memory for subscription");
return NULL; return NULL;
} }
SSqlObj* pSql = calloc(1, sizeof(SSqlObj)); SSqlObj* pSql = calloc(1, sizeof(SSqlObj));
if (pSql == NULL) { if (pSql == NULL) {
globalCode = TSDB_CODE_CLI_OUT_OF_MEMORY; terrno = TSDB_CODE_CLI_OUT_OF_MEMORY;
tscError("failed to allocate SSqlObj for subscription"); tscError("failed to allocate SSqlObj for subscription");
goto failed; goto failed;
} }
...@@ -309,7 +309,7 @@ void tscSaveSubscriptionProgress(void* sub) { ...@@ -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) { 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; STscObj* pObj = (STscObj*)taos;
if (pObj == NULL || pObj->signature != pObj) { if (pObj == NULL || pObj->signature != pObj) {
globalCode = TSDB_CODE_DISCONNECTED; terrno = TSDB_CODE_DISCONNECTED;
tscError("connection disconnected"); tscError("connection disconnected");
return NULL; return NULL;
} }
......
...@@ -33,7 +33,6 @@ void * pVMeterConn; ...@@ -33,7 +33,6 @@ void * pVMeterConn;
void * pTscMgmtConn; void * pTscMgmtConn;
void * pSlaveConn; void * pSlaveConn;
void * tscCacheHandle; void * tscCacheHandle;
int32_t globalCode = 0;
int slaveIndex; int slaveIndex;
void * tscTmr; void * tscTmr;
void * tscQhandle; void * tscQhandle;
......
...@@ -819,7 +819,7 @@ void tscCloseTscObj(STscObj* pObj) { ...@@ -819,7 +819,7 @@ void tscCloseTscObj(STscObj* pObj) {
pObj->signature = NULL; pObj->signature = NULL;
SSqlObj* pSql = pObj->pSql; SSqlObj* pSql = pObj->pSql;
if (pSql) { if (pSql) {
globalCode = pSql->res.code; terrno = pSql->res.code;
} }
taosTmrStopA(&(pObj->pTimer)); taosTmrStopA(&(pObj->pTimer));
...@@ -2153,7 +2153,7 @@ int16_t tscGetJoinTagColIndexByUid(STagCond* pTagCond, uint64_t uid) { ...@@ -2153,7 +2153,7 @@ int16_t tscGetJoinTagColIndexByUid(STagCond* pTagCond, uint64_t uid) {
bool tscIsUpdateQuery(STscObj* pObj) { bool tscIsUpdateQuery(STscObj* pObj) {
if (pObj == NULL || pObj->signature != pObj) { if (pObj == NULL || pObj->signature != pObj) {
globalCode = TSDB_CODE_DISCONNECTED; terrno = TSDB_CODE_DISCONNECTED;
return TSDB_CODE_DISCONNECTED; return TSDB_CODE_DISCONNECTED;
} }
......
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
#include "tsdb.h" #include "tsdb.h"
#include "tskiplist.h" #include "tskiplist.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings"
typedef struct ResultObj { typedef struct ResultObj {
int32_t numOfResult; int32_t numOfResult;
char * resultName[64]; char * resultName[64];
......
...@@ -158,7 +158,7 @@ void loadDataTest() { ...@@ -158,7 +158,7 @@ void loadDataTest() {
for (int32_t i = 0; i < numOfTags; ++i) { for (int32_t i = 0; i < numOfTags; ++i) {
int64_t* list = createTsList(num, start, step); int64_t* list = createTsList(num, start, step);
tsBufAppend(pTSBuf, j, i, (const char*)list, num * sizeof(int64_t)); 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); free(list);
start += step * num; start += step * num;
...@@ -195,7 +195,7 @@ void loadDataTest() { ...@@ -195,7 +195,7 @@ void loadDataTest() {
tsBufResetPos(pNewBuf); tsBufResetPos(pNewBuf);
int64_t s = taosGetTimestampUs(); int64_t s = taosGetTimestampUs();
printf("start:%lld\n", s); printf("start:%" PRIu64 "\n", s);
int32_t x = 0; int32_t x = 0;
while (tsBufNextPos(pNewBuf)) { while (tsBufNextPos(pNewBuf)) {
...@@ -204,11 +204,11 @@ void loadDataTest() { ...@@ -204,11 +204,11 @@ void loadDataTest() {
break; 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(); 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() {} void randomIncTsTest() {}
...@@ -229,14 +229,14 @@ void TSTraverse() { ...@@ -229,14 +229,14 @@ void TSTraverse() {
for (int32_t i = 0; i < numOfTags; ++i) { for (int32_t i = 0; i < numOfTags; ++i) {
int64_t* list = createTsList(num, start, step); int64_t* list = createTsList(num, start, step);
tsBufAppend(pTSBuf, j, i, (const char*)list, num * sizeof(int64_t)); 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); free(list);
start += step * num; start += step * num;
list = createTsList(num, start, step); list = createTsList(num, start, step);
tsBufAppend(pTSBuf, j, i, (const char*)list, num * sizeof(int64_t)); 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); free(list);
start += step * num; start += step * num;
...@@ -250,7 +250,7 @@ void TSTraverse() { ...@@ -250,7 +250,7 @@ void TSTraverse() {
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// reverse traverse // reverse traverse
int64_t s = taosGetTimestampUs(); int64_t s = taosGetTimestampUs();
printf("start:%lld\n", s); printf("start:%" PRIu64 "\n", s);
pTSBuf->cur.order = TSQL_SO_DESC; pTSBuf->cur.order = TSQL_SO_DESC;
...@@ -258,7 +258,7 @@ void TSTraverse() { ...@@ -258,7 +258,7 @@ void TSTraverse() {
int32_t x = 0; int32_t x = 0;
while (tsBufNextPos(pTSBuf)) { while (tsBufNextPos(pTSBuf)) {
STSElem elem = tsBufGetElem(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 // specify the data block with vnode and tags value
...@@ -273,7 +273,7 @@ void TSTraverse() { ...@@ -273,7 +273,7 @@ void TSTraverse() {
int32_t totalOutput = 10; int32_t totalOutput = 10;
while (1) { while (1) {
STSElem elem = tsBufGetElem(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);
if (!tsBufNextPos(pTSBuf)) { if (!tsBufNextPos(pTSBuf)) {
break; break;
...@@ -303,7 +303,7 @@ void TSTraverse() { ...@@ -303,7 +303,7 @@ void TSTraverse() {
// complete forwards traverse // complete forwards traverse
while (tsBufNextPos(pTSBuf)) { while (tsBufNextPos(pTSBuf)) {
STSElem elem = tsBufGetElem(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 // specify the data block with vnode and tags value
...@@ -318,7 +318,7 @@ void TSTraverse() { ...@@ -318,7 +318,7 @@ void TSTraverse() {
totalOutput = 10; totalOutput = 10;
while (1) { while (1) {
STSElem elem = tsBufGetElem(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);
if (!tsBufNextPos(pTSBuf)) { if (!tsBufNextPos(pTSBuf)) {
break; break;
...@@ -429,7 +429,7 @@ void mergeIdenticalVnodeBufferTest() { ...@@ -429,7 +429,7 @@ void mergeIdenticalVnodeBufferTest() {
STSElem elem = tsBufGetElem(pTSBuf1); STSElem elem = tsBufGetElem(pTSBuf1);
EXPECT_EQ(elem.vnode, 12); 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); tsBufDestory(pTSBuf1);
......
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
#include "tvariant.h" #include "tvariant.h"
#include "ttokendef.h" #include "ttokendef.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings"
namespace { namespace {
int32_t testValidateName(char* name) { int32_t testValidateName(char* name) {
SSQLToken token = {0}; SSQLToken token = {0};
......
...@@ -98,7 +98,7 @@ SCacheObj *taosCacheInit(void *tmrCtrl, int64_t refreshTimeInSeconds); ...@@ -98,7 +98,7 @@ SCacheObj *taosCacheInit(void *tmrCtrl, int64_t refreshTimeInSeconds);
* @param keepTime survival time in second * @param keepTime survival time in second
* @return cached element * @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 * get data from cache
......
...@@ -233,8 +233,8 @@ static FORCE_INLINE void taosCacheMoveToTrash(SCacheObj *pCacheObj, SCacheDataNo ...@@ -233,8 +233,8 @@ static FORCE_INLINE void taosCacheMoveToTrash(SCacheObj *pCacheObj, SCacheDataNo
* @param dataSize * @param dataSize
* @return * @return
*/ */
static SCacheDataNode *taosUpdateCacheImpl(SCacheObj *pCacheObj, SCacheDataNode *pNode, char *key, int32_t keyLen, static SCacheDataNode *taosUpdateCacheImpl(SCacheObj *pCacheObj, SCacheDataNode *pNode, const char *key, int32_t keyLen,
void *pData, uint32_t dataSize, uint64_t duration) { const void *pData, uint32_t dataSize, uint64_t duration) {
SCacheDataNode *pNewNode = NULL; SCacheDataNode *pNewNode = NULL;
// only a node is not referenced by any other object, in-place update it // only a node is not referenced by any other object, in-place update it
...@@ -288,7 +288,7 @@ static SCacheDataNode *taosUpdateCacheImpl(SCacheObj *pCacheObj, SCacheDataNode ...@@ -288,7 +288,7 @@ static SCacheDataNode *taosUpdateCacheImpl(SCacheObj *pCacheObj, SCacheDataNode
* @param pNode * @param pNode
* @return * @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) { size_t dataSize, uint64_t duration) {
SCacheDataNode *pNode = taosCreateHashNode(key, keyLen, pData, dataSize, duration); SCacheDataNode *pNode = taosCreateHashNode(key, keyLen, pData, dataSize, duration);
if (pNode == NULL) { if (pNode == NULL) {
...@@ -401,7 +401,7 @@ SCacheObj *taosCacheInit(void *tmrCtrl, int64_t refreshTime) { ...@@ -401,7 +401,7 @@ SCacheObj *taosCacheInit(void *tmrCtrl, int64_t refreshTime) {
return pCacheObj; 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; SCacheDataNode *pNode;
if (pCacheObj == NULL || pCacheObj->pHashTable == NULL) { if (pCacheObj == NULL || pCacheObj->pHashTable == NULL) {
......
...@@ -22,15 +22,15 @@ TEST(testCase, client_cache_test) { ...@@ -22,15 +22,15 @@ TEST(testCase, client_cache_test) {
void* tscTmr = taosTmrInit (tsMaxMgmtConnections*2, 200, 6000, "TSC"); void* tscTmr = taosTmrInit (tsMaxMgmtConnections*2, 200, 6000, "TSC");
SCacheObj* tscCacheHandle = taosCacheInit(tscTmr, REFRESH_TIME_IN_SEC); SCacheObj* tscCacheHandle = taosCacheInit(tscTmr, REFRESH_TIME_IN_SEC);
char* key1 = "test1"; const char* key1 = "test1";
char* data1 = "test11"; char data1[] = "test11";
char* cachedObj = (char*) taosCachePut(tscCacheHandle, key1, data1, strlen(data1), 1); char* cachedObj = (char*) taosCachePut(tscCacheHandle, key1, data1, strlen(data1), 1);
sleep(REFRESH_TIME_IN_SEC+1); sleep(REFRESH_TIME_IN_SEC+1);
printf("obj is still valid: %s\n", cachedObj); printf("obj is still valid: %s\n", cachedObj);
char* data2 = "test22"; char data2[] = "test22";
taosCacheRelease(tscCacheHandle, (void**) &cachedObj, false); taosCacheRelease(tscCacheHandle, (void**) &cachedObj, false);
/* the object is cleared by cache clean operation */ /* the object is cleared by cache clean operation */
...@@ -43,8 +43,8 @@ TEST(testCase, client_cache_test) { ...@@ -43,8 +43,8 @@ TEST(testCase, client_cache_test) {
getchar(); getchar();
char* key3 = "test2"; const char* key3 = "test2";
char* data3 = "kkkkkkk"; const char* data3 = "kkkkkkk";
char* cachedObj2 = (char*) taosCachePut(tscCacheHandle, key3, data3, strlen(data3), 1); char* cachedObj2 = (char*) taosCachePut(tscCacheHandle, key3, data3, strlen(data3), 1);
printf("%s\n", cachedObj2); printf("%s\n", cachedObj2);
...@@ -55,11 +55,11 @@ TEST(testCase, client_cache_test) { ...@@ -55,11 +55,11 @@ TEST(testCase, client_cache_test) {
char* d = (char*) taosCacheAcquireByName(tscCacheHandle, key3); char* d = (char*) taosCacheAcquireByName(tscCacheHandle, key3);
// assert(d == NULL); // assert(d == NULL);
char* key5 = "test5"; char key5[] = "test5";
char* data5 = "data5kkkkk"; char data5[] = "data5kkkkk";
cachedObj2 = (char*) taosCachePut(tscCacheHandle, key5, data5, strlen(data5), 20); 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); taosCacheRelease(tscCacheHandle, (void**) &cachedObj2, false);
cachedObj2 = (char*) taosCachePut(tscCacheHandle, key5, data6, strlen(data6), 20); cachedObj2 = (char*) taosCachePut(tscCacheHandle, key5, data6, strlen(data6), 20);
...@@ -67,7 +67,7 @@ TEST(testCase, client_cache_test) { ...@@ -67,7 +67,7 @@ TEST(testCase, client_cache_test) {
taosCacheRelease(tscCacheHandle, (void**) &cachedObj2, true); 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); cachedObj2 = (char*) taosCachePut(tscCacheHandle, key5, data7, strlen(data7), 20);
printf("%s\n=======================================\n\n", cachedObj2); printf("%s\n=======================================\n\n", cachedObj2);
...@@ -76,8 +76,8 @@ TEST(testCase, client_cache_test) { ...@@ -76,8 +76,8 @@ TEST(testCase, client_cache_test) {
taosCacheRelease(tscCacheHandle, (void**) &cachedObj2, true); taosCacheRelease(tscCacheHandle, (void**) &cachedObj2, true);
taosCacheRelease(tscCacheHandle, (void**) &cc, false); taosCacheRelease(tscCacheHandle, (void**) &cc, false);
char* data8 = "ttft"; const char* data8 = "ttft";
char* key6 = "key6"; const char* key6 = "key6";
char* ft = (char*) taosCachePut(tscCacheHandle, key6, data8, strlen(data8), 20); char* ft = (char*) taosCachePut(tscCacheHandle, key6, data8, strlen(data8), 20);
taosCacheRelease(tscCacheHandle, (void**) &ft, false); taosCacheRelease(tscCacheHandle, (void**) &ft, false);
...@@ -86,7 +86,7 @@ TEST(testCase, client_cache_test) { ...@@ -86,7 +86,7 @@ TEST(testCase, client_cache_test) {
* 140ns * 140ns
*/ */
uint64_t startTime = taosGetTimestampUs(); 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) { for(int32_t i=0; i<1000; ++i) {
char* dd = (char*) taosCacheAcquireByName(tscCacheHandle, key6); char* dd = (char*) taosCacheAcquireByName(tscCacheHandle, key6);
if (dd != NULL) { if (dd != NULL) {
...@@ -101,7 +101,7 @@ TEST(testCase, client_cache_test) { ...@@ -101,7 +101,7 @@ TEST(testCase, client_cache_test) {
uint64_t endTime = taosGetTimestampUs(); uint64_t endTime = taosGetTimestampUs();
int64_t el = endTime - startTime; 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); taosCacheCleanup(tscCacheHandle);
} }
...@@ -125,7 +125,7 @@ TEST(testCase, cache_resize_test) { ...@@ -125,7 +125,7 @@ TEST(testCase, cache_resize_test) {
} }
uint64_t endTime = taosGetTimestampUs(); 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(); startTime = taosGetTimestampUs();
for(int32_t i = 0; i < num; ++i) { for(int32_t i = 0; i < num; ++i) {
...@@ -134,7 +134,7 @@ TEST(testCase, cache_resize_test) { ...@@ -134,7 +134,7 @@ TEST(testCase, cache_resize_test) {
assert(k != 0); assert(k != 0);
} }
endTime = taosGetTimestampUs(); 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); taosCacheCleanup(pCache);
taosMsleep(20000); taosMsleep(20000);
......
...@@ -175,7 +175,7 @@ void stringKeySkiplistTest() { ...@@ -175,7 +175,7 @@ void stringKeySkiplistTest() {
} }
int64_t e = taosGetTimestampUs(); 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"); printf("level two------------------\n");
tSkipListPrint(pSkipList, 1); tSkipListPrint(pSkipList, 1);
...@@ -237,13 +237,13 @@ void skiplistPerformanceTest() { ...@@ -237,13 +237,13 @@ void skiplistPerformanceTest() {
int64_t cur = taosGetTimestampMs(); int64_t cur = taosGetTimestampMs();
int64_t elapsed = cur - prev; 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; prev = cur;
} }
} }
int64_t e = taosGetTimestampMs(); 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); printf("max level of skiplist:%d, actually level:%d\n ", pSkipList->maxLevel, pSkipList->level);
assert(tSkipListGetSize(pSkipList) == size); assert(tSkipListGetSize(pSkipList) == size);
......
...@@ -1053,7 +1053,7 @@ typedef struct SSyntaxTreeFilterSupporter { ...@@ -1053,7 +1053,7 @@ typedef struct SSyntaxTreeFilterSupporter {
* convert the result pointer to STabObj instead of tSkipListNode * convert the result pointer to STabObj instead of tSkipListNode
* @param pRes * @param pRes
*/ */
static void tansformQueryResult(SArray* pRes) { static UNUSED_FUNC void tansformQueryResult(SArray* pRes) {
if (pRes == NULL || taosArrayGetSize(pRes) == 0) { if (pRes == NULL || taosArrayGetSize(pRes) == 0) {
return; return;
} }
...@@ -1305,10 +1305,10 @@ bool tSkipListNodeFilterCallback(const void* pNode, void* param) { ...@@ -1305,10 +1305,10 @@ bool tSkipListNodeFilterCallback(const void* pNode, void* param) {
} }
static int32_t doQueryTableList(STable* pSTable, SArray* pRes, const char* pCond) { 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; 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 // failed to build expression, no result, return immediately
if (pExpr == NULL) { if (pExpr == NULL) {
...@@ -1319,18 +1319,18 @@ static int32_t doQueryTableList(STable* pSTable, SArray* pRes, const char* pCond ...@@ -1319,18 +1319,18 @@ static int32_t doQueryTableList(STable* pSTable, SArray* pRes, const char* pCond
} }
// query according to the binary expression // query according to the binary expression
SSyntaxTreeFilterSupporter s = {.pTagSchema = stcol, .numOfTags = schemaNCols(pSTable->tagSchema)}; // SSyntaxTreeFilterSupporter s = {.pTagSchema = stcol, .numOfTags = schemaNCols(pSTable->tagSchema)};
//
SBinaryFilterSupp supp = { // SBinaryFilterSupp supp = {
.fp = (__result_filter_fn_t)tSkipListNodeFilterCallback, // .fp = (__result_filter_fn_t)tSkipListNodeFilterCallback,
.setupInfoFn = (__do_filter_suppl_fn_t)filterPrepare, // .setupInfoFn = (__do_filter_suppl_fn_t)filterPrepare,
.pExtInfo = &s // .pExtInfo = &s
}; // };
//
tSQLBinaryExprTraverse(pExpr, pSTable->pIndex, pRes, &supp); // tSQLBinaryExprTraverse(pExpr, pSTable->pIndex, pRes, &supp);
tExprTreeDestroy(&pExpr, tSQLListTraverseDestroyInfo); // tExprTreeDestroy(&pExpr, tSQLListTraverseDestroyInfo);
//
tansformQueryResult(pRes); // tansformQueryResult(pRes);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
......
...@@ -24,44 +24,20 @@ ...@@ -24,44 +24,20 @@
void taosMsleep(int mseconds); 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[]) { int main(int argc, char *argv[]) {
TAOS * taos; TAOS * taos;
char qstr[1024]; char qstr[1024];
TAOS_RES *result; TAOS_RES *result;
// connect to server // connect to server
if (argc < 2) { if (argc < 2) {
printf("please input server-ip \n"); printf("please input server-ip \n");
return 0; return 0;
} }
taos_options(TSDB_OPTION_CONFIGDIR, "~/sec/cfg");
// init TAOS // init TAOS
taos_init(); taos_init();
taos = taos_connect(argv[1], "root", "taosdata", NULL, 0); taos = taos_connect(argv[1], "root", "taosdata", NULL, 0);
if (taos == NULL) { if (taos == NULL) {
printf("failed to connect to server, reason:%s\n", taos_errstr(taos)); printf("failed to connect to server, reason:%s\n", taos_errstr(taos));
...@@ -69,20 +45,6 @@ int main(int argc, char *argv[]) { ...@@ -69,20 +45,6 @@ int main(int argc, char *argv[]) {
} }
printf("success to connect to server\n"); 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"); taos_query(taos, "drop database demo");
if (taos_query(taos, "create database demo") != 0) { if (taos_query(taos, "create database demo") != 0) {
...@@ -90,19 +52,19 @@ int main(int argc, char *argv[]) { ...@@ -90,19 +52,19 @@ int main(int argc, char *argv[]) {
exit(1); exit(1);
} }
printf("success to create database\n"); printf("success to create database\n");
taos_query(taos, "use demo"); taos_query(taos, "use demo");
// create table // create table
if (taos_query(taos, "create table m1 (ts timestamp, speed int)") != 0) { if (taos_query(taos, "create table m1 (ts timestamp, speed int)") != 0) {
printf("failed to create table, reason:%s\n", taos_errstr(taos)); printf("failed to create table, reason:%s\n", taos_errstr(taos));
exit(1); exit(1);
} }
printf("success to create table\n"); printf("success to create table\n");
// sleep for one second to make sure table is created on data node // sleep for one second to make sure table is created on data node
// taosMsleep(1000); // taosMsleep(1000);
// insert 10 records // insert 10 records
int i = 0; int i = 0;
for (i = 0; i < 10; ++i) { for (i = 0; i < 10; ++i) {
...@@ -113,28 +75,35 @@ int main(int argc, char *argv[]) { ...@@ -113,28 +75,35 @@ int main(int argc, char *argv[]) {
//sleep(1); //sleep(1);
} }
printf("success to insert rows, total %d rows\n", i); printf("success to insert rows, total %d rows\n", i);
// query the records // query the records
sprintf(qstr, "SELECT * FROM m1"); sprintf(qstr, "SELECT * FROM m1");
if (taos_query(taos, qstr) != 0) { if (taos_query(taos, qstr) != 0) {
printf("failed to select, reason:%s\n", taos_errstr(taos)); printf("failed to select, reason:%s\n", taos_errstr(taos));
exit(1); exit(1);
} }
result = taos_use_result(taos); result = taos_use_result(taos);
if (result == NULL) { if (result == NULL) {
printf("failed to get result, reason:%s\n", taos_errstr(taos)); printf("failed to get result, reason:%s\n", taos_errstr(taos));
exit(1); exit(1);
} }
// TAOS_ROW row; TAOS_ROW row;
int rows = 0; int rows = 0;
int num_fields = taos_field_count(taos); int num_fields = taos_field_count(taos);
TAOS_FIELD *fields = taos_fetch_fields(result); TAOS_FIELD *fields = taos_fetch_fields(result);
char temp[256]; 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); taos_free_result(result);
printf("====demo end====\n\n"); printf("====demo end====\n\n");
return getchar(); return getchar();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册