diff --git a/include/client/taos.h b/include/client/taos.h index e59ea9d418..17f97d3d3d 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -111,14 +111,14 @@ typedef struct TAOS_FIELD_E { int32_t bytes; } TAOS_FIELD_E; -typedef struct TAOS_FIELD_STB { +typedef struct TAOS_FIELD_ALL { char name[65]; int8_t type; uint8_t precision; uint8_t scale; int32_t bytes; uint8_t field_type; -} TAOS_FIELD_STB; +} TAOS_FIELD_ALL; #ifdef WINDOWS #define DLL_EXPORT __declspec(dllexport) @@ -250,10 +250,8 @@ DLL_EXPORT int taos_stmt2_bind_param(TAOS_STMT2 *stmt, TAOS_STMT2_BINDV DLL_EXPORT int taos_stmt2_exec(TAOS_STMT2 *stmt, int *affected_rows); DLL_EXPORT int taos_stmt2_close(TAOS_STMT2 *stmt); DLL_EXPORT int taos_stmt2_is_insert(TAOS_STMT2 *stmt, int *insert); -DLL_EXPORT int taos_stmt2_get_fields(TAOS_STMT2 *stmt, TAOS_FIELD_T field_type, int *count, TAOS_FIELD_E **fields); -DLL_EXPORT int taos_stmt2_get_stb_fields(TAOS_STMT2 *stmt, int *count, TAOS_FIELD_STB **fields); -DLL_EXPORT void taos_stmt2_free_fields(TAOS_STMT2 *stmt, TAOS_FIELD_E *fields); -DLL_EXPORT void taos_stmt2_free_stb_fields(TAOS_STMT2 *stmt, TAOS_FIELD_STB *fields); +DLL_EXPORT int taos_stmt2_get_fields(TAOS_STMT2 *stmt, int *count, TAOS_FIELD_ALL **fields); +DLL_EXPORT void taos_stmt2_free_fields(TAOS_STMT2 *stmt, TAOS_FIELD_ALL *fields); DLL_EXPORT TAOS_RES *taos_stmt2_result(TAOS_STMT2 *stmt); DLL_EXPORT char *taos_stmt2_error(TAOS_STMT2 *stmt); diff --git a/include/libs/parser/parser.h b/include/libs/parser/parser.h index 82985457a8..95f522f504 100644 --- a/include/libs/parser/parser.h +++ b/include/libs/parser/parser.h @@ -150,7 +150,7 @@ int32_t qBindStmtSingleColValue(void* pBlock, SArray* pCols, TAOS_MULTI_BIND* bi int32_t colIdx, int32_t rowNum, void* charsetCxt); int32_t qBuildStmtColFields(void* pDataBlock, int32_t* fieldNum, TAOS_FIELD_E** fields); int32_t qBuildStmtStbColFields(void* pBlock, void* boundTags, bool hasCtbName, int32_t* fieldNum, - TAOS_FIELD_STB** fields); + TAOS_FIELD_ALL** fields); int32_t qBuildStmtTagFields(void* pBlock, void* boundTags, int32_t* fieldNum, TAOS_FIELD_E** fields); int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const char* sTableName, char* tName, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen, void* charsetCxt); diff --git a/source/client/inc/clientStmt2.h b/source/client/inc/clientStmt2.h index 64abf31bc1..c42de739c6 100644 --- a/source/client/inc/clientStmt2.h +++ b/source/client/inc/clientStmt2.h @@ -222,7 +222,7 @@ 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_STB **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); diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index d80c7df2e4..c98b89dad4 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -2249,29 +2249,29 @@ 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; - } +// 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; - } -} +// 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_stb_fields(TAOS_STMT2 *stmt, int *count, TAOS_FIELD_STB **fields) { +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__); terrno = TSDB_CODE_INVALID_PARA; @@ -2293,13 +2293,7 @@ int taos_stmt2_get_stb_fields(TAOS_STMT2 *stmt, int *count, TAOS_FIELD_STB **fie return stmtGetStbColFields2(stmt, count, fields); } -void taos_stmt2_free_fields(TAOS_STMT2 *stmt, TAOS_FIELD_E *fields) { - (void)stmt; - if (!fields) return; - taosMemoryFree(fields); -} - -DLL_EXPORT void taos_stmt2_free_stb_fields(TAOS_STMT2 *stmt, TAOS_FIELD_STB *fields) { +DLL_EXPORT void taos_stmt2_free_fields(TAOS_STMT2 *stmt, TAOS_FIELD_ALL *fields) { (void)stmt; if (!fields) return; taosMemoryFree(fields); diff --git a/source/client/src/clientStmt2.c b/source/client/src/clientStmt2.c index f03879f199..bae9c6da88 100644 --- a/source/client/src/clientStmt2.c +++ b/source/client/src/clientStmt2.c @@ -1070,7 +1070,7 @@ static int stmtFetchColFields2(STscStmt2* pStmt, int32_t* fieldNum, TAOS_FIELD_E return TSDB_CODE_SUCCESS; } -static int stmtFetchStbColFields2(STscStmt2* pStmt, int32_t* fieldNum, TAOS_FIELD_STB** fields) { +static int stmtFetchStbColFields2(STscStmt2* pStmt, int32_t* fieldNum, TAOS_FIELD_ALL** fields) { if (pStmt->errCode != TSDB_CODE_SUCCESS) { return pStmt->errCode; } @@ -1894,7 +1894,7 @@ int stmtGetColFields2(TAOS_STMT2* stmt, int* nums, TAOS_FIELD_E** fields) { return stmtFetchColFields2(stmt, nums, fields); } -int stmtGetStbColFields2(TAOS_STMT2* stmt, int* nums, TAOS_FIELD_STB** fields) { +int stmtGetStbColFields2(TAOS_STMT2* stmt, int* nums, TAOS_FIELD_ALL** fields) { int32_t code = stmtParseColFields2(stmt); if (code != TSDB_CODE_SUCCESS) { return code; diff --git a/source/libs/parser/src/parInsertStmt.c b/source/libs/parser/src/parInsertStmt.c index 9e6abe1517..fae5caaff0 100644 --- a/source/libs/parser/src/parInsertStmt.c +++ b/source/libs/parser/src/parInsertStmt.c @@ -938,13 +938,17 @@ int32_t buildBoundFields(int32_t numOfBound, int16_t* boundColumns, SSchema* pSc return TSDB_CODE_SUCCESS; } -int32_t buildStbBoundFields(SBoundColInfo boundColsInfo, SSchema* pSchema, int32_t* fieldNum, TAOS_FIELD_STB** fields, +int32_t buildStbBoundFields(SBoundColInfo boundColsInfo, SSchema* pSchema, int32_t* fieldNum, TAOS_FIELD_ALL** fields, STableMeta* pMeta, void* boundTags, bool preCtbname) { SBoundColInfo* tags = (SBoundColInfo*)boundTags; - int32_t numOfBound = boundColsInfo.numOfBound + (tags->mixTagsCols ? 0 : tags->numOfBound) + (preCtbname ? 1 : 0); + bool hastag = tags != NULL; + int32_t numOfBound = boundColsInfo.numOfBound + (preCtbname ? 1 : 0); + if (hastag) { + numOfBound += tags->mixTagsCols ? 0 : tags->numOfBound; + } int32_t idx = 0; if (fields != NULL) { - *fields = taosMemoryCalloc(numOfBound, sizeof(TAOS_FIELD_STB)); + *fields = taosMemoryCalloc(numOfBound, sizeof(TAOS_FIELD_ALL)); if (NULL == *fields) { return terrno; } @@ -957,7 +961,7 @@ int32_t buildStbBoundFields(SBoundColInfo boundColsInfo, SSchema* pSchema, int32 idx++; } - if (tags->numOfBound > 0 && !tags->mixTagsCols) { + if (hastag && tags->numOfBound > 0 && !tags->mixTagsCols) { SSchema* tagSchema = getTableTagSchema(pMeta); for (int32_t i = 0; i < tags->numOfBound; ++i) { @@ -1054,7 +1058,7 @@ int32_t qBuildStmtColFields(void* pBlock, int32_t* fieldNum, TAOS_FIELD_E** fiel } int32_t qBuildStmtStbColFields(void* pBlock, void* boundTags, bool preCtbname, int32_t* fieldNum, - TAOS_FIELD_STB** fields) { + TAOS_FIELD_ALL** fields) { STableDataCxt* pDataBlock = (STableDataCxt*)pBlock; SSchema* pSchema = getTableColumnSchema(pDataBlock->pMeta); if (pDataBlock->boundColsInfo.numOfBound <= 0) { diff --git a/tests/script/api/stmt2-example.c b/tests/script/api/stmt2-example.c index 692ff90a06..611de1ebc3 100644 --- a/tests/script/api/stmt2-example.c +++ b/tests/script/api/stmt2-example.c @@ -58,8 +58,8 @@ void do_stmt(TAOS* taos) { } int fieldNum = 0; - TAOS_FIELD_STB* pFields = NULL; - code = taos_stmt2_get_stb_fields(stmt, &fieldNum, &pFields); + 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 { @@ -70,6 +70,7 @@ void do_stmt(TAOS* taos) { } } + int64_t ts = 1591060628000; for (int i = 0; i < 2; ++i) { v.ts[i] = ts++; @@ -88,6 +89,7 @@ void do_stmt(TAOS* taos) { return; } + taos_stmt2_free_fields(stmt, pFields); taos_stmt2_close(stmt); } diff --git a/tests/script/api/stmt2-get-fields.c b/tests/script/api/stmt2-get-fields.c index df677eba1a..e14c0e2265 100755 --- a/tests/script/api/stmt2-get-fields.c +++ b/tests/script/api/stmt2-get-fields.c @@ -16,8 +16,8 @@ void getFields(TAOS *taos, const char *sql) { return; } int fieldNum = 0; - TAOS_FIELD_STB *pFields = NULL; - code = taos_stmt2_get_stb_fields(stmt, &fieldNum, &pFields); + 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 { @@ -28,7 +28,7 @@ void getFields(TAOS *taos, const char *sql) { } } printf("====================================\n"); - taos_stmt2_free_stb_fields(stmt, pFields); + taos_stmt2_free_fields(stmt, pFields); taos_stmt2_close(stmt); } @@ -42,15 +42,15 @@ void getQueryFields(TAOS *taos, const char *sql) { return; } int fieldNum = 0; - TAOS_FIELD_STB *pFields = NULL; - code = taos_stmt2_get_stb_fields(stmt, &fieldNum, &pFields); + 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"); - taos_stmt2_free_stb_fields(stmt, pFields); + taos_stmt2_free_fields(stmt, pFields); taos_stmt2_close(stmt); } diff --git a/tests/script/api/stmt2-nchar.c b/tests/script/api/stmt2-nchar.c index 3952bd5898..0f402517bf 100644 --- a/tests/script/api/stmt2-nchar.c +++ b/tests/script/api/stmt2-nchar.c @@ -205,11 +205,11 @@ void veriry_stmt(TAOS* taos) { return; } printf("param_count: %d\n", param_count); - */ - TAOS_FIELD_E* fields = NULL; + */ + TAOS_FIELD_ALL* fields = NULL; int field_count = -1; start = clock(); - code = taos_stmt2_get_fields(stmt, TAOS_FIELD_COL, &field_count, NULL); + code = taos_stmt2_get_fields(stmt, &field_count, &fields); end = clock(); printf("get fields time:%f\n", (double)(end - start) / CLOCKS_PER_SEC); if (code != 0) { diff --git a/tests/script/api/stmt2-nohole.c b/tests/script/api/stmt2-nohole.c index 5954f3660b..4bf0aae959 100644 --- a/tests/script/api/stmt2-nohole.c +++ b/tests/script/api/stmt2-nohole.c @@ -292,10 +292,10 @@ _bind_again: } printf("param_count: %d\n", param_count); */ - TAOS_FIELD_E* fields = NULL; + TAOS_FIELD_ALL* fields = NULL; int field_count = -1; start = clock(); - code = taos_stmt2_get_fields(stmt, TAOS_FIELD_TBNAME, &field_count, NULL); + code = taos_stmt2_get_fields(stmt, &field_count, &fields); end = clock(); printf("get fields time:%f\n", (double)(end - start) / CLOCKS_PER_SEC); if (code != 0) { diff --git a/tests/script/api/stmt2-test.c b/tests/script/api/stmt2-test.c index 2bbceec92e..d4e617ef66 100644 --- a/tests/script/api/stmt2-test.c +++ b/tests/script/api/stmt2-test.c @@ -35,8 +35,8 @@ typedef struct { } FuncInfo; typedef enum { - BP_BIND_TAG = 1, - BP_BIND_COL, + BP_BIND_COL = 1, + BP_BIND_TAG, } BP_BIND_TYPE; #define BP_BIND_TYPE_STR(t) (((t) == BP_BIND_COL) ? "column" : "tag") @@ -385,7 +385,7 @@ void *taosMemoryMalloc(uint64_t size) { return malloc(size); } void *taosMemoryCalloc(int32_t num, int32_t size) { return calloc(num, size); } void taosMemoryFree(const void *ptr) { - if (ptr == NULL) return; + if (ptr == NULL) return; return free((void *)ptr); } @@ -1303,23 +1303,23 @@ static int st_stmt2_exec(TAOS_STMT2 *stmt, int *affected_rows) { return taos_stm static int st_stmt2_is_insert(TAOS_STMT2 *stmt, int *insert) { return taos_stmt2_is_insert(stmt, insert); } -static int st_stmt2_num_params(TAOS_STMT2 *stmt, int *count) { - return taos_stmt2_get_fields(stmt, TAOS_FIELD_QUERY, count, NULL); -} +// static int st_stmt2_num_params(TAOS_STMT2 *stmt, int *count) { +// return taos_stmt2_get_fields(stmt, count, NULL); +// } -static int st_stmt2_get_tag_fields(TAOS_STMT2 *stmt, int *count, TAOS_FIELD_E **fields) { - return taos_stmt2_get_fields(stmt, TAOS_FIELD_TAG, count, fields); -} +// static int st_stmt2_get_tag_fields(TAOS_STMT2 *stmt, int *count, TAOS_FIELD_ALL **fields) { +// return taos_stmt2_get_fields(stmt, count, fields); +// } -static int st_stmt2_get_col_fields(TAOS_STMT2 *stmt, int *count, TAOS_FIELD_E **fields) { - return taos_stmt2_get_fields(stmt, TAOS_FIELD_COL, count, fields); -} +// static int st_stmt2_get_col_fields(TAOS_STMT2 *stmt, int *count, TAOS_FIELD_E **fields) { +// return taos_stmt2_get_fields(stmt, TAOS_FIELD_COL, count, fields); +// } static int st_stmt2_get_param(TAOS_STMT2 *stmt, int idx, int *type, int *bytes) { - int32_t code = 0, nums = 0; - TAOS_FIELD_E *fields = NULL; + int32_t code = 0, nums = 0; + TAOS_FIELD_ALL *fields = NULL; - code = taos_stmt2_get_fields(stmt, TAOS_FIELD_COL, &nums, &fields); + code = taos_stmt2_get_fields(stmt, &nums, &fields); if (code) { return code; } @@ -1398,8 +1398,8 @@ void bpCheckIsInsert(TAOS_STMT2 *stmt, int32_t insert) { void bpCheckParamNum(TAOS_STMT2 *stmt) { int32_t num = 0; - if (st_stmt2_num_params(stmt, &num)) { - printf("!!!st_stmt2_num_params error:%s\n", st_stmt2_error(stmt)); + if (taos_stmt2_get_fields(stmt, &num, NULL)) { + printf("!!!taos_stmt2_get_fields error:%s\n", st_stmt2_error(stmt)); exit(1); } @@ -1468,7 +1468,7 @@ void bpCheckQueryResult(TAOS_STMT2 *stmt, TAOS *taos, char *stmtSql, TAOS_STMT2_ printf("***sql res num match stmt res num %d\n", stmtResNum); } -void bpCheckColTagFields(TAOS_STMT2 *stmt, int32_t fieldNum, TAOS_FIELD_E *pFields, int32_t expecteNum, +void bpCheckColTagFields(TAOS_STMT2 *stmt, int32_t fieldNum, TAOS_FIELD_ALL *pFields, int32_t expecteNum, TAOS_STMT2_BIND *pBind, BP_BIND_TYPE type) { int32_t code = 0; @@ -1485,6 +1485,11 @@ void bpCheckColTagFields(TAOS_STMT2 *stmt, int32_t fieldNum, TAOS_FIELD_E *pFiel } for (int32_t i = 0; i < fieldNum; ++i) { + if (pFields[i].field_type != type) { + printf("!!!%s %dth field type %d mis-match expect type %d\n", BP_BIND_TYPE_STR(type), i, pFields[i].field_type, + TAOS_FIELD_TAG); + exit(1); + } if (pFields[i].type != pBind[i].buffer_type) { printf("!!!%s %dth field type %d mis-match expect type %d\n", BP_BIND_TYPE_STR(type), i, pFields[i].type, pBind[i].buffer_type); @@ -1545,17 +1550,17 @@ void bpCheckColTagFields(TAOS_STMT2 *stmt, int32_t fieldNum, TAOS_FIELD_E *pFiel } void bpCheckTagFields(TAOS_STMT2 *stmt, TAOS_STMT2_BIND *pBind) { - int32_t code = 0; - int fieldNum = 0; - TAOS_FIELD_E *pFields = NULL; - code = st_stmt2_get_tag_fields(stmt, &fieldNum, &pFields); + int32_t code = 0; + int fieldNum = 0; + TAOS_FIELD_ALL *pFields = NULL; + code = taos_stmt2_get_fields(stmt, &fieldNum, &pFields); if (code != 0) { - printf("!!!st_stmt2_get_tag_fields error:%s\n", st_stmt2_error(stmt)); + printf("!!!taos_stmt2_get_fields error:%s\n", st_stmt2_error(stmt)); exit(1); } bpCheckColTagFields(stmt, fieldNum, pFields, gCurCase->bindTagNum, pBind, BP_BIND_TAG); - taosMemoryFree(pFields); + taos_stmt2_free_fields(stmt, pFields); } void bpCheckColFields(TAOS_STMT2 *stmt, TAOS_STMT2_BIND *pBind) { @@ -1563,10 +1568,10 @@ void bpCheckColFields(TAOS_STMT2 *stmt, TAOS_STMT2_BIND *pBind) { return; } - int32_t code = 0; - int fieldNum = 0; - TAOS_FIELD_E *pFields = NULL; - code = st_stmt2_get_col_fields(stmt, &fieldNum, &pFields); + int32_t code = 0; + int fieldNum = 0; + TAOS_FIELD_ALL *pFields = NULL; + code = taos_stmt2_get_fields(stmt, &fieldNum, &pFields); if (code != 0) { printf("!!!st_stmt2_get_col_fields error:%s\n", st_stmt2_error(stmt)); exit(1); diff --git a/tests/script/api/stmt2.c b/tests/script/api/stmt2.c index 5b9f41baff..0ddff274a6 100644 --- a/tests/script/api/stmt2.c +++ b/tests/script/api/stmt2.c @@ -257,10 +257,10 @@ void veriry_stmt(TAOS* taos) { } printf("param_count: %d\n", param_count); */ - TAOS_FIELD_E* fields = NULL; + TAOS_FIELD_ALL* fields = NULL; int field_count = -1; start = clock(); - code = taos_stmt2_get_fields(stmt, TAOS_FIELD_COL, &field_count, NULL); + code = taos_stmt2_get_fields(stmt, &field_count, NULL); end = clock(); printf("get fields time:%f\n", (double)(end - start) / CLOCKS_PER_SEC); if (code != 0) {