add test case

This commit is contained in:
pengrongkun94@qq.com 2024-12-30 20:41:44 +08:00
parent 8d3c0a8d91
commit 2ca9035b6f
1 changed files with 47 additions and 21 deletions

View File

@ -123,7 +123,6 @@ void do_stmt(TAOS* taos, TAOS_STMT2_OPTION* option, const char* sql, int CTB_NUM
ASSERT_NE(stmt, nullptr);
int code = taos_stmt2_prepare(stmt, sql, 0);
ASSERT_EQ(code, 0);
ASSERT_EQ(terrno, 0);
// tbname
char** tbs = (char**)taosMemoryMalloc(CTB_NUMS * sizeof(char*));
@ -183,12 +182,10 @@ void do_stmt(TAOS* taos, TAOS_STMT2_OPTION* option, const char* sql, int CTB_NUM
TAOS_STMT2_BINDV bindv = {CTB_NUMS, tbs, tags, paramv};
code = taos_stmt2_bind_param(stmt, &bindv, -1);
ASSERT_EQ(code, 0);
ASSERT_EQ(errno, 0);
// exec
code = taos_stmt2_exec(stmt, NULL);
ASSERT_EQ(code, 0);
ASSERT_EQ(errno, 0);
for (int i = 0; i < CTB_NUMS; i++) {
if (hastags) {
@ -793,12 +790,10 @@ TEST(stmt2Case, stmt2_init_prepare_Test) {
ASSERT_EQ(terrno, 0);
ASSERT_NE(stmt, nullptr);
int code = taos_stmt2_prepare(stmt, "wrong sql", 0);
ASSERT_EQ(terrno, 0);
ASSERT_NE(stmt, nullptr);
ASSERT_EQ(((STscStmt2*)stmt)->db, nullptr);
code = taos_stmt2_prepare(stmt, "insert into 'db'.stb(t1,t2,ts,b,tbname) values(?,?,?,?,?)", 0);
ASSERT_EQ(terrno, 0);
ASSERT_NE(stmt, nullptr);
ASSERT_STREQ(((STscStmt2*)stmt)->db, "db"); // add in main TD-33332
taos_stmt2_close(stmt);
@ -807,7 +802,6 @@ TEST(stmt2Case, stmt2_init_prepare_Test) {
{
TAOS_STMT2_OPTION option = {0, true, false, NULL, NULL};
TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
ASSERT_EQ(terrno, 0);
ASSERT_NE(stmt, nullptr);
taos_stmt2_close(stmt);
}
@ -815,7 +809,6 @@ TEST(stmt2Case, stmt2_init_prepare_Test) {
{
TAOS_STMT2_OPTION option = {0, true, true, stmtAsyncQueryCb, NULL};
TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
ASSERT_EQ(terrno, 0);
ASSERT_NE(stmt, nullptr);
taos_stmt2_close(stmt);
}
@ -856,25 +849,33 @@ TEST(stmt2Case, stmt2_query) {
TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
ASSERT_NE(stmt, nullptr);
const char* sql = "select * from db.stb where ts = ?";
const char* sql = "select * from db.stb where ts = ? and tbname = ?";
int code = taos_stmt2_prepare(stmt, sql, 0);
ASSERT_EQ(code, 0);
ASSERT_EQ(terrno, 0);
int t64_len[2] = {sizeof(int64_t), sizeof(int64_t)};
int b_len[2] = {5, 5};
int t64_len[1] = {sizeof(int64_t)};
int b_len[1] = {3};
int64_t ts = 1591060628000;
TAOS_STMT2_BIND params[2] = {{TSDB_DATA_TYPE_TIMESTAMP, &ts, t64_len, NULL, 1},
{TSDB_DATA_TYPE_BINARY, (void*)"tb1", b_len, NULL, 1}};
TAOS_STMT2_BIND* paramv = &params[0];
TAOS_STMT2_BINDV bindv = {1, NULL, NULL, &paramv};
taos_stmt2_bind_param(stmt, &bindv, -1);
code = taos_stmt2_bind_param(stmt, &bindv, -1);
ASSERT_EQ(code, 0);
ASSERT_EQ(errno, 0);
taos_stmt2_exec(stmt, NULL);
ASSERT_EQ(code, 0);
ASSERT_EQ(errno, 0);
TAOS_RES* pRes = taos_stmt2_result(stmt);
ASSERT_NE(pRes, nullptr);
int getRecordCounts = 0;
TAOS_ROW row;
while ((row = taos_fetch_row(pRes))) {
getRecordCounts++;
}
ASSERT_EQ(getRecordCounts, 1);
taos_free_result(pRes);
taos_stmt2_close(stmt);
taos_close(taos);
@ -894,11 +895,10 @@ TEST(stmt2Case, stmt2_ntb_insert) {
const char* sql = "insert into db.ntb values(?,?)";
int code = taos_stmt2_prepare(stmt, sql, 0);
ASSERT_EQ(code, 0);
ASSERT_EQ(terrno, 0);
for (int i = 0; i < 3; i++) {
int64_t ts[3] = {1591060628000 + i * 3, 1591060628001 + i * 3, 1591060628002 + i * 3};
int t64_len[3] = {sizeof(int64_t), sizeof(int64_t), sizeof(int64_t)};
int b_len[3] = {5,5,5};
int b_len[3] = {5, 5, 5};
TAOS_STMT2_BIND params1 = {TSDB_DATA_TYPE_TIMESTAMP, &ts[0], &t64_len[0], NULL, 3};
TAOS_STMT2_BIND params2 = {TSDB_DATA_TYPE_BINARY, (void*)"abcdefghijklmnopqrstuvwxyz", &b_len[0], NULL, 3};
@ -908,14 +908,12 @@ TEST(stmt2Case, stmt2_ntb_insert) {
TAOS_STMT2_BINDV bindv1 = {1, NULL, NULL, &paramv1};
TAOS_STMT2_BINDV bindv2 = {1, NULL, NULL, &paramv2};
taos_stmt2_bind_param(stmt, &bindv1, 0);
taos_stmt2_bind_param(stmt, &bindv2, 1);
code = taos_stmt2_bind_param(stmt, &bindv1, 0);
code = taos_stmt2_bind_param(stmt, &bindv2, 1);
ASSERT_EQ(code, 0);
ASSERT_EQ(errno, 0);
code = taos_stmt2_exec(stmt, NULL);
ASSERT_EQ(code, 0);
ASSERT_EQ(errno, 0);
}
checkRows(taos, "select * from db.ntb", 9);
@ -923,6 +921,34 @@ TEST(stmt2Case, stmt2_ntb_insert) {
taos_close(taos);
}
TEST(stmt2Case, stmt2_status_Test) {}
TEST(stmt2Case, stmt2_status_Test) {
TAOS* taos = taos_connect("localhost", "root", "taosdata", "", 0);
ASSERT_NE(taos, nullptr);
TAOS_STMT2_OPTION option = {0, true, true, NULL, NULL};
TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
int64_t ts[3] = {1591060628000, 1591060628001, 1591060628002};
int t64_len[3] = {sizeof(int64_t), sizeof(int64_t), sizeof(int64_t)};
TAOS_STMT2_BIND params = {TSDB_DATA_TYPE_TIMESTAMP, &ts[0], &t64_len[0], NULL, 3};
TAOS_STMT2_BIND* paramv = &params;
TAOS_STMT2_BINDV bindv1 = {1, NULL, NULL, &paramv};
int code = taos_stmt2_bind_param(stmt, &bindv1, 0);
ASSERT_EQ(code, TSDB_CODE_TSC_STMT_BIND_NUMBER_ERROR);
ASSERT_STREQ(taos_stmt2_error(stmt), "bind number out of range or not match");
code = taos_stmt2_exec(stmt, NULL);
ASSERT_EQ(code, TSDB_CODE_TSC_STMT_API_ERROR);
ASSERT_STREQ(taos_stmt2_error(stmt), "Stmt API usage error");
const char* sql = "insert into db.ntb values(?,?)";
code = taos_stmt2_prepare(stmt, sql, 0);
ASSERT_EQ(code, TSDB_CODE_TSC_STMT_API_ERROR);
ASSERT_STREQ(taos_stmt2_error(stmt), "Stmt API usage error");
taos_stmt2_close(stmt);
taos_close(taos);
}
#pragma GCC diagnostic pop