fix TD-33470 and add some test
This commit is contained in:
parent
13424d0521
commit
7ca71f8150
|
@ -105,12 +105,14 @@ TARGET_INCLUDE_DIRECTORIES(
|
|||
TARGET_INCLUDE_DIRECTORIES(
|
||||
stmt2Test
|
||||
PUBLIC "${TD_SOURCE_DIR}/include/client/"
|
||||
PUBLIC "${TD_SOURCE_DIR}/include/libs/geometry"
|
||||
PRIVATE "${TD_SOURCE_DIR}/source/client/inc"
|
||||
)
|
||||
|
||||
TARGET_INCLUDE_DIRECTORIES(
|
||||
stmtTest
|
||||
PUBLIC "${TD_SOURCE_DIR}/include/client/"
|
||||
PUBLIC "${TD_SOURCE_DIR}/include/libs/geometry"
|
||||
PRIVATE "${TD_SOURCE_DIR}/source/client/inc"
|
||||
)
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <string.h>
|
||||
#include "clientInt.h"
|
||||
#include "geosWrapper.h"
|
||||
#include "osSemaphore.h"
|
||||
#include "taoserror.h"
|
||||
#include "tglobal.h"
|
||||
|
@ -33,17 +34,17 @@
|
|||
#include "taos.h"
|
||||
|
||||
namespace {
|
||||
|
||||
void checkRows(TAOS* pConn, const char* sql, int32_t expectedRows) {
|
||||
TAOS_RES* pRes = taos_query(pConn, sql);
|
||||
ASSERT_EQ(taos_errno(pRes), TSDB_CODE_SUCCESS);
|
||||
TAOS_ROW pRow = NULL;
|
||||
int rows = 0;
|
||||
while ((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
rows++;
|
||||
void checkError(TAOS_STMT2* stmt, int code) {
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
STscStmt2* pStmt = (STscStmt2*)stmt;
|
||||
if (pStmt == nullptr || pStmt->sql.sqlStr == nullptr) {
|
||||
printf("stmt api error\n stats : %d\n errstr : %s\n", pStmt->sql.status, taos_stmt_errstr(stmt));
|
||||
} else {
|
||||
printf("stmt api error\n sql : %s\n stats : %d\n errstr : %s\n", pStmt->sql.sqlStr, pStmt->sql.status,
|
||||
taos_stmt_errstr(stmt));
|
||||
}
|
||||
ASSERT_EQ(code, TSDB_CODE_SUCCESS);
|
||||
}
|
||||
// ASSERT_EQ(rows, expectedRows);
|
||||
taos_free_result(pRes);
|
||||
}
|
||||
|
||||
void stmtAsyncQueryCb(void* param, TAOS_RES* pRes, int code) {
|
||||
|
@ -56,12 +57,12 @@ void getFieldsSuccess(TAOS* taos, const char* sql, TAOS_FIELD_ALL* expectedField
|
|||
TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
|
||||
ASSERT_NE(stmt, nullptr);
|
||||
int code = taos_stmt2_prepare(stmt, sql, 0);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
|
||||
int fieldNum = 0;
|
||||
TAOS_FIELD_ALL* pFields = NULL;
|
||||
code = taos_stmt2_get_fields(stmt, &fieldNum, &pFields);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
ASSERT_EQ(fieldNum, expectedFieldNum);
|
||||
|
||||
for (int i = 0; i < fieldNum; i++) {
|
||||
|
@ -81,7 +82,7 @@ void getFieldsError(TAOS* taos, const char* sql, int errorCode) {
|
|||
TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
|
||||
ASSERT_NE(stmt, nullptr);
|
||||
int code = taos_stmt2_prepare(stmt, sql, 0);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
|
||||
int fieldNum = 0;
|
||||
TAOS_FIELD_ALL* pFields = NULL;
|
||||
|
@ -96,12 +97,12 @@ void getQueryFields(TAOS* taos, const char* sql, int expectedFieldNum) {
|
|||
TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
|
||||
ASSERT_NE(stmt, nullptr);
|
||||
int code = taos_stmt2_prepare(stmt, sql, 0);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
|
||||
int fieldNum = 0;
|
||||
TAOS_FIELD_ALL* pFields = NULL;
|
||||
code = taos_stmt2_get_fields(stmt, &fieldNum, NULL);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
ASSERT_EQ(fieldNum, expectedFieldNum);
|
||||
taos_stmt2_free_fields(stmt, NULL);
|
||||
taos_stmt2_close(stmt);
|
||||
|
@ -109,13 +110,18 @@ void getQueryFields(TAOS* taos, const char* sql, int expectedFieldNum) {
|
|||
|
||||
void do_query(TAOS* taos, const char* sql) {
|
||||
TAOS_RES* result = taos_query(taos, sql);
|
||||
ASSERT_EQ(taos_errno(result), TSDB_CODE_SUCCESS);
|
||||
// printf("sql: %s\n", sql);
|
||||
int code = taos_errno(result);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
printf("query failen sql : %s\n errstr : %s\n", sql, taos_errstr(result));
|
||||
ASSERT_EQ(taos_errno(result), TSDB_CODE_SUCCESS);
|
||||
}
|
||||
taos_free_result(result);
|
||||
}
|
||||
|
||||
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);
|
||||
printf("test sql : %s\n", sql);
|
||||
do_query(taos, "drop database if exists testdb1");
|
||||
do_query(taos, "create database IF NOT EXISTS testdb1");
|
||||
do_query(taos, "create table testdb1.stb (ts timestamp, b binary(10)) tags(t1 int, t2 binary(10))");
|
||||
|
@ -123,7 +129,8 @@ void do_stmt(TAOS* taos, TAOS_STMT2_OPTION* option, const char* sql, int CTB_NUM
|
|||
TAOS_STMT2* stmt = taos_stmt2_init(taos, option);
|
||||
ASSERT_NE(stmt, nullptr);
|
||||
int code = taos_stmt2_prepare(stmt, sql, 0);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
int total_affected = 0;
|
||||
|
||||
// tbname
|
||||
char** tbs = (char**)taosMemoryMalloc(CTB_NUMS * sizeof(char*));
|
||||
|
@ -182,11 +189,13 @@ void do_stmt(TAOS* taos, TAOS_STMT2_OPTION* option, const char* sql, int CTB_NUM
|
|||
// bind
|
||||
TAOS_STMT2_BINDV bindv = {CTB_NUMS, tbs, tags, paramv};
|
||||
code = taos_stmt2_bind_param(stmt, &bindv, -1);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
|
||||
// exec
|
||||
code = taos_stmt2_exec(stmt, NULL);
|
||||
ASSERT_EQ(code, 0);
|
||||
int affected;
|
||||
code = taos_stmt2_exec(stmt, &affected);
|
||||
total_affected += affected;
|
||||
checkError(stmt, code);
|
||||
|
||||
for (int i = 0; i < CTB_NUMS; i++) {
|
||||
if (hastags) {
|
||||
|
@ -206,7 +215,7 @@ void do_stmt(TAOS* taos, TAOS_STMT2_OPTION* option, const char* sql, int CTB_NUM
|
|||
}
|
||||
}
|
||||
|
||||
checkRows(taos, "select * from testdb1.stb", CYC_NUMS * ROW_NUMS * CTB_NUMS);
|
||||
ASSERT_EQ(total_affected, CYC_NUMS * ROW_NUMS * CTB_NUMS);
|
||||
for (int i = 0; i < CTB_NUMS; i++) {
|
||||
taosMemoryFree(tbs[i]);
|
||||
}
|
||||
|
@ -233,8 +242,8 @@ TEST(stmt2Case, insert_stb_get_fields_Test) {
|
|||
"int, t2 binary(10))");
|
||||
do_query(
|
||||
taos,
|
||||
"create table if not exists testdb2.all_stb(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 bigint, v6 "
|
||||
"tinyint unsigned, v7 smallint unsigned, v8 int unsigned, v9 bigint unsigned, v10 float, v11 double, v12 "
|
||||
"create table if not exists testdb2.all_stb(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 bigint, "
|
||||
"v6 tinyint unsigned, v7 smallint unsigned, v8 int unsigned, v9 bigint unsigned, v10 float, v11 double, v12 "
|
||||
"binary(20), v13 varbinary(20), v14 geometry(100), v15 nchar(20))tags(tts timestamp, tv1 bool, tv2 tinyint, tv3 "
|
||||
"smallint, tv4 int, tv5 bigint, tv6 tinyint unsigned, tv7 smallint unsigned, tv8 int unsigned, tv9 bigint "
|
||||
"unsigned, tv10 float, tv11 double, tv12 binary(20), tv13 varbinary(20), tv14 geometry(100), tv15 nchar(20));");
|
||||
|
@ -444,8 +453,8 @@ TEST(stmt2Case, insert_ctb_using_get_fields_Test) {
|
|||
"int, t2 binary(10))");
|
||||
do_query(
|
||||
taos,
|
||||
"create table if not exists testdb3.all_stb(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 bigint, v6 "
|
||||
"tinyint unsigned, v7 smallint unsigned, v8 int unsigned, v9 bigint unsigned, v10 float, v11 double, v12 "
|
||||
"create table if not exists testdb3.all_stb(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 bigint, "
|
||||
"v6 tinyint unsigned, v7 smallint unsigned, v8 int unsigned, v9 bigint unsigned, v10 float, v11 double, v12 "
|
||||
"binary(20), v13 varbinary(20), v14 geometry(100), v15 nchar(20))tags(tts timestamp, tv1 bool, tv2 tinyint, tv3 "
|
||||
"smallint, tv4 int, tv5 bigint, tv6 tinyint unsigned, tv7 smallint unsigned, tv8 int unsigned, tv9 bigint "
|
||||
"unsigned, tv10 float, tv11 double, tv12 binary(20), tv13 varbinary(20), tv14 geometry(100), tv15 nchar(20));");
|
||||
|
@ -641,11 +650,10 @@ TEST(stmt2Case, insert_ntb_get_fields_Test) {
|
|||
do_query(taos, "drop database if exists testdb4");
|
||||
do_query(taos, "create database IF NOT EXISTS testdb4 PRECISION 'ms'");
|
||||
do_query(taos, "CREATE TABLE testdb4.ntb(nts timestamp, nb binary(10),nvc varchar(16),ni int);");
|
||||
do_query(
|
||||
taos,
|
||||
"create table if not exists testdb4.all_ntb(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 bigint, v6 "
|
||||
"tinyint unsigned, v7 smallint unsigned, v8 int unsigned, v9 bigint unsigned, v10 float, v11 double, v12 "
|
||||
"binary(20), v13 varbinary(20), v14 geometry(100), v15 nchar(20));");
|
||||
do_query(taos,
|
||||
"create table if not exists testdb4.all_ntb(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 "
|
||||
"bigint, v6 tinyint unsigned, v7 smallint unsigned, v8 int unsigned, v9 bigint unsigned, v10 float, v11 "
|
||||
"double, v12 binary(20), v13 varbinary(20), v14 geometry(100), v15 nchar(20));");
|
||||
|
||||
printf("support case \n");
|
||||
|
||||
|
@ -817,12 +825,17 @@ TEST(stmt2Case, stmt2_stb_insert) {
|
|||
// normal
|
||||
TAOS_STMT2_OPTION option = {0, true, true, NULL, NULL};
|
||||
{ do_stmt(taos, &option, "insert into `testdb1`.`stb` (tbname,ts,b,t1,t2) values(?,?,?,?,?)", 3, 3, 3, true, true); }
|
||||
{ do_stmt(taos, &option, "insert into `testdb1`.? using `testdb1`.`stb` tags(?,?) values(?,?)", 3, 3, 3, true, true); }
|
||||
{
|
||||
do_stmt(taos, &option, "insert into `testdb1`.? using `testdb1`.`stb` tags(?,?) values(?,?)", 3, 3, 3, true, true);
|
||||
}
|
||||
|
||||
// async
|
||||
option = {0, true, true, stmtAsyncQueryCb, NULL};
|
||||
{ do_stmt(taos, &option, "insert into testdb1.stb (ts,b,tbname,t1,t2) values(?,?,?,?,?)", 3, 3, 3, true, true); }
|
||||
{ do_stmt(taos, &option, "insert into testdb1.? using testdb1.stb (t1,t2)tags(?,?) (ts,b)values(?,?)", 3, 3, 3, true, true); }
|
||||
{
|
||||
do_stmt(taos, &option, "insert into testdb1.? using testdb1.stb (t1,t2)tags(?,?) (ts,b)values(?,?)", 3, 3, 3, true,
|
||||
true);
|
||||
}
|
||||
// { do_stmt(taos, &option, "insert into db.? values(?,?)", 3, 3, 3, false, true); }
|
||||
|
||||
// interlace = 0 & use db]
|
||||
|
@ -861,7 +874,8 @@ TEST(stmt2Case, stmt2_insert_non_statndard) {
|
|||
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);
|
||||
checkError(stmt, code);
|
||||
int total_affect_rows = 0;
|
||||
|
||||
int t64_len[2] = {sizeof(int64_t), sizeof(int64_t)};
|
||||
int tag_i = 0;
|
||||
|
@ -881,16 +895,16 @@ TEST(stmt2Case, stmt2_insert_non_statndard) {
|
|||
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);
|
||||
checkError(stmt, code);
|
||||
|
||||
int affected_rows;
|
||||
taos_stmt2_exec(stmt, &affected_rows);
|
||||
ASSERT_EQ(code, 0);
|
||||
total_affect_rows += affected_rows;
|
||||
|
||||
checkError(stmt, code);
|
||||
}
|
||||
|
||||
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);
|
||||
ASSERT_EQ(total_affect_rows, 12);
|
||||
taos_stmt2_close(stmt);
|
||||
}
|
||||
|
||||
|
@ -901,7 +915,7 @@ TEST(stmt2Case, stmt2_insert_non_statndard) {
|
|||
const char* sql =
|
||||
"INSERT INTO example_all_type_stmt1.stb1 (binary_tag,int_col,tbname,ts,int_tag) VALUES (?,?,?,?,?)";
|
||||
int code = taos_stmt2_prepare(stmt, sql, 0);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
|
||||
int tag_i = 0;
|
||||
int tag_l = sizeof(int);
|
||||
|
@ -910,6 +924,7 @@ TEST(stmt2Case, stmt2_insert_non_statndard) {
|
|||
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;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
ts[0] += 1000;
|
||||
ts[1] += 1000;
|
||||
|
@ -928,16 +943,14 @@ TEST(stmt2Case, stmt2_insert_non_statndard) {
|
|||
char* tbname[2] = {"tb3", "tb4"};
|
||||
TAOS_STMT2_BINDV bindv = {2, &tbname[0], &tagv[0], ¶mv[0]};
|
||||
code = taos_stmt2_bind_param(stmt, &bindv, -1);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
|
||||
int affected_rows;
|
||||
taos_stmt2_exec(stmt, &affected_rows);
|
||||
ASSERT_EQ(code, 0);
|
||||
total_affect_rows += affected_rows;
|
||||
checkError(stmt, code);
|
||||
}
|
||||
|
||||
checkRows(taos, "select * from example_all_type_stmt1.tb3", 6);
|
||||
checkRows(taos, "select * from example_all_type_stmt1.tb4", 6);
|
||||
checkRows(taos, "select * from example_all_type_stmt1.stb1", 24);
|
||||
ASSERT_EQ(total_affect_rows, 12);
|
||||
taos_stmt2_close(stmt);
|
||||
}
|
||||
|
||||
|
@ -962,12 +975,13 @@ TEST(stmt2Case, stmt2_insert_db) {
|
|||
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);
|
||||
checkError(stmt, code);
|
||||
|
||||
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};
|
||||
int total_affect_rows = 0;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
ts[0] += 1000;
|
||||
ts[1] += 1000;
|
||||
|
@ -982,16 +996,15 @@ TEST(stmt2Case, stmt2_insert_db) {
|
|||
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);
|
||||
checkError(stmt, code);
|
||||
|
||||
int affected_rows;
|
||||
taos_stmt2_exec(stmt, &affected_rows);
|
||||
ASSERT_EQ(code, 0);
|
||||
total_affect_rows += affected_rows;
|
||||
checkError(stmt, code);
|
||||
}
|
||||
|
||||
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);
|
||||
ASSERT_EQ(total_affect_rows, 12);
|
||||
taos_stmt2_close(stmt);
|
||||
taos_close(taos);
|
||||
}
|
||||
|
@ -1017,7 +1030,7 @@ TEST(stmt2Case, stmt2_query) {
|
|||
|
||||
const char* sql = "select * from testdb7.stb where ts = ? and tbname = ?";
|
||||
int code = taos_stmt2_prepare(stmt, sql, 0);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
|
||||
int t64_len[1] = {sizeof(int64_t)};
|
||||
int b_len[1] = {3};
|
||||
|
@ -1027,10 +1040,10 @@ TEST(stmt2Case, stmt2_query) {
|
|||
TAOS_STMT2_BIND* paramv = ¶ms[0];
|
||||
TAOS_STMT2_BINDV bindv = {1, NULL, NULL, ¶mv};
|
||||
code = taos_stmt2_bind_param(stmt, &bindv, -1);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
|
||||
taos_stmt2_exec(stmt, NULL);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
|
||||
TAOS_RES* pRes = taos_stmt2_result(stmt);
|
||||
ASSERT_NE(pRes, nullptr);
|
||||
|
@ -1058,9 +1071,11 @@ TEST(stmt2Case, stmt2_ntb_insert) {
|
|||
TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
|
||||
ASSERT_NE(stmt, nullptr);
|
||||
|
||||
int total_affected_rows = 0;
|
||||
|
||||
const char* sql = "insert into testdb8.ntb values(?,?)";
|
||||
int code = taos_stmt2_prepare(stmt, sql, 0);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
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)};
|
||||
|
@ -1076,12 +1091,14 @@ TEST(stmt2Case, stmt2_ntb_insert) {
|
|||
|
||||
code = taos_stmt2_bind_param(stmt, &bindv1, 0);
|
||||
code = taos_stmt2_bind_param(stmt, &bindv2, 1);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
|
||||
code = taos_stmt2_exec(stmt, NULL);
|
||||
ASSERT_EQ(code, 0);
|
||||
int affected_rows;
|
||||
code = taos_stmt2_exec(stmt, &affected_rows);
|
||||
total_affected_rows += affected_rows;
|
||||
checkError(stmt, code);
|
||||
}
|
||||
checkRows(taos, "select * from testdb8.ntb", 9);
|
||||
ASSERT_EQ(total_affected_rows, 9);
|
||||
|
||||
taos_stmt2_close(stmt);
|
||||
taos_close(taos);
|
||||
|
@ -1194,7 +1211,7 @@ TEST(stmt2Case, stmt2_nchar) {
|
|||
params[5].num = 10;
|
||||
|
||||
int code = taos_stmt2_prepare(stmt, "insert into ? (ts, blob2, blob, blob3, blob4, blob5) values(?,?,?,?,?,?)", 0);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
|
||||
int64_t ts = 1591060628000;
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
|
@ -1219,13 +1236,15 @@ TEST(stmt2Case, stmt2_nchar) {
|
|||
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);
|
||||
checkError(stmt, code);
|
||||
|
||||
code = taos_stmt2_exec(stmt, NULL);
|
||||
ASSERT_EQ(code, 0);
|
||||
int affected_rows;
|
||||
code = taos_stmt2_exec(stmt, &affected_rows);
|
||||
checkError(stmt, code);
|
||||
ASSERT_EQ(affected_rows, 10);
|
||||
|
||||
taos_stmt2_close(stmt);
|
||||
|
||||
taos_close(taos);
|
||||
taosMemoryFree(blob_len);
|
||||
taosMemoryFree(blob_len2);
|
||||
taosMemoryFree(blob_len5);
|
||||
|
@ -1239,16 +1258,16 @@ TEST(stmt2Case, all_type) {
|
|||
|
||||
do_query(taos, "drop database if exists testdb11");
|
||||
do_query(taos, "create database IF NOT EXISTS testdb11");
|
||||
do_query(taos,
|
||||
"create stable testdb11.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))");
|
||||
do_query(
|
||||
taos,
|
||||
"create stable testdb11.stb(ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 binary(8), c6 smallint, c7 "
|
||||
"tinyint, c8 bool, c9 nchar(8), c10 geometry(256))TAGS(tts timestamp, t1 int, t2 bigint, t3 float, t4 double, t5 "
|
||||
"binary(8), t6 smallint, t7 tinyint, t8 bool, t9 nchar(8), t10 geometry(256))");
|
||||
|
||||
TAOS_STMT2_OPTION option = {0};
|
||||
TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
|
||||
ASSERT_NE(stmt, nullptr);
|
||||
|
||||
int code = 0;
|
||||
uintptr_t c10len = 0;
|
||||
struct {
|
||||
int64_t c1;
|
||||
|
@ -1340,22 +1359,102 @@ TEST(stmt2Case, all_type) {
|
|||
params[9].is_null = NULL;
|
||||
params[9].num = 1;
|
||||
|
||||
char* stmt_sql = "insert into testdb11.? using stb tags(?,?,?,?,?,?,?,?,?,?)values (?,?,?,?,?,?,?,?,?,?)";
|
||||
int code = taos_stmt2_prepare(stmt, stmt_sql, 0);
|
||||
ASSERT_EQ(code, 0);
|
||||
unsigned char* outputGeom1;
|
||||
size_t size1;
|
||||
initCtxMakePoint();
|
||||
code = doMakePoint(1.000, 2.000, &outputGeom1, &size1);
|
||||
checkError(stmt, code);
|
||||
params[10].buffer_type = TSDB_DATA_TYPE_GEOMETRY;
|
||||
params[10].buffer = outputGeom1;
|
||||
params[10].length = (int32_t*)&size1;
|
||||
params[10].is_null = NULL;
|
||||
params[10].num = 1;
|
||||
|
||||
char* tbname = "tb1";
|
||||
char* stmt_sql = "insert into testdb11.? using stb tags(?,?,?,?,?,?,?,?,?,?,?)values (?,?,?,?,?,?,?,?,?,?,?)";
|
||||
code = taos_stmt2_prepare(stmt, stmt_sql, 0);
|
||||
checkError(stmt, code);
|
||||
|
||||
char* tbname[1] = {"tb1"};
|
||||
TAOS_STMT2_BIND* tags = ¶ms[0];
|
||||
TAOS_STMT2_BIND* cols = ¶ms[0];
|
||||
TAOS_STMT2_BINDV bindv = {1, &tbname, &tags, &cols};
|
||||
TAOS_STMT2_BINDV bindv = {1, &tbname[0], &tags, &cols};
|
||||
code = taos_stmt2_bind_param(stmt, &bindv, -1);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
|
||||
code = taos_stmt2_exec(stmt, NULL);
|
||||
ASSERT_EQ(code, 0);
|
||||
int affected_rows;
|
||||
code = taos_stmt2_exec(stmt, &affected_rows);
|
||||
checkError(stmt, code);
|
||||
ASSERT_EQ(affected_rows, 1);
|
||||
|
||||
geosFreeBuffer(outputGeom1);
|
||||
taos_stmt2_close(stmt);
|
||||
taos_close(taos);
|
||||
}
|
||||
|
||||
TEST(stmt2Case, geometry) {
|
||||
TAOS* taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(taos, nullptr);
|
||||
|
||||
do_query(taos, "DROP DATABASE IF EXISTS testdb15");
|
||||
do_query(taos, "CREATE DATABASE IF NOT EXISTS testdb15");
|
||||
do_query(taos, "CREATE TABLE testdb15.tb1(ts timestamp,c1 geometry(256))");
|
||||
|
||||
TAOS_STMT2_OPTION option = {0};
|
||||
TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
|
||||
ASSERT_NE(stmt, nullptr);
|
||||
|
||||
unsigned char wkb1[] = { // 1
|
||||
0x01, // 字节顺序:小端字节序
|
||||
0x01, 0x00, 0x00, 0x00, // 几何类型:Point (1)
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, // p1
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, // p2
|
||||
// 2
|
||||
0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0,
|
||||
0x3f,
|
||||
// 3
|
||||
0x01,
|
||||
0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0,
|
||||
0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x40};
|
||||
|
||||
// unsigned char* wkb_all[3]{&wkb1[0], &wkb2[0], &wkb3[0]};
|
||||
int32_t wkb_len[3] = {21, 61, 41};
|
||||
|
||||
int64_t ts[3] = {1591060628000, 1591060628001, 1591060628002};
|
||||
int32_t t64_len[3] = {sizeof(int64_t), sizeof(int64_t), sizeof(int64_t)};
|
||||
|
||||
TAOS_STMT2_BIND params[2];
|
||||
params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
params[0].buffer = &ts[0];
|
||||
params[0].length = &t64_len[0];
|
||||
params[0].is_null = NULL;
|
||||
params[0].num = 3;
|
||||
|
||||
params[1].buffer_type = TSDB_DATA_TYPE_GEOMETRY;
|
||||
params[1].buffer = &wkb1[0];
|
||||
params[1].length = &wkb_len[0];
|
||||
params[1].is_null = NULL;
|
||||
params[1].num = 3;
|
||||
|
||||
char* stmt_sql = "insert into testdb15.tb1 (ts,c1)values(?,?)";
|
||||
int code = taos_stmt2_prepare(stmt, stmt_sql, 0);
|
||||
checkError(stmt, code);
|
||||
|
||||
TAOS_STMT2_BIND* cols = ¶ms[0];
|
||||
TAOS_STMT2_BINDV bindv = {1, NULL, NULL, &cols};
|
||||
code = taos_stmt2_bind_param(stmt, &bindv, -1);
|
||||
checkError(stmt, code);
|
||||
|
||||
int affected_rows;
|
||||
code = taos_stmt2_exec(stmt, &affected_rows);
|
||||
checkError(stmt, code);
|
||||
ASSERT_EQ(affected_rows, 3);
|
||||
|
||||
taos_stmt2_close(stmt);
|
||||
taos_close(taos);
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <string.h>
|
||||
#include "clientInt.h"
|
||||
#include "geosWrapper.h"
|
||||
#include "osSemaphore.h"
|
||||
#include "taoserror.h"
|
||||
#include "tglobal.h"
|
||||
|
@ -33,23 +34,29 @@
|
|||
#include "taos.h"
|
||||
|
||||
namespace {
|
||||
|
||||
void checkError(TAOS_STMT *stmt, int code) {
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
STscStmt *pStmt = (STscStmt *)stmt;
|
||||
if (pStmt == nullptr || pStmt->sql.sqlStr == nullptr) {
|
||||
printf("stmt api error\n stats : %d\n errstr : %s\n", pStmt->sql.status, taos_stmt_errstr(stmt));
|
||||
} else {
|
||||
printf("stmt api error\n sql : %s\n stats : %d\n errstr : %s\n", pStmt->sql.sqlStr, pStmt->sql.status,
|
||||
taos_stmt_errstr(stmt));
|
||||
}
|
||||
ASSERT_EQ(code, TSDB_CODE_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
void do_query(TAOS *taos, const char *sql) {
|
||||
TAOS_RES *result = taos_query(taos, sql);
|
||||
// printf("sql: %s\n", sql);
|
||||
ASSERT_EQ(taos_errno(result), TSDB_CODE_SUCCESS);
|
||||
taos_free_result(result);
|
||||
}
|
||||
|
||||
void checkRows(TAOS *pConn, const char *sql, int32_t expectedRows) {
|
||||
TAOS_RES *pRes = taos_query(pConn, sql);
|
||||
ASSERT_EQ(taos_errno(pRes), TSDB_CODE_SUCCESS);
|
||||
TAOS_ROW pRow = NULL;
|
||||
int rows = 0;
|
||||
while ((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
rows++;
|
||||
int code = taos_errno(result);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
printf("query failen sql : %s\n errstr : %s\n", sql, taos_errstr(result));
|
||||
ASSERT_EQ(taos_errno(result), TSDB_CODE_SUCCESS);
|
||||
}
|
||||
ASSERT_EQ(rows, expectedRows);
|
||||
taos_free_result(pRes);
|
||||
taos_free_result(result);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
|
@ -62,13 +69,12 @@ typedef struct {
|
|||
void insertData(TAOS *taos, TAOS_STMT_OPTIONS *option, const char *sql, int CTB_NUMS, int ROW_NUMS, int CYC_NUMS,
|
||||
bool isCreateTable) {
|
||||
// create database and table
|
||||
do_query(taos, "DROP DATABASE IF EXISTS stmttest_db_1");
|
||||
do_query(taos, "CREATE DATABASE IF NOT EXISTS stmttest_db_1");
|
||||
do_query(
|
||||
taos,
|
||||
"CREATE STABLE IF NOT EXISTS stmttest_db_1.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS "
|
||||
"(groupId INT, location BINARY(24))");
|
||||
do_query(taos, "USE stmttest_db_1");
|
||||
do_query(taos, "DROP DATABASE IF EXISTS testdb2");
|
||||
do_query(taos, "CREATE DATABASE IF NOT EXISTS testdb2");
|
||||
do_query(taos,
|
||||
"CREATE STABLE IF NOT EXISTS testdb2.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS "
|
||||
"(groupId INT, location BINARY(24))");
|
||||
do_query(taos, "USE testdb2");
|
||||
|
||||
// init
|
||||
TAOS_STMT *stmt;
|
||||
|
@ -79,7 +85,7 @@ void insertData(TAOS *taos, TAOS_STMT_OPTIONS *option, const char *sql, int CTB_
|
|||
}
|
||||
ASSERT_NE(stmt, nullptr);
|
||||
int code = taos_stmt_prepare(stmt, sql, 0);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
int total_affected = 0;
|
||||
|
||||
for (int k = 0; k < CYC_NUMS; k++) {
|
||||
|
@ -118,23 +124,23 @@ void insertData(TAOS *taos, TAOS_STMT_OPTIONS *option, const char *sql, int CTB_
|
|||
if (!isCreateTable) {
|
||||
if (k % 2 == 0) {
|
||||
code = taos_stmt_set_tbname_tags(stmt, table_name, tags);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
|
||||
} else {
|
||||
if (i % 2 == 0) {
|
||||
code = taos_stmt_set_tbname(stmt, table_name);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
} else {
|
||||
code = taos_stmt_set_sub_tbname(stmt, table_name);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
}
|
||||
|
||||
code = taos_stmt_set_tags(stmt, tags);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
}
|
||||
} else {
|
||||
code = taos_stmt_set_tbname(stmt, table_name);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
}
|
||||
|
||||
// insert rows
|
||||
|
@ -177,14 +183,14 @@ void insertData(TAOS *taos, TAOS_STMT_OPTIONS *option, const char *sql, int CTB_
|
|||
params[3].buffer = &phase;
|
||||
// bind param
|
||||
code = taos_stmt_bind_param(stmt, params);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
}
|
||||
// add batch
|
||||
code = taos_stmt_add_batch(stmt);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
// execute batch
|
||||
code = taos_stmt_execute(stmt);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
// get affected rows
|
||||
int affected = taos_stmt_affected_rows_once(stmt);
|
||||
total_affected += affected;
|
||||
|
@ -194,7 +200,6 @@ void insertData(TAOS *taos, TAOS_STMT_OPTIONS *option, const char *sql, int CTB_
|
|||
}
|
||||
}
|
||||
ASSERT_EQ(total_affected, CTB_NUMS * ROW_NUMS * CYC_NUMS);
|
||||
checkRows(taos, "select * from meters", CTB_NUMS * ROW_NUMS * CYC_NUMS);
|
||||
|
||||
taos_stmt_close(stmt);
|
||||
}
|
||||
|
@ -202,29 +207,28 @@ void insertData(TAOS *taos, TAOS_STMT_OPTIONS *option, const char *sql, int CTB_
|
|||
void getFields(TAOS *taos, const char *sql, int expectedALLFieldNum, TAOS_FIELD_E *expectedTagFields,
|
||||
int expectedTagFieldNum, TAOS_FIELD_E *expectedColFields, int expectedColFieldNum) {
|
||||
// create database and table
|
||||
do_query(taos, "DROP DATABASE IF EXISTS stmttest_db_2");
|
||||
do_query(taos, "CREATE DATABASE IF NOT EXISTS stmttest_db_2");
|
||||
do_query(taos, "USE stmttest_db_2");
|
||||
do_query(
|
||||
taos,
|
||||
"CREATE STABLE IF NOT EXISTS stmttest_db_2.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS "
|
||||
"(groupId INT, location BINARY(24))");
|
||||
do_query(taos, "DROP DATABASE IF EXISTS testdb3");
|
||||
do_query(taos, "CREATE DATABASE IF NOT EXISTS testdb3");
|
||||
do_query(taos, "USE testdb3");
|
||||
do_query(taos,
|
||||
"CREATE STABLE IF NOT EXISTS testdb3.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS "
|
||||
"(groupId INT, location BINARY(24))");
|
||||
|
||||
TAOS_STMT *stmt = taos_stmt_init(taos);
|
||||
ASSERT_NE(stmt, nullptr);
|
||||
int code = taos_stmt_prepare(stmt, sql, 0);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
code = taos_stmt_set_tbname(stmt, "ctb_1");
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
|
||||
int fieldNum = 0;
|
||||
TAOS_FIELD_E *pFields = NULL;
|
||||
code = stmtGetParamNum(stmt, &fieldNum);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
ASSERT_EQ(fieldNum, expectedColFieldNum);
|
||||
|
||||
code = taos_stmt_get_tag_fields(stmt, &fieldNum, &pFields);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
ASSERT_EQ(fieldNum, expectedTagFieldNum);
|
||||
for (int i = 0; i < fieldNum; i++) {
|
||||
ASSERT_STREQ(pFields[i].name, expectedTagFields[i].name);
|
||||
|
@ -238,7 +242,7 @@ void getFields(TAOS *taos, const char *sql, int expectedALLFieldNum, TAOS_FIELD_
|
|||
int type;
|
||||
int bytes;
|
||||
code = taos_stmt_get_col_fields(stmt, &fieldNum, &pFields);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
ASSERT_EQ(fieldNum, expectedColFieldNum);
|
||||
for (int i = 0; i < fieldNum; i++) {
|
||||
taos_stmt_get_param(stmt, i, &type, &bytes);
|
||||
|
@ -267,7 +271,7 @@ TEST(stmtCase, stb_insert) {
|
|||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(taos, nullptr);
|
||||
// interlace = 0
|
||||
{ insertData(taos, nullptr, "INSERT INTO stmttest_db_1.? USING meters TAGS(?,?) VALUES (?,?,?,?)", 1, 1, 1, false); }
|
||||
{ insertData(taos, nullptr, "INSERT INTO testdb2.? USING meters TAGS(?,?) VALUES (?,?,?,?)", 1, 1, 1, false); }
|
||||
|
||||
{ insertData(taos, nullptr, "INSERT INTO ? USING meters TAGS(?,?) VALUES (?,?,?,?)", 3, 3, 3, false); }
|
||||
|
||||
|
@ -297,19 +301,18 @@ 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 stmt_db");
|
||||
do_query(taos, "create database IF NOT EXISTS stmt_db");
|
||||
do_query(taos,
|
||||
"create stable stmt_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))");
|
||||
|
||||
do_query(taos, "DROP DATABASE IF EXISTS testdb1");
|
||||
do_query(taos, "CREATE DATABASE IF NOT EXISTS testdb1");
|
||||
do_query(
|
||||
taos,
|
||||
"create stable testdb1.stb(ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 binary(8), c6 smallint, c7 "
|
||||
"tinyint, c8 bool, c9 nchar(8), c10 geometry(100))TAGS(tts timestamp, t1 int, t2 bigint, t3 float, t4 double, t5 "
|
||||
"binary(8), t6 smallint, t7 tinyint, t8 bool, t9 nchar(8), t10 geometry(100))");
|
||||
|
||||
TAOS_STMT *stmt = taos_stmt_init(taos);
|
||||
ASSERT_NE(stmt, nullptr);
|
||||
|
@ -326,7 +329,24 @@ c7 " "tinyint, c8 bool, c9 nchar(8))TAGS(tts timestamp, t1 int, t2 bigint, t3 fl
|
|||
int8_t c8;
|
||||
int8_t c9;
|
||||
char c10[32];
|
||||
} v = {0};
|
||||
} 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_MULTI_BIND params[11];
|
||||
params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
params[0].buffer_length = sizeof(v.c1);
|
||||
|
@ -398,38 +418,110 @@ c7 " "tinyint, c8 bool, c9 nchar(8))TAGS(tts timestamp, t1 int, t2 bigint, t3 fl
|
|||
params[9].is_null = NULL;
|
||||
params[9].num = 1;
|
||||
|
||||
char *stmt_sql = "insert into stmt_db.? using stb tags(?,?,?,?,?,?,?,?,?,?)values (?,?,?,?,?,?,?,?,?,?)";
|
||||
int code = taos_stmt_prepare(stmt, stmt_sql, 0);
|
||||
ASSERT_EQ(code, 0);
|
||||
unsigned char *outputGeom1;
|
||||
size_t size1;
|
||||
initCtxMakePoint();
|
||||
int code = doMakePoint(1.000, 2.000, &outputGeom1, &size1);
|
||||
checkError(stmt, code);
|
||||
params[10].buffer_type = TSDB_DATA_TYPE_GEOMETRY;
|
||||
params[10].buffer = outputGeom1;
|
||||
params[10].length = (int32_t *)&size1;
|
||||
params[10].is_null = NULL;
|
||||
params[10].num = 1;
|
||||
|
||||
char *stmt_sql = "insert into testdb1.? using stb tags(?,?,?,?,?,?,?,?,?,?,?)values (?,?,?,?,?,?,?,?,?,?,?)";
|
||||
code = taos_stmt_prepare(stmt, stmt_sql, 0);
|
||||
checkError(stmt, code);
|
||||
|
||||
code = taos_stmt_set_tbname(stmt, "ntb");
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
|
||||
code = taos_stmt_set_tags(stmt, params);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
|
||||
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_bind_param(stmt, params);
|
||||
checkError(stmt, code);
|
||||
|
||||
code = taos_stmt_add_batch(stmt);
|
||||
checkError(stmt, code);
|
||||
|
||||
code = taos_stmt_execute(stmt);
|
||||
ASSERT_EQ(code, 0);
|
||||
checkError(stmt, code);
|
||||
|
||||
taos_stmt_close(stmt);
|
||||
taos_close(taos);
|
||||
}
|
||||
*/
|
||||
|
||||
TEST(stmtCase, geometry) {
|
||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(taos, nullptr);
|
||||
|
||||
do_query(taos, "DROP DATABASE IF EXISTS testdb5");
|
||||
do_query(taos, "CREATE DATABASE IF NOT EXISTS testdb5");
|
||||
do_query(taos, "CREATE TABLE testdb5.tb1(ts timestamp,c1 geometry(256))");
|
||||
|
||||
TAOS_STMT *stmt = taos_stmt_init(taos);
|
||||
ASSERT_NE(stmt, nullptr);
|
||||
unsigned char wkb1[3][61] = {
|
||||
{
|
||||
0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40,
|
||||
},
|
||||
//
|
||||
{0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f},
|
||||
{0x01, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40}};
|
||||
|
||||
int64_t ts[3] = {1591060628000, 1591060628001, 1591060628002};
|
||||
int32_t *t64_len = (int32_t *)taosMemoryMalloc(sizeof(int32_t) * 3);
|
||||
int32_t *wkb_len = (int32_t *)taosMemoryMalloc(sizeof(int32_t) * 3);
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
t64_len[i] = sizeof(int64_t);
|
||||
}
|
||||
wkb_len[0] = 21;
|
||||
wkb_len[1] = 61;
|
||||
wkb_len[2] = 41;
|
||||
|
||||
TAOS_MULTI_BIND params[2];
|
||||
params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
params[0].buffer_length = sizeof(int64_t);
|
||||
params[0].buffer = &ts[0];
|
||||
params[0].length = t64_len;
|
||||
params[0].is_null = NULL;
|
||||
params[0].num = 3;
|
||||
|
||||
params[1].buffer_type = TSDB_DATA_TYPE_GEOMETRY;
|
||||
params[1].buffer_length = 61;
|
||||
params[1].buffer = wkb1;
|
||||
params[1].length = wkb_len;
|
||||
params[1].is_null = NULL;
|
||||
params[1].num = 3;
|
||||
|
||||
char *stmt_sql = "insert into testdb5.tb1 (ts,c1)values(?,?)";
|
||||
int code = taos_stmt_prepare(stmt, stmt_sql, 0);
|
||||
checkError(stmt, code);
|
||||
|
||||
// code = taos_stmt_set_tbname(stmt, "tb1");
|
||||
// checkError(stmt, code);
|
||||
|
||||
code = taos_stmt_bind_param_batch(stmt, params);
|
||||
checkError(stmt, code);
|
||||
|
||||
code = taos_stmt_add_batch(stmt);
|
||||
checkError(stmt, code);
|
||||
|
||||
code = taos_stmt_execute(stmt);
|
||||
checkError(stmt, code);
|
||||
|
||||
taosMemoryFree(t64_len);
|
||||
taosMemoryFree(wkb_len);
|
||||
taos_stmt_close(stmt);
|
||||
taos_close(taos);
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic pop
|
|
@ -325,11 +325,6 @@ int32_t checkWKB(const unsigned char *wkb, size_t size) {
|
|||
return TSDB_CODE_FUNC_FUNTION_PARA_VALUE;
|
||||
}
|
||||
|
||||
if (!GEOSisValid_r(geosCtx->handle, geom)) {
|
||||
code = TSDB_CODE_FUNC_FUNTION_PARA_VALUE;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
_exit:
|
||||
if (geom) {
|
||||
GEOSGeom_destroy_r(geosCtx->handle, geom);
|
||||
|
|
Loading…
Reference in New Issue