From 21a9534d322edbcea15aa055b1dbb6ef1eb707fe Mon Sep 17 00:00:00 2001 From: "pengrongkun94@qq.com" Date: Mon, 6 Jan 2025 14:32:18 +0800 Subject: [PATCH] add all type test --- source/client/test/stmt2Test.cpp | 242 +++++++++++++++++++++++++++++++ source/client/test/stmtTest.cpp | 133 +++++++++++++++++ 2 files changed, 375 insertions(+) diff --git a/source/client/test/stmt2Test.cpp b/source/client/test/stmt2Test.cpp index 59ad86528c..56a3d623fe 100644 --- a/source/client/test/stmt2Test.cpp +++ b/source/client/test/stmt2Test.cpp @@ -1119,4 +1119,246 @@ TEST(stmt2Case, stmt2_status_Test) { taos_close(taos); } +TEST(stmt2Case, stmt2_nchar) { + TAOS* taos = taos_connect("localhost", "root", "taosdata", "", 0); + do_query(taos, "drop database if exists db;"); + do_query(taos, "create database db;"); + do_query(taos, "use db;"); + do_query(taos, + "create table m1 (ts timestamp, blob2 nchar(10), blob nchar(10),blob3 nchar(10),blob4 nchar(10),blob5 " + "nchar(10))"); + + // insert 10 records + struct { + int64_t ts[10]; + char blob[10][1]; + char blob2[10][1]; + char blob3[10][1]; + char blob4[10][1]; + char blob5[10][1]; + + } v; + + int32_t* t64_len = (int32_t*)taosMemMalloc(sizeof(int32_t) * 10); + int32_t* blob_len = (int32_t*)taosMemMalloc(sizeof(int32_t) * 10); + int32_t* blob_len2 = (int32_t*)taosMemMalloc(sizeof(int32_t) * 10); + int32_t* blob_len3 = (int32_t*)taosMemMalloc(sizeof(int32_t) * 10); + int32_t* blob_len4 = (int32_t*)taosMemMalloc(sizeof(int32_t) * 10); + int32_t* blob_len5 = (int32_t*)taosMemMalloc(sizeof(int32_t) * 10); + + TAOS_STMT2_OPTION option = {0, true, true, NULL, NULL}; + + TAOS_STMT2* stmt = taos_stmt2_init(taos, &option); + ASSERT_NE(stmt, nullptr); + TAOS_STMT2_BIND params[10]; + char is_null[10] = {0}; + + params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; + // params[0].buffer_length = sizeof(v.ts[0]); + params[0].buffer = v.ts; + params[0].length = t64_len; + params[0].is_null = is_null; + params[0].num = 10; + + params[1].buffer_type = TSDB_DATA_TYPE_NCHAR; + // params[8].buffer_length = sizeof(v.blob2[0]); + params[1].buffer = v.blob2; + params[1].length = blob_len2; + params[1].is_null = is_null; + params[1].num = 10; + + params[2].buffer_type = TSDB_DATA_TYPE_NCHAR; + // params[9].buffer_length = sizeof(v.blob[0]); + params[2].buffer = v.blob3; + params[2].length = blob_len; + params[2].is_null = is_null; + params[2].num = 10; + + params[3].buffer_type = TSDB_DATA_TYPE_NCHAR; + // params[9].buffer_length = sizeof(v.blob[0]); + params[3].buffer = v.blob4; + params[3].length = blob_len; + params[3].is_null = is_null; + params[3].num = 10; + + params[4].buffer_type = TSDB_DATA_TYPE_NCHAR; + // params[9].buffer_length = sizeof(v.blob[0]); + params[4].buffer = v.blob; + params[4].length = blob_len; + params[4].is_null = is_null; + params[4].num = 10; + + params[5].buffer_type = TSDB_DATA_TYPE_NCHAR; + // params[9].buffer_length = sizeof(v.blob[0]); + params[5].buffer = v.blob5; + params[5].length = blob_len; + params[5].is_null = is_null; + params[5].num = 10; + + int code = taos_stmt2_prepare(stmt, "insert into ? (ts, blob2, blob, blob3, blob4, blob5) values(?,?,?,?,?,?)", 0); + ASSERT_EQ(code, 0); + + int64_t ts = 1591060628000; + for (int i = 0; i < 10; ++i) { + is_null[i] = 0; + + v.ts[i] = ts++; + + v.blob[i][0] = 'a' + i; + v.blob2[i][0] = 'f' + i; + v.blob3[i][0] = 't' + i; + v.blob4[i][0] = 'A' + i; + v.blob5[i][0] = 'G' + i; + + blob_len[i] = sizeof(char); + blob_len2[i] = sizeof(char); + blob_len3[i] = sizeof(char); + blob_len4[i] = sizeof(char); + blob_len5[i] = sizeof(char); + } + + char* tbname = "m1"; + TAOS_STMT2_BIND* bind_cols[1] = {¶ms[0]}; + TAOS_STMT2_BINDV bindv = {1, &tbname, NULL, &bind_cols[0]}; + code = taos_stmt2_bind_param(stmt, &bindv, -1); + ASSERT_EQ(code, 0); + + code = taos_stmt2_exec(stmt, NULL); + ASSERT_EQ(code, 0); + + taos_stmt2_close(stmt); + + taosMemoryFree(blob_len); + taosMemoryFree(blob_len2); + taosMemoryFree(blob_len5); + taosMemoryFree(blob_len3); + taosMemoryFree(blob_len4); +} + +TEST(stmt2Case, all_type) { + TAOS* taos = taos_connect("localhost", "root", "taosdata", "", 0); + ASSERT_NE(taos, nullptr); + + do_query(taos, "drop database if exists db"); + do_query(taos, "create database db"); + do_query(taos, "use db"); + do_query(taos, + "create stable db.stb(ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 binary(8), c6 smallint, c7 " + "tinyint, c8 bool, c9 nchar(8))TAGS(tts timestamp, t1 int, t2 bigint, t3 float, t4 double, t5 binary(8), t6 " + "smallint, t7 " + "tinyint, t8 bool, t9 nchar(8))"); + + TAOS_STMT2_OPTION option = {0}; + TAOS_STMT2* stmt = taos_stmt2_init(taos, &option); + ASSERT_NE(stmt, nullptr); + + uintptr_t c10len = 0; + struct { + int64_t c1; + int32_t c2; + int64_t c3; + float c4; + double c5; + unsigned char c6[8]; + int16_t c7; + int8_t c8; + int8_t c9; + char c10[32]; + } v = {1591060628000, 1, 2, 3.0, 4.0, "abcdef", 5, 6, 7, "ijnop"}; + + struct { + int32_t c1; + int32_t c2; + int32_t c3; + int32_t c4; + int32_t c5; + int32_t c6; + int32_t c7; + int32_t c8; + int32_t c9; + int32_t c10; + } v_len = {sizeof(int64_t), sizeof(int32_t), + sizeof(int64_t), sizeof(float), + sizeof(double), 8, + sizeof(int16_t), sizeof(int8_t), + sizeof(int8_t), 8}; + TAOS_STMT2_BIND params[11]; + params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; + params[0].length = (int32_t*)&v_len.c1; + params[0].buffer = &v.c1; + params[0].is_null = NULL; + params[0].num = 1; + + params[1].buffer_type = TSDB_DATA_TYPE_INT; + params[1].buffer = &v.c2; + params[1].length = (int32_t*)&v_len.c2; + params[1].is_null = NULL; + params[1].num = 1; + + params[2].buffer_type = TSDB_DATA_TYPE_BIGINT; + params[2].buffer = &v.c3; + params[2].length = (int32_t*)&v_len.c3; + params[2].is_null = NULL; + params[2].num = 1; + + params[3].buffer_type = TSDB_DATA_TYPE_FLOAT; + params[3].buffer = &v.c4; + params[3].length = (int32_t*)&v_len.c4; + params[3].is_null = NULL; + params[3].num = 1; + + params[4].buffer_type = TSDB_DATA_TYPE_DOUBLE; + params[4].buffer = &v.c5; + params[4].length = (int32_t*)&v_len.c5; + params[4].is_null = NULL; + params[4].num = 1; + + params[5].buffer_type = TSDB_DATA_TYPE_BINARY; + params[5].buffer = &v.c6; + params[5].length = (int32_t*)&v_len.c6; + params[5].is_null = NULL; + params[5].num = 1; + + params[6].buffer_type = TSDB_DATA_TYPE_SMALLINT; + params[6].buffer = &v.c7; + params[6].length = (int32_t*)&v_len.c7; + params[6].is_null = NULL; + params[6].num = 1; + + params[7].buffer_type = TSDB_DATA_TYPE_TINYINT; + params[7].buffer = &v.c8; + params[7].length = (int32_t*)&v_len.c8; + params[7].is_null = NULL; + params[7].num = 1; + + params[8].buffer_type = TSDB_DATA_TYPE_BOOL; + params[8].buffer = &v.c9; + params[8].length = (int32_t*)&v_len.c9; + params[8].is_null = NULL; + params[8].num = 1; + + params[9].buffer_type = TSDB_DATA_TYPE_NCHAR; + params[9].buffer = &v.c10; + params[9].length = (int32_t*)&v_len.c10; + params[9].is_null = NULL; + params[9].num = 1; + + char* stmt_sql = "insert into ? using stb tags(?,?,?,?,?,?,?,?,?,?)values (?,?,?,?,?,?,?,?,?,?)"; + int code = taos_stmt2_prepare(stmt, stmt_sql, 0); + ASSERT_EQ(code, 0); + + char* tbname = "tb1"; + TAOS_STMT2_BIND* tags = ¶ms[0]; + TAOS_STMT2_BIND* cols = ¶ms[0]; + TAOS_STMT2_BINDV bindv = {1, &tbname, &tags, &cols}; + code = taos_stmt2_bind_param(stmt, &bindv, -1); + ASSERT_EQ(code, 0); + + code = taos_stmt2_exec(stmt, NULL); + ASSERT_EQ(code, 0); + + taos_stmt2_close(stmt); + taos_close(taos); +} + #pragma GCC diagnostic pop diff --git a/source/client/test/stmtTest.cpp b/source/client/test/stmtTest.cpp index e7e762eff0..a264f81cf5 100644 --- a/source/client/test/stmtTest.cpp +++ b/source/client/test/stmtTest.cpp @@ -293,4 +293,137 @@ TEST(stmtCase, get_fields) { taos_close(taos); } +TEST(stmtCase, all_type) { + 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"); + do_query(taos, "use db"); + do_query(taos, + "create stable db.stb(ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 binary(8), c6 smallint, c7 " + "tinyint, c8 bool, c9 nchar(8))TAGS(tts timestamp, t1 int, t2 bigint, t3 float, t4 double, t5 binary(8), t6 " + "smallint, t7 " + "tinyint, t8 bool, t9 nchar(8))"); + + TAOS_STMT *stmt = taos_stmt_init(taos); + ASSERT_NE(stmt, nullptr); + + uintptr_t c10len = 0; + struct { + int64_t c1; + int32_t c2; + int64_t c3; + float c4; + double c5; + unsigned char c6[8]; + int16_t c7; + int8_t c8; + int8_t c9; + char c10[32]; + } v = {0}; + TAOS_MULTI_BIND params[11]; + params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; + params[0].buffer_length = sizeof(v.c1); + params[0].buffer = &v.c1; + params[0].length = (int32_t *)¶ms[0].buffer_length; + params[0].is_null = NULL; + params[0].num = 1; + + params[1].buffer_type = TSDB_DATA_TYPE_INT; + params[1].buffer_length = sizeof(v.c2); + params[1].buffer = &v.c2; + params[1].length = (int32_t *)¶ms[1].buffer_length; + params[1].is_null = NULL; + params[1].num = 1; + + params[2].buffer_type = TSDB_DATA_TYPE_BIGINT; + params[2].buffer_length = sizeof(v.c3); + params[2].buffer = &v.c3; + params[2].length = (int32_t *)¶ms[2].buffer_length; + params[2].is_null = NULL; + params[2].num = 1; + + params[3].buffer_type = TSDB_DATA_TYPE_FLOAT; + params[3].buffer_length = sizeof(v.c4); + params[3].buffer = &v.c4; + params[3].length = (int32_t *)¶ms[3].buffer_length; + params[3].is_null = NULL; + params[3].num = 1; + + params[4].buffer_type = TSDB_DATA_TYPE_DOUBLE; + params[4].buffer_length = sizeof(v.c5); + params[4].buffer = &v.c5; + params[4].length = (int32_t *)¶ms[4].buffer_length; + params[4].is_null = NULL; + params[4].num = 1; + + params[5].buffer_type = TSDB_DATA_TYPE_BINARY; + params[5].buffer_length = sizeof(v.c6); + params[5].buffer = &v.c6; + params[5].length = (int32_t *)¶ms[5].buffer_length; + params[5].is_null = NULL; + params[5].num = 1; + + params[6].buffer_type = TSDB_DATA_TYPE_SMALLINT; + params[6].buffer_length = sizeof(v.c7); + params[6].buffer = &v.c7; + params[6].length = (int32_t *)¶ms[6].buffer_length; + params[6].is_null = NULL; + params[6].num = 1; + + params[7].buffer_type = TSDB_DATA_TYPE_TINYINT; + params[7].buffer_length = sizeof(v.c8); + params[7].buffer = &v.c8; + params[7].length = (int32_t *)¶ms[7].buffer_length; + params[7].is_null = NULL; + params[7].num = 1; + + params[8].buffer_type = TSDB_DATA_TYPE_BOOL; + params[8].buffer_length = sizeof(v.c9); + params[8].buffer = &v.c9; + params[8].length = (int32_t *)¶ms[8].buffer_length; + params[8].is_null = NULL; + params[8].num = 1; + + params[9].buffer_type = TSDB_DATA_TYPE_NCHAR; + params[9].buffer_length = sizeof(v.c10); + params[9].buffer = &v.c10; + params[9].length = (int32_t *)&c10len; + params[9].is_null = NULL; + params[9].num = 1; + + char *stmt_sql = "insert into ? using stb tags(?,?,?,?,?,?,?,?,?,?)values (?,?,?,?,?,?,?,?,?,?)"; + int code = taos_stmt_prepare(stmt, stmt_sql, 0); + ASSERT_EQ(code, 0); + + code = taos_stmt_set_tbname(stmt, "ntb"); + ASSERT_EQ(code, 0); + + code = taos_stmt_set_tags(stmt, params); + ASSERT_EQ(code, 0); + + v.c1 = (int64_t)1591060628000; + v.c2 = (int32_t)2147483647; + v.c3 = (int64_t)2147483648; + v.c4 = (float)0.1; + v.c5 = (double)0.000000001; + for (int j = 0; j < sizeof(v.c6); j++) { + v.c6[j] = (char)('a'); + } + v.c7 = 32767; + v.c8 = 127; + v.c9 = 1; + strcpy(v.c10, "一二三四五六七八"); + c10len = strlen(v.c10); + taos_stmt_bind_param(stmt, params); + taos_stmt_add_batch(stmt); + + code = taos_stmt_execute(stmt); + ASSERT_EQ(code, 0); + + taos_stmt_close(stmt); + taos_close(taos); +} + #pragma GCC diagnostic pop \ No newline at end of file