diff --git a/src/client/inc/tscSubquery.h b/src/client/inc/tscSubquery.h index 7876069ccee841485fae9069d1116c13f385ce7b..bc01de110345e4c90cf5c15d3d7f6b010cb7308d 100644 --- a/src/client/inc/tscSubquery.h +++ b/src/client/inc/tscSubquery.h @@ -39,7 +39,7 @@ int32_t tscHandleMultivnodeInsert(SSqlObj *pSql); int32_t tscHandleInsertRetry(SSqlObj* pSql); void tscBuildResFromSubqueries(SSqlObj *pSql); -void **doSetResultRowData(SSqlObj *pSql, bool finalResult); +TAOS_ROW doSetResultRowData(SSqlObj *pSql, bool finalResult); #ifdef __cplusplus } diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index 8621f9d28bc90b22bb54bcdb8585c3db7a1bf429..74550c56e8d18ce6a241e5f11b398cdc3650b5ae 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -308,7 +308,7 @@ typedef struct { int32_t numOfGroups; SResRec * pGroupRec; char * data; - void ** tsrow; + TAOS_ROW tsrow; int32_t* length; // length for each field for current row char ** buffer; // Buffer used to put multibytes encoded using unicode (wchar_t) SColumnIndex * pColumnIndex; @@ -448,9 +448,8 @@ void tscCloseTscObj(STscObj *pObj); // todo move to taos? or create a new file: taos_internal.h TAOS *taos_connect_a(char *ip, char *user, char *pass, char *db, uint16_t port, void (*fp)(void *, TAOS_RES *, int), - void *param, void **taos); + void *param, TAOS **taos); TAOS_RES* taos_query_h(TAOS* taos, const char *sqlstr, TAOS_RES** res); - void waitForQueryRsp(void *param, TAOS_RES *tres, int code); void doAsyncQuery(STscObj *pObj, SSqlObj *pSql, __async_cb_func_t fp, void *param, const char *sqlstr, size_t sqlLen); @@ -481,11 +480,11 @@ static FORCE_INLINE void tscGetResultColumnChr(SSqlRes* pRes, SFieldInfo* pField if (type == TSDB_DATA_TYPE_NCHAR || type == TSDB_DATA_TYPE_BINARY) { pData = pInfo->pSqlExpr->param[1].pz; pRes->length[columnIndex] = pInfo->pSqlExpr->param[1].nLen; - pRes->tsrow[columnIndex] = (pInfo->pSqlExpr->param[1].nType == TSDB_DATA_TYPE_NULL) ? NULL : pData; + pRes->tsrow[columnIndex] = (pInfo->pSqlExpr->param[1].nType == TSDB_DATA_TYPE_NULL) ? NULL : (unsigned char*)pData; } else { assert(bytes == tDataTypeDesc[type].nSize); - pRes->tsrow[columnIndex] = isNull(pData, type) ? NULL : &pInfo->pSqlExpr->param[1].i64Key; + pRes->tsrow[columnIndex] = isNull(pData, type) ? NULL : (unsigned char*)&pInfo->pSqlExpr->param[1].i64Key; pRes->length[columnIndex] = bytes; } } else { @@ -493,7 +492,7 @@ static FORCE_INLINE void tscGetResultColumnChr(SSqlRes* pRes, SFieldInfo* pField int32_t realLen = varDataLen(pData); assert(realLen <= bytes - VARSTR_HEADER_SIZE); - pRes->tsrow[columnIndex] = (isNull(pData, type)) ? NULL : ((tstr *)pData)->data; + pRes->tsrow[columnIndex] = (isNull(pData, type)) ? NULL : (unsigned char*)((tstr *)pData)->data; if (realLen < pInfo->pSqlExpr->resBytes - VARSTR_HEADER_SIZE) { // todo refactor *(pData + realLen + VARSTR_HEADER_SIZE) = 0; } @@ -502,7 +501,7 @@ static FORCE_INLINE void tscGetResultColumnChr(SSqlRes* pRes, SFieldInfo* pField } else { assert(bytes == tDataTypeDesc[type].nSize); - pRes->tsrow[columnIndex] = isNull(pData, type) ? NULL : pData; + pRes->tsrow[columnIndex] = isNull(pData, type) ? NULL : (unsigned char*)pData; pRes->length[columnIndex] = bytes; } } diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index a15673bdb1edf97fda23d879ab69839fd500549e..929b9ffe68333831fcdfef03c545a6b3361d0694 100644 --- a/src/client/src/tscLocal.c +++ b/src/client/src/tscLocal.c @@ -296,7 +296,7 @@ static int32_t tscProcessDescribeTable(SSqlObj *pSql) { return tscSetValueToResObj(pSql, rowLen); } static int32_t tscGetNthFieldResult(TAOS_ROW row, TAOS_FIELD* fields, int *lengths, int idx, char *result) { - const char *val = row[idx]; + const char *val = (const char*)row[idx]; if (val == NULL) { sprintf(result, "%s", TSDB_DATA_NULL_STR); return -1; diff --git a/src/client/src/tscProfile.c b/src/client/src/tscProfile.c index bae0f91dcc40e78c3d2f707ff93ee6ebd5322339..eb6843b0e4fd844c9d13da7f55dca47008f62a79 100644 --- a/src/client/src/tscProfile.c +++ b/src/client/src/tscProfile.c @@ -20,8 +20,10 @@ #include "tutil.h" #include "taosmsg.h" +#include "taos.h" + void tscSaveSlowQueryFp(void *handle, void *tmrId); -void *tscSlowQueryConn = NULL; +TAOS *tscSlowQueryConn = NULL; bool tscSlowQueryConnInitialized = false; void tscInitConnCb(void *param, TAOS_RES *result, int code) { diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 494a8a9c301175352c399317c83324f364a31eb6..40e050e6a47f5f9806e68ef275f1695327a80a08 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -1366,7 +1366,7 @@ static int tscSetResultPointer(SQueryInfo *pQueryInfo, SSqlRes *pRes) { for (int i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) { int16_t offset = tscFieldInfoGetOffset(pQueryInfo, i); - pRes->tsrow[i] = ((char*) pRes->data + offset * pRes->numOfRows); + pRes->tsrow[i] = (unsigned char*)((char*) pRes->data + offset * pRes->numOfRows); } return 0; diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 7594a73c9604b25fb29143e7b88ad7876b2a496d..9799c9129bd4339b675a209aaec915bdf675474d 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -51,8 +51,8 @@ static bool validPassword(const char* passwd) { return validImpl(passwd, TSDB_PASSWORD_LEN - 1); } -SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, const char *auth, const char *db, - uint16_t port, void (*fp)(void *, TAOS_RES *, int), void *param, void **taos) { +static SSqlObj *taosConnectImpl(const char *ip, const char *user, const char *pass, const char *auth, const char *db, + uint16_t port, void (*fp)(void *, TAOS_RES *, int), void *param, TAOS **taos) { taos_init(); if (!validUserName(user)) { @@ -174,7 +174,7 @@ static void syncConnCallback(void *param, TAOS_RES *tres, int code) { TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass, const char *auth, const char *db, uint16_t port) { STscObj *pObj = NULL; - SSqlObj *pSql = taosConnectImpl(ip, user, pass, auth, db, port, syncConnCallback, NULL, (void **)&pObj); + SSqlObj *pSql = taosConnectImpl(ip, user, pass, auth, db, port, syncConnCallback, NULL, &pObj); if (pSql != NULL) { pSql->fp = syncConnCallback; pSql->param = pSql; @@ -243,16 +243,19 @@ static void asyncConnCallback(void *param, TAOS_RES *tres, int code) { } TAOS *taos_connect_a(char *ip, char *user, char *pass, char *db, uint16_t port, void (*fp)(void *, TAOS_RES *, int), - void *param, void **taos) { - SSqlObj* pSql = taosConnectImpl(ip, user, pass, NULL, db, port, asyncConnCallback, param, taos); + void *param, TAOS **taos) { + STscObj *pObj = NULL; + SSqlObj* pSql = taosConnectImpl(ip, user, pass, NULL, db, port, asyncConnCallback, param, &pObj); if (pSql == NULL) { return NULL; } - + + if (taos) *taos = pObj; + pSql->fetchFp = fp; pSql->res.code = tscProcessSql(pSql); tscDebug("%p DB async connection is opening", taos); - return taos; + return pObj; } void taos_close(TAOS *taos) { @@ -881,7 +884,7 @@ int taos_validate_sql(TAOS *taos, const char *sql) { if (pSql->sqlstr == NULL) { pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; tscError("%p failed to malloc sql string buffer", pSql); - tscDebug("%p Valid SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(taos), pObj); + tscDebug("%p Valid SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(pSql), pObj); taosTFree(pSql); return pRes->code; } @@ -906,7 +909,7 @@ int taos_validate_sql(TAOS *taos, const char *sql) { } if (code != TSDB_CODE_SUCCESS) { - tscDebug("%p Valid SQL result:%d, %s pObj:%p", pSql, code, taos_errstr(taos), pObj); + tscDebug("%p Valid SQL result:%d, %s pObj:%p", pSql, code, taos_errstr(pSql), pObj); } taos_free_result(pSql); @@ -1050,7 +1053,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { tscDoQuery(pSql); - tscDebug("%p load multi table meta result:%d %s pObj:%p", pSql, pRes->code, taos_errstr(taos), pObj); + tscDebug("%p load multi table meta result:%d %s pObj:%p", pSql, pRes->code, taos_errstr(pSql), pObj); if ((code = pRes->code) != TSDB_CODE_SUCCESS) { tscFreeSqlObj(pSql); } diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 49759bc4d30fa9a9a89591c33c3dc6666894d1b2..06e1efc9e4fee46d7e8735770b1a0597b2153d66 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -2130,7 +2130,7 @@ static void transferNcharData(SSqlObj *pSql, int32_t columnIndex, TAOS_FIELD *pF int32_t length = taosUcs4ToMbs(pRes->tsrow[columnIndex], pRes->length[columnIndex], pRes->buffer[columnIndex]); if ( length >= 0 ) { - pRes->tsrow[columnIndex] = pRes->buffer[columnIndex]; + pRes->tsrow[columnIndex] = (unsigned char*)pRes->buffer[columnIndex]; pRes->length[columnIndex] = length; } else { tscError("%p charset:%s to %s. val:%s convert failed.", pSql, DEFAULT_UNICODE_ENCODEC, tsCharset, (char*)pRes->tsrow[columnIndex]); @@ -2158,7 +2158,7 @@ static char *getArithemicInputSrc(void *param, const char *name, int32_t colId) return pSupport->data[index] + pSupport->offset * pExpr->resBytes; } -void **doSetResultRowData(SSqlObj *pSql, bool finalResult) { +TAOS_ROW doSetResultRowData(SSqlObj *pSql, bool finalResult) { SSqlCmd *pCmd = &pSql->cmd; SSqlRes *pRes = &pSql->res; @@ -2211,7 +2211,7 @@ void **doSetResultRowData(SSqlObj *pSql, bool finalResult) { tExprTreeCalcTraverse(pRes->pArithSup->pArithExpr->pExpr, 1, pRes->buffer[i], pRes->pArithSup, TSDB_ORDER_ASC, getArithemicInputSrc); - pRes->tsrow[i] = pRes->buffer[i]; + pRes->tsrow[i] = (unsigned char*)pRes->buffer[i]; } } diff --git a/src/inc/taos.h b/src/inc/taos.h index 2d72b1739d1023945f2fff7c4af10d908475c7d1..66b5f930bca4116ae72c1ee60753e4cc22c3b088 100644 --- a/src/inc/taos.h +++ b/src/inc/taos.h @@ -22,12 +22,13 @@ extern "C" { #endif -typedef void TAOS; -typedef void** TAOS_ROW; -typedef void TAOS_RES; -typedef void TAOS_SUB; -typedef void TAOS_STREAM; -typedef void TAOS_STMT; +typedef struct STscObj TAOS; +typedef struct STscStmt TAOS_STMT; +typedef struct SSqlObj TAOS_RES; +typedef struct SSqlStream TAOS_STREAM; +typedef struct SSub TAOS_SUB; +typedef unsigned char** TAOS_ROW; + // Data type definition #define TSDB_DATA_TYPE_NULL 0 // 1 bytes diff --git a/src/kit/shell/inc/shell.h b/src/kit/shell/inc/shell.h index 765181dbba5c92ca9dc80adb7376e68c70237d6d..f508d186083c84482080f2f8fe251173733f1366 100644 --- a/src/kit/shell/inc/shell.h +++ b/src/kit/shell/inc/shell.h @@ -60,7 +60,7 @@ typedef struct SShellArguments { extern void shellParseArgument(int argc, char* argv[], SShellArguments* arguments); extern TAOS* shellInit(SShellArguments* args); extern void* shellLoopQuery(void* arg); -extern void taos_error(TAOS* con); +extern void taos_error(TAOS_RES* tres); extern int regex_match(const char* s, const char* reg, int cflags); void shellReadCommand(TAOS* con, char command[]); int32_t shellRunCommand(TAOS* con, char* command); @@ -72,7 +72,7 @@ void source_dir(TAOS* con, SShellArguments* args); void get_history_path(char* history); void cleanup_handler(void* arg); void exitShell(); -int shellDumpResult(TAOS* con, char* fname, int* error_no, bool printMode); +int shellDumpResult(TAOS_RES* con, char* fname, int* error_no, bool printMode); void shellGetGrantInfo(void *con); int isCommentLine(char *line); diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index 24388bf50c7a215920a58e79f8d33ab81752c547..748b7e792982352de611227d82a844448d251ee2 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -493,7 +493,7 @@ static int dumpResultToFile(const char* fname, TAOS_RES* tres) { if (i > 0) { fputc(',', fp); } - dumpFieldToFile(fp, row[i], fields +i, length[i], precision); + dumpFieldToFile(fp, (const char*)row[i], fields +i, length[i], precision); } fputc('\n', fp); @@ -619,7 +619,7 @@ static int verticalPrintResult(TAOS_RES* tres) { int padding = (int)(maxColNameLen - strlen(field->name)); printf("%*.s%s: ", padding, " ", field->name); - printField(row[i], field, 0, length[i], precision); + printField((const char*)row[i], field, 0, length[i], precision); putchar('\n'); } @@ -720,7 +720,7 @@ static int horizontalPrintResult(TAOS_RES* tres) { int32_t* length = taos_fetch_lengths(tres); for (int i = 0; i < num_fields; i++) { putchar(' '); - printField(row[i], fields + i, width[i], length[i], precision); + printField((const char*)row[i], fields + i, width[i], length[i], precision); putchar(' '); putchar('|'); } diff --git a/src/kit/shell/src/shellImport.c b/src/kit/shell/src/shellImport.c index ee0a90757bb51a98dd2bf535319afc215dbc04a8..af61995c618bc80389b8abf6d8c6f6c929327925 100644 --- a/src/kit/shell/src/shellImport.c +++ b/src/kit/shell/src/shellImport.c @@ -204,7 +204,7 @@ static void shellSourceFile(TAOS *con, char *fptr) { int32_t code = taos_errno(pSql); if (code != 0) { - fprintf(stderr, "DB error: %s: %s (%d)\n", taos_errstr(con), fname, lineNo); + fprintf(stderr, "DB error: %s: %s (%d)\n", taos_errstr(pSql), fname, lineNo); } /* free local resouce: allocated memory/metric-meta refcnt */ @@ -243,7 +243,7 @@ static void shellRunImportThreads(SShellArguments* args) pThread->totalThreads = args->threadNum; pThread->taos = taos_connect(args->host, args->user, args->password, args->database, tsDnodeShellPort); if (pThread->taos == NULL) { - fprintf(stderr, "ERROR: thread:%d failed connect to TDengine, error:%s\n", pThread->threadIndex, taos_errstr(pThread->taos)); + fprintf(stderr, "ERROR: thread:%d failed connect to TDengine, error:%s\n", pThread->threadIndex, "null taos"/*taos_errstr(pThread->taos)*/); exit(0); } diff --git a/src/plugins/http/inc/httpInt.h b/src/plugins/http/inc/httpInt.h index 36a022159f4e8b58ca4179e9ae73d5ad7dd793d2..affc0e838ea97f25dcb2e53947ecbb7b025dffb1 100644 --- a/src/plugins/http/inc/httpInt.h +++ b/src/plugins/http/inc/httpInt.h @@ -122,9 +122,9 @@ typedef struct { } HttpDecodeMethod; typedef struct { - void (*startJsonFp)(struct HttpContext *pContext, HttpSqlCmd *cmd, void *result); + void (*startJsonFp)(struct HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result); void (*stopJsonFp)(struct HttpContext *pContext, HttpSqlCmd *cmd); - bool (*buildQueryJsonFp)(struct HttpContext *pContext, HttpSqlCmd *cmd, void *result, int numOfRows); + bool (*buildQueryJsonFp)(struct HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result, int numOfRows); void (*buildAffectRowJsonFp)(struct HttpContext *pContext, HttpSqlCmd *cmd, int affectRows); void (*initJsonFp)(struct HttpContext *pContext); void (*cleanJsonFp)(struct HttpContext *pContext); @@ -148,7 +148,7 @@ typedef struct HttpContext { char ipstr[22]; char user[TSDB_USER_LEN]; // parsed from auth token or login message char pass[TSDB_PASSWORD_LEN]; - void * taos; + TAOS * taos; void * ppContext; HttpSession *session; z_stream gzipStream; diff --git a/src/plugins/http/src/httpGcJson.c b/src/plugins/http/src/httpGcJson.c index 80e4ae3bc2b51387d5573af00aa1e91d2c1cd663..2c9eca11deb51acc8cc25965b83cc686ac04c6e5 100644 --- a/src/plugins/http/src/httpGcJson.c +++ b/src/plugins/http/src/httpGcJson.c @@ -217,7 +217,7 @@ bool gcBuildQueryJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result, break; case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_NCHAR: - httpJsonStringForTransMean(jsonBuf, row[i], fields[i].bytes); + httpJsonStringForTransMean(jsonBuf, (char*)row[i], fields[i].bytes); break; case TSDB_DATA_TYPE_TIMESTAMP: if (precision == TSDB_TIME_PRECISION_MILLI) { //ms diff --git a/src/plugins/http/src/httpRestJson.c b/src/plugins/http/src/httpRestJson.c index 954678c24c8fb4597ef3184d2d65060c6d159aa1..a5b156bffc23ea3cdb042f456a327895fc0bdaa6 100644 --- a/src/plugins/http/src/httpRestJson.c +++ b/src/plugins/http/src/httpRestJson.c @@ -131,7 +131,7 @@ bool restBuildSqlJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result, break; case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_NCHAR: - httpJsonStringForTransMean(jsonBuf, row[i], length[i]); + httpJsonStringForTransMean(jsonBuf, (char*)row[i], length[i]); break; case TSDB_DATA_TYPE_TIMESTAMP: if (timestampFormat == REST_TIMESTAMP_FMT_LOCAL_STRING) { @@ -195,4 +195,4 @@ void restStopSqlJson(HttpContext *pContext, HttpSqlCmd *cmd) { httpJsonToken(jsonBuf, JsonObjEnd); httpWriteJsonBufEnd(jsonBuf); -} \ No newline at end of file +} diff --git a/src/plugins/http/src/httpSql.c b/src/plugins/http/src/httpSql.c index 883fa574ff19958591051512e717a9b512f3e0ce..70d644146cf5ebe15a42c8f00a2e6e4bd603d081 100644 --- a/src/plugins/http/src/httpSql.c +++ b/src/plugins/http/src/httpSql.c @@ -27,8 +27,6 @@ #include "httpSession.h" #include "httpQueue.h" -void *taos_connect_a(char *ip, char *user, char *pass, char *db, uint16_t port, void (*fp)(void *, TAOS_RES *, int), - void *param, void **taos); void httpProcessMultiSql(HttpContext *pContext); void httpProcessMultiSqlRetrieveCallBack(void *param, TAOS_RES *result, int numOfRows); diff --git a/tests/comparisonTest/tdengine/tdengineTest.c b/tests/comparisonTest/tdengine/tdengineTest.c index 237403f52565c1b68b21e895d5555a2a673bb5f7..1298aa8323b0f876e3c64ff88323031b8d529648 100644 --- a/tests/comparisonTest/tdengine/tdengineTest.c +++ b/tests/comparisonTest/tdengine/tdengineTest.c @@ -108,9 +108,9 @@ void parseArg(int argc, char *argv[]) { } } -void taos_error(TAOS *con) { - printf("TDengine error: %s\n", taos_errstr(con)); - taos_close(con); +static void taos_error(TAOS_RES *tres, TAOS *conn) { + printf("TDengine error: %s\n", tres?taos_errstr(tres):"null result"); + taos_close(conn); exit(1); } @@ -125,13 +125,17 @@ void writeDataImp(void *param) { printf("Thread %d, writing sID %d, eID %d\n", pThread->threadId, pThread->sID, pThread->eID); void *taos = taos_connect("127.0.0.1", "root", "taosdata", NULL, 0); - if (taos == NULL) - taos_error(taos); + if (taos == NULL) { + // where to find errstr? + // taos_error(NULL, taos); + printf("TDengine error: %s\n", "failed to connect"); + exit(1); + } TAOS_RES* result = taos_query(taos, "use db"); int32_t code = taos_errno(result); if (code != 0) { - taos_error(taos); + taos_error(result, taos); } taos_free_result(result); @@ -227,12 +231,17 @@ void writeData() { taos_init(); void *taos = taos_connect("127.0.0.1", "root", "taosdata", NULL, 0); - if (taos == NULL) taos_error(taos); + if (taos == NULL) { + // where to find errstr? + // taos_error(NULL, taos); + printf("TDengine error: %s\n", "failed to connect"); + exit(1); + } TAOS_RES *result = taos_query(taos, "create database if not exists db"); int32_t code = taos_errno(result); if (code != 0) { - taos_error(taos); + taos_error(result, taos); } taos_free_result(result); @@ -241,7 +250,7 @@ void writeData() { "tags(devid int, devname binary(16), devgroup int)"); code = taos_errno(result); if (code != 0) { - taos_error(taos); + taos_error(result, taos); } taos_free_result(result); @@ -293,8 +302,12 @@ void readDataImp(void *param) printf("open file %s success\n", arguments.sql); void *taos = taos_connect("127.0.0.1", "root", "taosdata", NULL, 0); - if (taos == NULL) - taos_error(taos); + if (taos == NULL) { + // where to find errstr? + // taos_error(NULL, taos); + printf("TDengine error: %s\n", "failed to connect"); + exit(1); + } char *line = NULL; size_t len = 0; @@ -313,7 +326,7 @@ void readDataImp(void *param) TAOS_RES *result = taos_query(taos, line); int32_t code = taos_errno(result); if (code != 0) { - taos_error(taos); + taos_error(result, taos); } TAOS_ROW row; @@ -343,8 +356,12 @@ void readData() { printf("---- clients: %d\n", arguments.clients); void *taos = taos_connect("127.0.0.1", "root", "taosdata", NULL, 0); - if (taos == NULL) - taos_error(taos); + if (taos == NULL) { + // where to find errstr? + // taos_error(NULL, taos); + printf("TDengine error: %s\n", "failed to connect"); + exit(1); + } ThreadObj *threads = calloc((size_t)arguments.clients, sizeof(ThreadObj)); diff --git a/tests/examples/c/demo.c b/tests/examples/c/demo.c index d64c0de1ce45597e26396979bb693cc0f96873d5..8f8a66a32593bc25d71b554808719ca42f5b32ac 100644 --- a/tests/examples/c/demo.c +++ b/tests/examples/c/demo.c @@ -38,7 +38,7 @@ int main(int argc, char *argv[]) { taos = taos_connect(argv[1], "root", "taosdata", NULL, 0); if (taos == NULL) { - printf("failed to connect to server, reason:%s\n", taos_errstr(taos)); + printf("failed to connect to server, reason:%s\n", "null taos"/*taos_errstr(taos)*/); exit(1); } printf("success to connect to server\n"); @@ -48,7 +48,7 @@ int main(int argc, char *argv[]) { result = taos_query(taos, "create database demo"); if (result == NULL) { - printf("failed to create database, reason:%s\n", taos_errstr(taos)); + printf("failed to create database, reason:%s\n", "null result"/*taos_errstr(taos)*/); exit(1); } printf("success to create database\n"); @@ -57,7 +57,7 @@ int main(int argc, char *argv[]) { // create table if (taos_query(taos, "create table m1 (ts timestamp, ti tinyint, si smallint, i int, bi bigint, f float, d double, b binary(10))") == 0) { - printf("failed to create table, reason:%s\n", taos_errstr(taos)); + printf("failed to create table, reason:%s\n", taos_errstr(result)); exit(1); } printf("success to create table\n"); @@ -70,9 +70,19 @@ int main(int argc, char *argv[]) { for (i = 0; i < 10; ++i) { sprintf(qstr, "insert into m1 values (%" PRId64 ", %d, %d, %d, %d, %f, %lf, '%s')", 1546300800000 + i * 1000, i, i, i, i*10000000, i*1.0, i*2.0, "hello"); printf("qstr: %s\n", qstr); - if (taos_query(taos, qstr)) { - printf("insert row: %i, reason:%s\n", i, taos_errstr(taos)); + + // note: how do you wanna do if taos_query returns non-NULL + // if (taos_query(taos, qstr)) { + // printf("insert row: %i, reason:%s\n", i, taos_errstr(taos)); + // } + TAOS_RES *result = taos_query(taos, qstr); + if (result) { + printf("insert row: %i\n", i); + } else { + printf("failed to insert row: %i, reason:%s\n", i, "null result"/*taos_errstr(result)*/); + exit(1); } + //sleep(1); } printf("success to insert rows, total %d rows\n", i);