diff --git a/source/client/src/clientStmt2.c b/source/client/src/clientStmt2.c index 820a7a0110..8edd60e4b5 100644 --- a/source/client/src/clientStmt2.c +++ b/source/client/src/clientStmt2.c @@ -853,7 +853,7 @@ static int stmtSetDbName2(TAOS_STMT2* stmt, const char* dbName) { // The SQL statement specifies a database name, overriding the previously specified database taosMemoryFreeClear(pStmt->exec.pRequest->pDb); - pStmt->exec.pRequest->pDb = taosStrdup(dbName); + pStmt->exec.pRequest->pDb = taosStrdup(pStmt->db); if (pStmt->exec.pRequest->pDb == NULL) { return terrno; } diff --git a/source/client/test/stmt2Test.cpp b/source/client/test/stmt2Test.cpp index 3c63bda398..a7b1078e81 100644 --- a/source/client/test/stmt2Test.cpp +++ b/source/client/test/stmt2Test.cpp @@ -114,10 +114,10 @@ void do_query(TAOS* taos, const char* sql) { void do_stmt(TAOS* taos, TAOS_STMT2_OPTION* option, const char* sql, int CTB_NUMS, int ROW_NUMS, int CYC_NUMS, bool hastags, bool createTable) { + printf("%s\n", sql); do_query(taos, "drop database if exists db"); do_query(taos, "create database db"); do_query(taos, "create table db.stb (ts timestamp, b binary(10)) tags(t1 int, t2 binary(10))"); - do_query(taos, "use db"); TAOS_STMT2* stmt = taos_stmt2_init(taos, option); ASSERT_NE(stmt, nullptr); @@ -818,14 +818,21 @@ TEST(stmt2Case, stmt2_init_prepare_Test) { TEST(stmt2Case, stmt2_stb_insert) { TAOS* taos = taos_connect("localhost", "root", "taosdata", "", 0); ASSERT_NE(taos, nullptr); + // normal insert into stb TAOS_STMT2_OPTION option = {0, true, true, NULL, NULL}; { do_stmt(taos, &option, "insert into db.stb (tbname,ts,b,t1,t2) values(?,?,?,?,?)", 3, 3, 3, true, true); } + // normal using option = {0, true, true, stmtAsyncQueryCb, NULL}; { do_stmt(taos, &option, "insert into db.? using db.stb tags(?,?) values(?,?)", 3, 3, 3, true, true); } - option = {0, false, false, NULL, NULL}; + // `db`.`stb` is not a super table + option = {0, true, true, NULL, NULL}; + { do_stmt(taos, &option, "insert into `db`.`stb` (tbname,ts,b) values(?,?,?)", 3, 3, 3, false, true); } + // use db + do_query(taos, "use db"); + option = {0, true, true, stmtAsyncQueryCb, NULL}; { do_stmt(taos, &option, "insert into stb (tbname,ts,b,t1,t2) values(?,?,?,?,?)", 3, 3, 3, true, false); } option = {0, true, true, NULL, NULL}; - { do_stmt(taos, &option, "insert into db.stb (tbname,ts,b) values(?,?,?)", 3, 3, 3, false, true); } + { do_stmt(taos, &option, "insert into ? using stb (t1,t2)tags(?,?) (ts,b)values(?,?)", 3, 3, 3, true, false); } taos_close(taos); } @@ -933,7 +940,7 @@ TEST(stmt2Case, stmt2_insert_non_statndard) { taos_close(taos); } -//TD-33419 +// TD-33419 TEST(stmt2Case, stmt2_insert_db) { TAOS* taos = taos_connect("localhost", "root", "taosdata", "", 0); ASSERT_NE(taos, nullptr); @@ -997,7 +1004,6 @@ TEST(stmt2Case, stmt2_query) { do_query(taos, "insert into db.tb2 using db.stb tags(2,'xyz') values(1591060628000, " "'abc'),(1591060628001,'def'),(1591060628002, 'hij')"); - do_query(taos, "use db"); TAOS_STMT2_OPTION option = {0, true, true, NULL, NULL}; diff --git a/source/libs/parser/inc/parInsertUtil.h b/source/libs/parser/inc/parInsertUtil.h index b2a585d881..c5cce55d9a 100644 --- a/source/libs/parser/inc/parInsertUtil.h +++ b/source/libs/parser/inc/parInsertUtil.h @@ -50,7 +50,6 @@ int32_t insInitColValues(STableMeta *pTableMeta, SArray *aColValues); void insCheckTableDataOrder(STableDataCxt *pTableCxt, SRowKey *rowKey); int32_t insGetTableDataCxt(SHashObj *pHash, void *id, int32_t idLen, STableMeta *pTableMeta, SVCreateTbReq **pCreateTbReq, STableDataCxt **pTableCxt, bool colMode, bool ignoreColVals); -int32_t initTableColSubmitDataWithBoundInfo(STableDataCxt *pTableCxt, SBoundColInfo pBoundColsInfo); int32_t initTableColSubmitData(STableDataCxt *pTableCxt); int32_t insMergeTableDataCxt(SHashObj *pTableHash, SArray **pVgDataBlocks, bool isRebuild); //int32_t insMergeStmtTableDataCxt(STableDataCxt* pTableCxt, SArray* pTableList, SArray** pVgDataBlocks, bool isRebuild, int32_t tbNum); diff --git a/source/libs/parser/src/parInsertSql.c b/source/libs/parser/src/parInsertSql.c index fe4abd5c8f..67ad874b15 100644 --- a/source/libs/parser/src/parInsertSql.c +++ b/source/libs/parser/src/parInsertSql.c @@ -1449,12 +1449,12 @@ int32_t initTableColSubmitData(STableDataCxt* pTableCxt) { int32_t initTableColSubmitDataWithBoundInfo(STableDataCxt* pTableCxt, SBoundColInfo pBoundColsInfo) { insDestroyBoundColInfo(&(pTableCxt->boundColsInfo)); pTableCxt->boundColsInfo = pBoundColsInfo; - pTableCxt->boundColsInfo.pColIndex = taosMemoryCalloc(pBoundColsInfo.numOfBound - 1, sizeof(int16_t)); + pTableCxt->boundColsInfo.pColIndex = taosMemoryCalloc(pBoundColsInfo.numOfBound, sizeof(int16_t)); if (NULL == pTableCxt->boundColsInfo.pColIndex) { return terrno; } (void)memcpy(pTableCxt->boundColsInfo.pColIndex, pBoundColsInfo.pColIndex, - sizeof(int16_t) * pBoundColsInfo.numOfBound - 1); + sizeof(int16_t) * pBoundColsInfo.numOfBound); for (int32_t i = 0; i < pBoundColsInfo.numOfBound; ++i) { SSchema* pSchema = &pTableCxt->pMeta->schema[pTableCxt->boundColsInfo.pColIndex[i]]; SColData* pCol = taosArrayReserve(pTableCxt->pData->aCol, 1);