From 0d1a99d7d07bdf4c5e8a5c5f149e83326dd4e2e4 Mon Sep 17 00:00:00 2001 From: "pengrongkun94@qq.com" Date: Thu, 26 Dec 2024 16:30:50 +0800 Subject: [PATCH] remove some unused code --- source/client/inc/clientStmt2.h | 3 - source/client/src/clientMain.c | 82 +++---- source/client/src/clientStmt2.c | 161 -------------- source/client/test/stmt2Test.cpp | 352 ++++++++++++++++++++++--------- 4 files changed, 281 insertions(+), 317 deletions(-) diff --git a/source/client/inc/clientStmt2.h b/source/client/inc/clientStmt2.h index 0fe813473d..05a4c849f8 100644 --- a/source/client/inc/clientStmt2.h +++ b/source/client/inc/clientStmt2.h @@ -221,11 +221,8 @@ int stmtPrepare2(TAOS_STMT2 *stmt, const char *sql, unsigned long length int stmtSetTbName2(TAOS_STMT2 *stmt, const char *tbName); int stmtSetTbTags2(TAOS_STMT2 *stmt, TAOS_STMT2_BIND *tags); int stmtBindBatch2(TAOS_STMT2 *stmt, TAOS_STMT2_BIND *bind, int32_t colIdx); -int stmtGetTagFields2(TAOS_STMT2 *stmt, int *nums, TAOS_FIELD_E **fields); -int stmtGetColFields2(TAOS_STMT2 *stmt, int *nums, TAOS_FIELD_E **fields); int stmtGetStbColFields2(TAOS_STMT2 *stmt, int *nums, TAOS_FIELD_ALL **fields); int stmtGetParamNum2(TAOS_STMT2 *stmt, int *nums); -int stmtGetParamTbName(TAOS_STMT2 *stmt, int *nums); int stmtIsInsert2(TAOS_STMT2 *stmt, int *insert); TAOS_RES *stmtUseResult2(TAOS_STMT2 *stmt); const char *stmtErrstr2(TAOS_STMT2 *stmt); diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index f041e4b030..83aff351dd 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -24,13 +24,13 @@ #include "query.h" #include "scheduler.h" #include "tcompare.h" +#include "tconv.h" #include "tdatablock.h" #include "tglobal.h" #include "tmsg.h" #include "tref.h" #include "trpc.h" #include "version.h" -#include "tconv.h" #define TSC_VAR_NOT_RELEASE 1 #define TSC_VAR_RELEASED 0 @@ -56,12 +56,12 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) { } #ifndef WINDOWS -static void freeTz(void *p){ +static void freeTz(void *p) { timezone_t tz = *(timezone_t *)p; tzfree(tz); } -int32_t tzInit(){ +int32_t tzInit() { pTimezoneMap = taosHashInit(0, MurmurHash3_32, false, HASH_ENTRY_LOCK); if (pTimezoneMap == NULL) { return terrno; @@ -75,15 +75,15 @@ int32_t tzInit(){ return 0; } -void tzCleanup(){ +void tzCleanup() { taosHashCleanup(pTimezoneMap); taosHashCleanup(pTimezoneNameMap); } -static timezone_t setConnnectionTz(const char* val){ - timezone_t tz = NULL; +static timezone_t setConnnectionTz(const char *val) { + timezone_t tz = NULL; timezone_t *tmp = taosHashGet(pTimezoneMap, val, strlen(val)); - if (tmp != NULL && *tmp != NULL){ + if (tmp != NULL && *tmp != NULL) { tz = *tmp; goto END; } @@ -100,20 +100,20 @@ static timezone_t setConnnectionTz(const char* val){ } } int32_t code = taosHashPut(pTimezoneMap, val, strlen(val), &tz, sizeof(timezone_t)); - if (code != 0){ + if (code != 0) { tscError("%s put timezone to tz map error:%d", __func__, code); tzfree(tz); tz = NULL; goto END; } - time_t tx1 = taosGetTimestampSec(); - char output[TD_TIMEZONE_LEN] = {0}; + time_t tx1 = taosGetTimestampSec(); + char output[TD_TIMEZONE_LEN] = {0}; code = taosFormatTimezoneStr(tx1, val, tz, output); - if (code == 0){ + if (code == 0) { code = taosHashPut(pTimezoneNameMap, &tz, sizeof(timezone_t), output, strlen(output) + 1); } - if (code != 0){ + if (code != 0) { tscError("failed to put timezone %s to map", val); } @@ -122,18 +122,18 @@ END: } #endif -static int32_t setConnectionOption(TAOS *taos, TSDB_OPTION_CONNECTION option, const char* val){ +static int32_t setConnectionOption(TAOS *taos, TSDB_OPTION_CONNECTION option, const char *val) { if (taos == NULL) { return terrno = TSDB_CODE_INVALID_PARA; } #ifdef WINDOWS - if (option == TSDB_OPTION_CONNECTION_TIMEZONE){ + if (option == TSDB_OPTION_CONNECTION_TIMEZONE) { return terrno = TSDB_CODE_NOT_SUPPORTTED_IN_WINDOWS; } #endif - if (option < TSDB_OPTION_CONNECTION_CLEAR || option >= TSDB_MAX_OPTIONS_CONNECTION){ + if (option < TSDB_OPTION_CONNECTION_CLEAR || option >= TSDB_MAX_OPTIONS_CONNECTION) { return terrno = TSDB_CODE_INVALID_PARA; } @@ -149,7 +149,7 @@ static int32_t setConnectionOption(TAOS *taos, TSDB_OPTION_CONNECTION option, co return terrno; } - if (option == TSDB_OPTION_CONNECTION_CLEAR){ + if (option == TSDB_OPTION_CONNECTION_CLEAR) { val = NULL; } @@ -165,19 +165,19 @@ static int32_t setConnectionOption(TAOS *taos, TSDB_OPTION_CONNECTION option, co goto END; } pObj->optionInfo.charsetCxt = tmp; - }else{ + } else { pObj->optionInfo.charsetCxt = NULL; } } if (option == TSDB_OPTION_CONNECTION_TIMEZONE || option == TSDB_OPTION_CONNECTION_CLEAR) { #ifndef WINDOWS - if (val != NULL){ - if (val[0] == 0){ + if (val != NULL) { + if (val[0] == 0) { val = "UTC"; } timezone_t tz = setConnnectionTz(val); - if (tz == NULL){ + if (tz == NULL) { code = terrno; goto END; } @@ -199,7 +199,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 = taosInetAddr(val); - if (pObj->optionInfo.userIp == INADDR_NONE){ + if (pObj->optionInfo.userIp == INADDR_NONE) { code = TSDB_CODE_INVALID_PARA; goto END; } @@ -213,7 +213,7 @@ END: return terrno = code; } -int taos_options_connection(TAOS *taos, TSDB_OPTION_CONNECTION option, const void *arg, ...){ +int taos_options_connection(TAOS *taos, TSDB_OPTION_CONNECTION option, const void *arg, ...) { return setConnectionOption(taos, option, (const char *)arg); } @@ -2129,6 +2129,11 @@ int taos_stmt_close(TAOS_STMT *stmt) { } TAOS_STMT2 *taos_stmt2_init(TAOS *taos, TAOS_STMT2_OPTION *option) { + if (NULL == taos) { + tscError("NULL parameter for %s", __FUNCTION__); + terrno = TSDB_CODE_INVALID_PARA; + return NULL; + } STscObj *pObj = acquireTscObj(*(int64_t *)taos); if (NULL == pObj) { tscError("invalid parameter for %s", __FUNCTION__); @@ -2257,16 +2262,7 @@ int taos_stmt2_close(TAOS_STMT2 *stmt) { return stmtClose2(stmt); } -/* -int taos_stmt2_param_count(TAOS_STMT2 *stmt, int *nums) { - if (stmt == NULL || nums == NULL) { - tscError("NULL parameter for %s", __FUNCTION__); - terrno = TSDB_CODE_INVALID_PARA; - return terrno; - } - return stmtGetParamNum2(stmt, nums); -} -*/ + int taos_stmt2_is_insert(TAOS_STMT2 *stmt, int *insert) { if (stmt == NULL || insert == NULL) { tscError("NULL parameter for %s", __FUNCTION__); @@ -2277,28 +2273,6 @@ int taos_stmt2_is_insert(TAOS_STMT2 *stmt, int *insert) { return stmtIsInsert2(stmt, insert); } -// int taos_stmt2_get_fields(TAOS_STMT2 *stmt, TAOS_FIELD_T field_type, int *count, TAOS_FIELD_E **fields) { -// if (stmt == NULL || count == NULL) { -// tscError("NULL parameter for %s", __FUNCTION__); -// terrno = TSDB_CODE_INVALID_PARA; -// return terrno; -// } - -// if (field_type == TAOS_FIELD_COL) { -// return stmtGetColFields2(stmt, count, fields); -// } else if (field_type == TAOS_FIELD_TAG) { -// return stmtGetTagFields2(stmt, count, fields); -// } else if (field_type == TAOS_FIELD_QUERY) { -// return stmtGetParamNum2(stmt, count); -// } else if (field_type == TAOS_FIELD_TBNAME) { -// return stmtGetParamTbName(stmt, count); -// } else { -// tscError("invalid parameter for %s", __FUNCTION__); -// terrno = TSDB_CODE_INVALID_PARA; -// return terrno; -// } -// } - int taos_stmt2_get_fields(TAOS_STMT2 *stmt, int *count, TAOS_FIELD_ALL **fields) { if (stmt == NULL || count == NULL) { tscError("NULL parameter for %s", __FUNCTION__); diff --git a/source/client/src/clientStmt2.c b/source/client/src/clientStmt2.c index acd118acc9..f7f4cbb087 100644 --- a/source/client/src/clientStmt2.c +++ b/source/client/src/clientStmt2.c @@ -1036,28 +1036,6 @@ int stmtSetTbTags2(TAOS_STMT2* stmt, TAOS_STMT2_BIND* tags) { return TSDB_CODE_SUCCESS; } -static int stmtFetchTagFields2(STscStmt2* pStmt, int32_t* fieldNum, TAOS_FIELD_E** fields) { - if (pStmt->errCode != TSDB_CODE_SUCCESS) { - return pStmt->errCode; - } - - if (STMT_TYPE_QUERY == pStmt->sql.type) { - tscError("invalid operation to get query tag fileds"); - STMT_ERR_RET(TSDB_CODE_TSC_STMT_API_ERROR); - } - - STableDataCxt** pDataBlock = - (STableDataCxt**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName)); - if (NULL == pDataBlock) { - tscError("table %s not found in exec blockHash", pStmt->bInfo.tbFName); - STMT_ERR_RET(TSDB_CODE_APP_ERROR); - } - - STMT_ERR_RET(qBuildStmtTagFields(*pDataBlock, pStmt->bInfo.boundTags, fieldNum, fields)); - - return TSDB_CODE_SUCCESS; -} - static int stmtFetchColFields2(STscStmt2* pStmt, int32_t* fieldNum, TAOS_FIELD_E** fields) { if (pStmt->errCode != TSDB_CODE_SUCCESS) { return pStmt->errCode; @@ -1819,47 +1797,6 @@ int stmtAffectedRows(TAOS_STMT* stmt) { return ((STscStmt2*)stmt)->affectedRows; int stmtAffectedRowsOnce(TAOS_STMT* stmt) { return ((STscStmt2*)stmt)->exec.affectedRows; } */ -int stmtGetTagFields2(TAOS_STMT2* stmt, int* nums, TAOS_FIELD_E** fields) { - int32_t code = 0; - STscStmt2* pStmt = (STscStmt2*)stmt; - int32_t preCode = pStmt->errCode; - - STMT_DLOG_E("start to get tag fields"); - - if (pStmt->errCode != TSDB_CODE_SUCCESS) { - return pStmt->errCode; - } - - if (STMT_TYPE_QUERY == pStmt->sql.type) { - STMT_ERRI_JRET(TSDB_CODE_TSC_STMT_API_ERROR); - } - - STMT_ERRI_JRET(stmtSwitchStatus(pStmt, STMT_FETCH_FIELDS)); - - if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 && - STMT_TYPE_MULTI_INSERT != pStmt->sql.type) { - pStmt->bInfo.needParse = false; - } - - if (pStmt->exec.pRequest && STMT_TYPE_QUERY == pStmt->sql.type && pStmt->sql.runTimes) { - taos_free_result(pStmt->exec.pRequest); - pStmt->exec.pRequest = NULL; - } - - STMT_ERRI_JRET(stmtCreateRequest(pStmt)); - - if (pStmt->bInfo.needParse) { - STMT_ERRI_JRET(stmtParseSql(pStmt)); - } - - STMT_ERRI_JRET(stmtFetchTagFields2(stmt, nums, fields)); - -_return: - - pStmt->errCode = preCode; - - return code; -} int stmtParseColFields2(TAOS_STMT2* stmt) { int32_t code = 0; @@ -1902,15 +1839,6 @@ _return: return code; } -int stmtGetColFields2(TAOS_STMT2* stmt, int* nums, TAOS_FIELD_E** fields) { - int32_t code = stmtParseColFields2(stmt); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - - return stmtFetchColFields2(stmt, nums, fields); -} - int stmtGetStbColFields2(TAOS_STMT2* stmt, int* nums, TAOS_FIELD_ALL** fields) { int32_t code = stmtParseColFields2(stmt); if (code != TSDB_CODE_SUCCESS) { @@ -1956,95 +1884,6 @@ int stmtGetParamNum2(TAOS_STMT2* stmt, int* nums) { return TSDB_CODE_SUCCESS; } -int stmtGetParamTbName(TAOS_STMT2* stmt, int* nums) { - STscStmt2* pStmt = (STscStmt2*)stmt; - int32_t code = 0; - int32_t preCode = pStmt->errCode; - - STMT_DLOG_E("start to get param num"); - - if (pStmt->errCode != TSDB_CODE_SUCCESS) { - return pStmt->errCode; - } - - STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_FETCH_FIELDS)); - - if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 && - STMT_TYPE_MULTI_INSERT != pStmt->sql.type) { - pStmt->bInfo.needParse = false; - } - - if (pStmt->exec.pRequest && STMT_TYPE_QUERY == pStmt->sql.type && pStmt->sql.runTimes) { - taos_free_result(pStmt->exec.pRequest); - pStmt->exec.pRequest = NULL; - } - - STMT_ERR_RET(stmtCreateRequest(pStmt)); - - if (pStmt->bInfo.needParse) { - STMT_ERRI_JRET(stmtParseSql(pStmt)); - } - - *nums = STMT_TYPE_MULTI_INSERT == pStmt->sql.type ? 1 : 0; - -_return: - if (TSDB_CODE_TSC_STMT_TBNAME_ERROR == code) { - *nums = 1; - code = TSDB_CODE_SUCCESS; - } - - pStmt->errCode = preCode; - return code; -} -/* -int stmtGetParam(TAOS_STMT* stmt, int idx, int* type, int* bytes) { - STscStmt2* pStmt = (STscStmt2*)stmt; - - STMT_DLOG_E("start to get param"); - - if (pStmt->errCode != TSDB_CODE_SUCCESS) { - return pStmt->errCode; - } - - if (STMT_TYPE_QUERY == pStmt->sql.type) { - STMT_RET(TSDB_CODE_TSC_STMT_API_ERROR); - } - - STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_FETCH_FIELDS)); - - if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 && - STMT_TYPE_MULTI_INSERT != pStmt->sql.type) { - pStmt->bInfo.needParse = false; - } - - if (pStmt->exec.pRequest && STMT_TYPE_QUERY == pStmt->sql.type && pStmt->sql.runTimes) { - taos_free_result(pStmt->exec.pRequest); - pStmt->exec.pRequest = NULL; - } - - STMT_ERR_RET(stmtCreateRequest(pStmt)); - - if (pStmt->bInfo.needParse) { - STMT_ERR_RET(stmtParseSql(pStmt)); - } - - int32_t nums = 0; - TAOS_FIELD_E* pField = NULL; - STMT_ERR_RET(stmtFetchColFields(stmt, &nums, &pField)); - if (idx >= nums) { - tscError("idx %d is too big", idx); - taosMemoryFree(pField); - STMT_ERR_RET(TSDB_CODE_INVALID_PARA); - } - - *type = pField[idx].type; - *bytes = pField[idx].bytes; - - taosMemoryFree(pField); - - return TSDB_CODE_SUCCESS; -} -*/ TAOS_RES* stmtUseResult2(TAOS_STMT2* stmt) { STscStmt2* pStmt = (STscStmt2*)stmt; diff --git a/source/client/test/stmt2Test.cpp b/source/client/test/stmt2Test.cpp index c325ed3a38..267b777ff3 100644 --- a/source/client/test/stmt2Test.cpp +++ b/source/client/test/stmt2Test.cpp @@ -27,10 +27,17 @@ #pragma GCC diagnostic ignored "-Wunused-variable" #pragma GCC diagnostic ignored "-Wsign-compare" +#include "../inc/clientStmt.h" +#include "../inc/clientStmt2.h" #include "executor.h" #include "taos.h" namespace { +void stmtAsyncQueryCb(void* param, TAOS_RES* pRes, int code) { + int affected_rows = taos_affected_rows(pRes); + return; +} + void getFieldsSuccess(TAOS* taos, const char* sql, TAOS_FIELD_ALL* expectedFields, int expectedFieldNum) { TAOS_STMT2_OPTION option = {0}; TAOS_STMT2* stmt = taos_stmt2_init(taos, &option); @@ -55,28 +62,35 @@ void getFieldsSuccess(TAOS* taos, const char* sql, TAOS_FIELD_ALL* expectedField taos_stmt2_close(stmt); } -void getQueryFields(TAOS* taos, const char* sql) { +void getFieldsError(TAOS* taos, const char* sql, int errorCode) { TAOS_STMT2_OPTION option = {0}; TAOS_STMT2* stmt = taos_stmt2_init(taos, &option); int code = taos_stmt2_prepare(stmt, sql, 0); - if (code != 0) { - printf("failed to execute taos_stmt2_prepare. error:%s\n", taos_stmt2_error(stmt)); - taos_stmt2_close(stmt); - return; - } + ASSERT_EQ(code, 0); + int fieldNum = 0; TAOS_FIELD_ALL* pFields = NULL; code = taos_stmt2_get_fields(stmt, &fieldNum, &pFields); - if (code != 0) { - printf("failed get col,ErrCode: 0x%x, ErrMessage: %s.\n", code, taos_stmt2_error(stmt)); - } else { - printf("bind nums:%d\n", fieldNum); - } - printf("====================================\n"); + ASSERT_EQ(code, errorCode); taos_stmt2_free_fields(stmt, pFields); taos_stmt2_close(stmt); } +void getQueryFields(TAOS* taos, const char* sql, int expectedFieldNum) { + TAOS_STMT2_OPTION option = {0}; + TAOS_STMT2* stmt = taos_stmt2_init(taos, &option); + int code = taos_stmt2_prepare(stmt, sql, 0); + ASSERT_EQ(code, 0); + + int fieldNum = 0; + TAOS_FIELD_ALL* pFields = NULL; + code = taos_stmt2_get_fields(stmt, &fieldNum, NULL); + ASSERT_EQ(code, 0); + ASSERT_EQ(fieldNum, expectedFieldNum); + taos_stmt2_free_fields(stmt, NULL); + taos_stmt2_close(stmt); +} + void do_query(TAOS* taos, const char* sql) { TAOS_RES* result = taos_query(taos, sql); int code = taos_errno(result); @@ -169,94 +183,134 @@ TEST(stmt2Case, insert_stb_get_fields_Test) { do_query(taos, "drop database if exists db"); do_query(taos, "create database db PRECISION 'ns'"); - do_query(taos, "use db"); do_query(taos, "create table db.stb (ts timestamp, b binary(10)) tags(t1 " "int, t2 binary(10))"); do_query( taos, - "create table if not exists all_stb(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 bigint, v6 " + "create table if not exists db.all_stb(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 bigint, v6 " "tinyint unsigned, v7 smallint unsigned, v8 int unsigned, v9 bigint unsigned, v10 float, v11 double, v12 " "binary(20), v13 varbinary(20), v14 geometry(100), v15 nchar(20))tags(tts timestamp, tv1 bool, tv2 tinyint, tv3 " "smallint, tv4 int, tv5 bigint, tv6 tinyint unsigned, tv7 smallint unsigned, tv8 int unsigned, tv9 bigint " "unsigned, tv10 float, tv11 double, tv12 binary(20), tv13 varbinary(20), tv14 geometry(100), tv15 nchar(20));"); + printf("support case \n"); - // // case 1 : test super table - // { - // const char* sql = "insert into db.stb(t1,t2,ts,b,tbname) values(?,?,?,?,?)"; - // TAOS_FIELD_ALL expectedFields[5] = {{"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG}, - // {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG}, - // {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}, - // {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}, - // {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}}; - // printf("case 1 : %s\n", sql); - // getFieldsSuccess(taos, sql, expectedFields, 5); - // } - - // case 2 : no tbname + // case 1 : test super table { - const char* sql = "insert into db.stb(t1,t2,ts,b,tbname) values(1,?,?,'abc',?)"; - TAOS_FIELD_ALL expectedFields[3] = {{"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG}, + const char* sql = "insert into db.stb(t1,t2,ts,b,tbname) values(?,?,?,?,?)"; + TAOS_FIELD_ALL expectedFields[5] = {{"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG}, + {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG}, {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}, + {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}, + {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}}; + printf("case 1 : %s\n", sql); + getFieldsSuccess(taos, sql, expectedFields, 5); + } + + { + // case 2 : no tag + const char* sql = "insert into db.stb(ts,b,tbname) values(?,?,?)"; + TAOS_FIELD_ALL expectedFields[3] = {{"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}, + {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}, {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}}; printf("case 2 : %s\n", sql); getFieldsSuccess(taos, sql, expectedFields, 3); } + // case 3 : random order { - // case 3 : insert into db.stb(ts,b,tbname) values(?,?,?) - // no tag - const char* sql = "insert into db.stb(ts,b,tbname) values(?,?,?)"; - TAOS_FIELD_ALL expectedFields[3] = { - {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}, - {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}, - {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}, - }; - printf("case 5 : %s\n", sql); - getFieldsSuccess(taos, sql, expectedFields, 3); + const char* sql = "insert into db.stb(tbname,ts,t2,b,t1) values(?,?,?,?,?)"; + TAOS_FIELD_ALL expectedFields[5] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}, + {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}, + {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG}, + {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}, + {"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG}}; + printf("case 3 : %s\n", sql); + getFieldsSuccess(taos, sql, expectedFields, 5); } - // case 12 : insert into ? using all_stb tags(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) - // values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) - // test all types + // case 4 : random order { - const char* sql = - "insert into ? using all_stb tags(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; - TAOS_FIELD_ALL expectedFields[33] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}, - {"tts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_TAG}, - {"tv1", TSDB_DATA_TYPE_BOOL, 0, 0, 1, TAOS_FIELD_TAG}, - {"tv2", TSDB_DATA_TYPE_TINYINT, 0, 0, 1, TAOS_FIELD_TAG}, - {"tv3", TSDB_DATA_TYPE_SMALLINT, 0, 0, 2, TAOS_FIELD_TAG}, - {"tv4", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG}, - {"tv5", TSDB_DATA_TYPE_BIGINT, 0, 0, 8, TAOS_FIELD_TAG}, - {"tv6", TSDB_DATA_TYPE_UTINYINT, 0, 0, 1, TAOS_FIELD_TAG}, - {"tv7", TSDB_DATA_TYPE_USMALLINT, 0, 0, 2, TAOS_FIELD_TAG}, - {"tv8", TSDB_DATA_TYPE_UINT, 0, 0, 4, TAOS_FIELD_TAG}, - {"tv9", TSDB_DATA_TYPE_UBIGINT, 0, 0, 8, TAOS_FIELD_TAG}, - {"tv10", TSDB_DATA_TYPE_FLOAT, 0, 0, 4, TAOS_FIELD_TAG}, - {"tv11", TSDB_DATA_TYPE_DOUBLE, 0, 0, 8, TAOS_FIELD_TAG}, - {"tv12", TSDB_DATA_TYPE_VARCHAR, 0, 0, 22, TAOS_FIELD_TAG}, - {"tv13", TSDB_DATA_TYPE_VARBINARY, 0, 0, 22, TAOS_FIELD_TAG}, - {"tv14", TSDB_DATA_TYPE_GEOMETRY, 0, 0, 102, TAOS_FIELD_TAG}, - {"tv15", TSDB_DATA_TYPE_NCHAR, 0, 0, 82, TAOS_FIELD_TAG}, - {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}, - {"v1", TSDB_DATA_TYPE_BOOL, 0, 0, 1, TAOS_FIELD_COL}, - {"v2", TSDB_DATA_TYPE_TINYINT, 0, 0, 1, TAOS_FIELD_COL}, - {"v3", TSDB_DATA_TYPE_SMALLINT, 0, 0, 2, TAOS_FIELD_COL}, - {"v4", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_COL}, - {"v5", TSDB_DATA_TYPE_BIGINT, 0, 0, 8, TAOS_FIELD_COL}, - {"v6", TSDB_DATA_TYPE_UTINYINT, 0, 0, 1, TAOS_FIELD_COL}, - {"v7", TSDB_DATA_TYPE_USMALLINT, 0, 0, 2, TAOS_FIELD_COL}, - {"v8", TSDB_DATA_TYPE_UINT, 0, 0, 4, TAOS_FIELD_COL}, - {"v9", TSDB_DATA_TYPE_UBIGINT, 0, 0, 8, TAOS_FIELD_COL}, - {"v10", TSDB_DATA_TYPE_FLOAT, 0, 0, 4, TAOS_FIELD_COL}, - {"v11", TSDB_DATA_TYPE_DOUBLE, 0, 0, 8, TAOS_FIELD_COL}, - {"v12", TSDB_DATA_TYPE_VARCHAR, 0, 0, 22, TAOS_FIELD_COL}, - {"v13", TSDB_DATA_TYPE_VARBINARY, 0, 0, 22, TAOS_FIELD_COL}, - {"v14", TSDB_DATA_TYPE_GEOMETRY, 0, 0, 102, TAOS_FIELD_COL}, - {"v15", TSDB_DATA_TYPE_NCHAR, 0, 0, 82, TAOS_FIELD_COL}}; - printf("case 12 : %s\n", sql); - getFieldsSuccess(taos, sql, expectedFields, 33); + const char* sql = "insert into db.stb(tbname,ts,t2,b,t1) values(?,?,?,?,?)"; + TAOS_FIELD_ALL expectedFields[5] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}, + {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}, + {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG}, + {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}, + {"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG}}; + printf("case 4 : %s\n", sql); + getFieldsSuccess(taos, sql, expectedFields, 5); + } + + // case 5 : 'db'.'stb' + { + const char* sql = "insert into 'db'.'stb'(t1,t2,ts,b,tbname) values(?,?,?,?,?)"; + TAOS_FIELD_ALL expectedFields[5] = {{"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG}, + {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG}, + {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}, + {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}, + {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}}; + printf("case 5 : %s\n", sql); + getFieldsSuccess(taos, sql, expectedFields, 5); + } + + // case 6 : use db + { + do_query(taos, "use db"); + const char* sql = "insert into stb(t1,t2,ts,b,tbname) values(?,?,?,?,?)"; + TAOS_FIELD_ALL expectedFields[5] = {{"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG}, + {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG}, + {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}, + {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}, + {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}}; + printf("case 6 : %s\n", sql); + getFieldsSuccess(taos, sql, expectedFields, 5); + } + + // case 7 : less param + { + const char* sql = "insert into db.stb(ts,tbname) values(?,?)"; + TAOS_FIELD_ALL expectedFields[2] = {{"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}, + {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}}; + printf("case 7 : %s\n", sql); + getFieldsSuccess(taos, sql, expectedFields, 2); + } + + // not support case + printf("not support case \n"); + + // case 5 : add in main TD-33353 + // { + // const char* sql = "insert into db.stb(t1,t2,ts,b,tbname) values(1,?,?,'abc',?)"; + // printf("case 2 : %s\n", sql); + // getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION); + // } + + // case 7 : no pk + { + const char* sql = "insert into db.stb(b,tbname) values(?,?)"; + printf("case 7 : %s\n", sql); + getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION); + } + + // case 5 : no tbname and tag(not support bind) + { + const char* sql = "insert into db.stb(ts,b) values(?,?)"; + printf("case 5 : %s\n", sql); + getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION); + } + + // case 5 : no tbname and tag(not support bind) + { + const char* sql = "insert into db.stb(tbname) values(?)"; + printf("case 5 : %s\n", sql); + getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION); + } + + // case 8 : no param + { + const char* sql = "insert into db.stb(?,?,?,?,?)"; + printf("case 8 : %s\n", sql); + getFieldsError(taos, sql, TSDB_CODE_PAR_SYNTAX_ERROR); } taos_close(taos); @@ -356,6 +410,49 @@ TEST(stmt2Case, insert_ctb_using_get_fields_Test) { // // "v11,v12,v13,v14,v15) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; // // printf("case 13 : %s\n", sql); // // getFields(taos, sql); + + // case 12 : insert into ? using all_stb tags(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) + // values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) + // test all types + // { + // const char* sql = + // "insert into ? using all_stb tags(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + // TAOS_FIELD_ALL expectedFields[33] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}, + // {"tts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_TAG}, + // {"tv1", TSDB_DATA_TYPE_BOOL, 0, 0, 1, TAOS_FIELD_TAG}, + // {"tv2", TSDB_DATA_TYPE_TINYINT, 0, 0, 1, TAOS_FIELD_TAG}, + // {"tv3", TSDB_DATA_TYPE_SMALLINT, 0, 0, 2, TAOS_FIELD_TAG}, + // {"tv4", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG}, + // {"tv5", TSDB_DATA_TYPE_BIGINT, 0, 0, 8, TAOS_FIELD_TAG}, + // {"tv6", TSDB_DATA_TYPE_UTINYINT, 0, 0, 1, TAOS_FIELD_TAG}, + // {"tv7", TSDB_DATA_TYPE_USMALLINT, 0, 0, 2, TAOS_FIELD_TAG}, + // {"tv8", TSDB_DATA_TYPE_UINT, 0, 0, 4, TAOS_FIELD_TAG}, + // {"tv9", TSDB_DATA_TYPE_UBIGINT, 0, 0, 8, TAOS_FIELD_TAG}, + // {"tv10", TSDB_DATA_TYPE_FLOAT, 0, 0, 4, TAOS_FIELD_TAG}, + // {"tv11", TSDB_DATA_TYPE_DOUBLE, 0, 0, 8, TAOS_FIELD_TAG}, + // {"tv12", TSDB_DATA_TYPE_VARCHAR, 0, 0, 22, TAOS_FIELD_TAG}, + // {"tv13", TSDB_DATA_TYPE_VARBINARY, 0, 0, 22, TAOS_FIELD_TAG}, + // {"tv14", TSDB_DATA_TYPE_GEOMETRY, 0, 0, 102, TAOS_FIELD_TAG}, + // {"tv15", TSDB_DATA_TYPE_NCHAR, 0, 0, 82, TAOS_FIELD_TAG}, + // {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}, + // {"v1", TSDB_DATA_TYPE_BOOL, 0, 0, 1, TAOS_FIELD_COL}, + // {"v2", TSDB_DATA_TYPE_TINYINT, 0, 0, 1, TAOS_FIELD_COL}, + // {"v3", TSDB_DATA_TYPE_SMALLINT, 0, 0, 2, TAOS_FIELD_COL}, + // {"v4", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_COL}, + // {"v5", TSDB_DATA_TYPE_BIGINT, 0, 0, 8, TAOS_FIELD_COL}, + // {"v6", TSDB_DATA_TYPE_UTINYINT, 0, 0, 1, TAOS_FIELD_COL}, + // {"v7", TSDB_DATA_TYPE_USMALLINT, 0, 0, 2, TAOS_FIELD_COL}, + // {"v8", TSDB_DATA_TYPE_UINT, 0, 0, 4, TAOS_FIELD_COL}, + // {"v9", TSDB_DATA_TYPE_UBIGINT, 0, 0, 8, TAOS_FIELD_COL}, + // {"v10", TSDB_DATA_TYPE_FLOAT, 0, 0, 4, TAOS_FIELD_COL}, + // {"v11", TSDB_DATA_TYPE_DOUBLE, 0, 0, 8, TAOS_FIELD_COL}, + // {"v12", TSDB_DATA_TYPE_VARCHAR, 0, 0, 22, TAOS_FIELD_COL}, + // {"v13", TSDB_DATA_TYPE_VARBINARY, 0, 0, 22, TAOS_FIELD_COL}, + // {"v14", TSDB_DATA_TYPE_GEOMETRY, 0, 0, 102, TAOS_FIELD_COL}, + // {"v15", TSDB_DATA_TYPE_NCHAR, 0, 0, 82, TAOS_FIELD_COL}}; + // printf("case 12 : %s\n", sql); + // getFieldsSuccess(taos, sql, expectedFields, 33); + // } } TEST(stmt2Case, insert_ntb_get_fields_Test) { @@ -388,30 +485,87 @@ TEST(stmt2Case, insert_ntb_get_fields_Test) { } TEST(stmt2Case, select_get_fields_Test) { - // // case 14 : select * from ntb where ts = ? - // // query type - // sql = "select * from ntb where ts = ?"; - // printf("case 14 : %s\n", sql); - // getQueryFields(taos, sql); + TAOS* taos = taos_connect("localhost", "root", "taosdata", NULL, 0); + ASSERT_NE(taos, nullptr); + do_query(taos, "drop database if exists db"); + do_query(taos, "create database db PRECISION 'ns'"); + do_query(taos, "use db"); + do_query(taos, "CREATE TABLE db.ntb(nts timestamp, nb binary(10),nvc varchar(16),ni int);"); + { + // case 1 : select * from ntb where ts = ? + // query type + const char* sql = "select * from ntb where ts = ?"; + printf("case 1 : %s\n", sql); + getQueryFields(taos, sql, 1); + } - // // case 15 : select * from ntb where ts = ? and b = ? - // // query type - // sql = "select * from ntb where ts = ? and b = ?"; - // printf("case 15 : %s\n", sql); - // getQueryFields(taos, sql); + { + // case 2 : select * from ntb where ts = ? and b = ? + // query type + const char* sql = "select * from ntb where ts = ? and b = ?"; + printf("case 2 : %s\n", sql); + getQueryFields(taos, sql, 2); + } } -TEST(stmt2Case, db_get_fields_Test) {} - TEST(stmt2Case, get_fields_error_Test) { - // { - // const char* sql = "insert into db.stb(t1,t2,ts,b,tbname) values(1,?,?,'abc',?)"; - // TAOS_FIELD_ALL expectedFields[3] = {{"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG}, - // {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}, - // {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}}; - // printf("case 2 : %s\n", sql); - // getFieldsSuccess(taos, sql, expectedFields, 3); - // } + // case 1 : + { + printf("case 1 : NULL param \n"); + int code = taos_stmt2_get_fields(NULL, NULL, NULL); + ASSERT_EQ(code, TSDB_CODE_INVALID_PARA); + } } +TEST(stmt2Case, stmt2_init_prepare_Test) { + TAOS* taos = taos_connect("localhost", "root", "taosdata", NULL, 0); + + { + (void)taos_stmt2_init(NULL, NULL); + ASSERT_EQ(terrno, TSDB_CODE_INVALID_PARA); + terrno = 0; + } + + { + (void)taos_stmt2_prepare(NULL, NULL, 0); + ASSERT_EQ(terrno, TSDB_CODE_INVALID_PARA); + terrno = 0; + } + + { + TAOS_STMT2_OPTION option = {0, true, true, NULL, NULL}; + TAOS_STMT2* stmt = taos_stmt2_init(taos, &option); + ASSERT_EQ(terrno, 0); + ASSERT_NE(stmt, nullptr); + int code = taos_stmt2_prepare(stmt, "wrong sql", 0); + ASSERT_EQ(terrno, 0); + ASSERT_NE(stmt, nullptr); + ASSERT_EQ(((STscStmt2*)stmt)->db, nullptr); + + code = taos_stmt2_prepare(stmt, "insert into 'db'.stb(t1,t2,ts,b,tbname) values(?,?,?,?,?)", 0); + ASSERT_EQ(terrno, 0); + ASSERT_NE(stmt, nullptr); + // ASSERT_STREQ(((STscStmt2*)stmt)->db, "db"); //add in main TD-33332 + taos_stmt2_close(stmt); + } + + { + TAOS_STMT2_OPTION option = {0, true, false, NULL, NULL}; + TAOS_STMT2* stmt = taos_stmt2_init(taos, &option); + ASSERT_EQ(terrno, 0); + ASSERT_NE(stmt, nullptr); + taos_stmt2_close(stmt); + } + + { + TAOS_STMT2_OPTION option = {0, true, true, stmtAsyncQueryCb, NULL}; + TAOS_STMT2* stmt = taos_stmt2_init(taos, &option); + ASSERT_EQ(terrno, 0); + ASSERT_NE(stmt, nullptr); + taos_stmt2_close(stmt); + } +} + +TEST(stmt2Case, stmt2_status_Test) {} + #pragma GCC diagnostic pop