From 8e24c29230c37f821a54098782efa93e25ed21d6 Mon Sep 17 00:00:00 2001 From: "pengrongkun94@qq.com" Date: Fri, 3 Jan 2025 09:11:13 +0800 Subject: [PATCH] TD33419 --- source/client/test/stmt2Test.cpp | 52 ++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/source/client/test/stmt2Test.cpp b/source/client/test/stmt2Test.cpp index e4dc9c3005..3c63bda398 100644 --- a/source/client/test/stmt2Test.cpp +++ b/source/client/test/stmt2Test.cpp @@ -933,6 +933,58 @@ TEST(stmt2Case, stmt2_insert_non_statndard) { taos_close(taos); } +//TD-33419 +TEST(stmt2Case, stmt2_insert_db) { + TAOS* taos = taos_connect("localhost", "root", "taosdata", "", 0); + ASSERT_NE(taos, nullptr); + do_query(taos, "drop database if exists example_all_type_stmt1"); + do_query(taos, "create database example_all_type_stmt1"); + do_query(taos, + "create table `example_all_type_stmt1`.`stb1` (ts timestamp, int_col int,long_col bigint,double_col " + "double,bool_col bool,binary_col binary(20),nchar_col nchar(20),varbinary_col varbinary(20),geometry_col " + "geometry(200)) tags(int_tag int,long_tag bigint,double_tag double,bool_tag bool,binary_tag " + "binary(20),nchar_tag nchar(20),varbinary_tag varbinary(20),geometry_tag geometry(200));"); + + TAOS_STMT2_OPTION option = {0, false, false, NULL, NULL}; + + TAOS_STMT2* stmt = taos_stmt2_init(taos, &option); + ASSERT_NE(stmt, nullptr); + const char* sql = "INSERT INTO `example_all_type_stmt1`.`stb1` (ts,int_tag,tbname) VALUES (?,?,?)"; + int code = taos_stmt2_prepare(stmt, sql, 0); + ASSERT_EQ(code, 0); + + int t64_len[2] = {sizeof(int64_t), sizeof(int64_t)}; + int tag_i = 0; + int tag_l = sizeof(int); + int64_t ts[2] = {1591060628000, 1591060628100}; + for (int i = 0; i < 3; i++) { + ts[0] += 1000; + ts[1] += 1000; + + TAOS_STMT2_BIND tags1 = {TSDB_DATA_TYPE_INT, &tag_i, &tag_l, NULL, 1}; + TAOS_STMT2_BIND tags2 = {TSDB_DATA_TYPE_INT, &tag_i, &tag_l, NULL, 1}; + TAOS_STMT2_BIND params1 = {TSDB_DATA_TYPE_TIMESTAMP, &ts, &t64_len[0], NULL, 2}; + TAOS_STMT2_BIND params2 = {TSDB_DATA_TYPE_TIMESTAMP, &ts, &t64_len[0], NULL, 2}; + + TAOS_STMT2_BIND* tagv[2] = {&tags1, &tags2}; + TAOS_STMT2_BIND* paramv[2] = {¶ms1, ¶ms2}; + char* tbname[2] = {"tb1", "tb2"}; + TAOS_STMT2_BINDV bindv = {2, &tbname[0], &tagv[0], ¶mv[0]}; + code = taos_stmt2_bind_param(stmt, &bindv, -1); + ASSERT_EQ(code, 0); + + int affected_rows; + taos_stmt2_exec(stmt, &affected_rows); + ASSERT_EQ(code, 0); + } + + checkRows(taos, "select * from example_all_type_stmt1.tb1", 6); + checkRows(taos, "select * from example_all_type_stmt1.tb2", 6); + checkRows(taos, "select * from example_all_type_stmt1.stb1", 12); + taos_stmt2_close(stmt); + taos_close(taos); +} + TEST(stmt2Case, stmt2_query) { TAOS* taos = taos_connect("localhost", "root", "taosdata", "", 0); ASSERT_NE(taos, nullptr);