From e46913e1fee650752ed3ae110e9f2e285e567b3f Mon Sep 17 00:00:00 2001 From: "pengrongkun94@qq.com" Date: Thu, 20 Feb 2025 18:32:51 +0800 Subject: [PATCH] enh stmt2 TD-33802 --- source/client/test/stmt2Test.cpp | 31 ++++++++++++++++++++++++++ source/common/src/tdataformat.c | 10 ++++----- source/libs/parser/src/parInsertStmt.c | 6 ++++- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/source/client/test/stmt2Test.cpp b/source/client/test/stmt2Test.cpp index 407c8745a5..72b2e6929c 100644 --- a/source/client/test/stmt2Test.cpp +++ b/source/client/test/stmt2Test.cpp @@ -1043,6 +1043,37 @@ TEST(stmt2Case, stmt2_insert_non_statndard) { taos_stmt2_close(stmt); } + // pk error + { + TAOS_STMT2* stmt = taos_stmt2_init(taos, &option); + ASSERT_NE(stmt, nullptr); + const char* sql = + "INSERT INTO stmt2_testdb_6.? using stmt2_testdb_6.stb1 (int_tag)tags(1) (int_col,ts)VALUES (?,?)"; + int code = taos_stmt2_prepare(stmt, sql, 0); + checkError(stmt, code); + + int tag_i = 0; + int tag_l = sizeof(int); + int tag_bl = 3; + int64_t ts[2] = {1591060628000, NULL}; + int t64_len[2] = {sizeof(int64_t), sizeof(int64_t)}; + int coli[2] = {1, 2}; + int ilen[2] = {sizeof(int), sizeof(int)}; + int total_affect_rows = 0; + char is_null[2] = {1, 1}; + + TAOS_STMT2_BIND params1[2] = {{TSDB_DATA_TYPE_INT, &coli, &ilen[0], is_null, 2}, + {TSDB_DATA_TYPE_TIMESTAMP, &ts, &t64_len[0], is_null, 2}}; + + TAOS_STMT2_BIND* paramv = ¶ms1[0]; + char* tbname = "tb3"; + TAOS_STMT2_BINDV bindv = {1, &tbname, NULL, ¶mv}; + code = taos_stmt2_bind_param(stmt, &bindv, -1); + ASSERT_EQ(code, TSDB_CODE_PAR_PRIMARY_KEY_IS_NULL); + + taos_stmt2_close(stmt); + } + do_query(taos, "drop database if exists stmt2_testdb_6"); taos_close(taos); } diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index f8f3c0f770..a02ca85a1f 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -152,10 +152,10 @@ static int32_t tRowBuildScan(SArray *colVals, const STSchema *schema, SRowBuildS return TSDB_CODE_INVALID_PARA; } if (!(colValArray[0].cid == PRIMARYKEY_TIMESTAMP_COL_ID)) { - return TSDB_CODE_INVALID_PARA; + return TSDB_CODE_PAR_INVALID_FIRST_COLUMN; } if (!(colValArray[0].value.type == TSDB_DATA_TYPE_TIMESTAMP)) { - return TSDB_CODE_INVALID_PARA; + return TSDB_CODE_PAR_INVALID_FIRST_COLUMN;; } *sinfo = (SRowBuildScanInfo){ @@ -3627,13 +3627,13 @@ int32_t tColDataSortMerge(SArray **arr) { SColData *aColData = (SColData *)TARRAY_DATA(colDataArr); if (!(aColData[0].type == TSDB_DATA_TYPE_TIMESTAMP)) { - return TSDB_CODE_INVALID_PARA; + return TSDB_CODE_PAR_INVALID_FIRST_COLUMN; } if (!(aColData[0].cid == PRIMARYKEY_TIMESTAMP_COL_ID)) { - return TSDB_CODE_INVALID_PARA; + return TSDB_CODE_PAR_INVALID_FIRST_COLUMN; } if (!(aColData[0].flag == HAS_VALUE)) { - return TSDB_CODE_INVALID_PARA; + return TSDB_CODE_PAR_PRIMARY_KEY_IS_NULL; } if (aColData[0].nVal <= 1) goto _exit; diff --git a/source/libs/parser/src/parInsertStmt.c b/source/libs/parser/src/parInsertStmt.c index 74fac463f1..9f9077d1b6 100644 --- a/source/libs/parser/src/parInsertStmt.c +++ b/source/libs/parser/src/parInsertStmt.c @@ -834,6 +834,10 @@ int32_t qBindStmtColsValue2(void* pBlock, SArray* pCols, TAOS_STMT2_BIND* bind, goto _return; } + if(boundInfo->pColIndex[c]==0){ + pCol->cflag |= COL_IS_KEY; + } + if (bind[c].num != rowNum) { code = buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same"); goto _return; @@ -863,7 +867,7 @@ int32_t qBindStmtColsValue2(void* pBlock, SArray* pCols, TAOS_STMT2_BIND* bind, } } - qDebug("stmt all %d columns bind %d rows data", boundInfo->numOfBound, rowNum); + qDebug("stmt2 all %d columns bind %d rows data as col format", boundInfo->numOfBound, rowNum); _return: