• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #3809

01 Apr 2025 03:03AM UTC coverage: 34.048% (+0.02%) from 34.033%
#3809

push

travis-ci

happyguoxy
test:alter gcda dir

148452 of 599532 branches covered (24.76%)

Branch coverage included in aggregate %.

222312 of 489411 relevant lines covered (45.42%)

761122.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

49.16
/source/client/test/stmt2Test.cpp
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#include <gtest/gtest.h>
17
#include <string.h>
18
#include <atomic>
19
#include <chrono>
20
#include <thread>
21
#include "clientInt.h"
22
#include "geosWrapper.h"
23
#include "osSemaphore.h"
24
#include "taoserror.h"
25
#include "tglobal.h"
26
#include "thash.h"
27

28
#pragma GCC diagnostic push
29
#pragma GCC diagnostic ignored "-Wwrite-strings"
30
#pragma GCC diagnostic ignored "-Wunused-function"
31
#pragma GCC diagnostic ignored "-Wunused-variable"
32
#pragma GCC diagnostic ignored "-Wsign-compare"
33

34
#include "../inc/clientStmt.h"
35
#include "../inc/clientStmt2.h"
36
#include "executor.h"
37
#include "taos.h"
38

39
namespace {
40
void checkError(TAOS_STMT2* stmt, int code) {
259✔
41
  if (code != TSDB_CODE_SUCCESS) {
259!
42
    STscStmt2* pStmt = (STscStmt2*)stmt;
×
43
    if (pStmt == nullptr || pStmt->sql.sqlStr == nullptr || pStmt->exec.pRequest == nullptr) {
×
44
      printf("stmt api error\n  stats : %d\n  errstr : %s\n", pStmt->sql.status, taos_stmt_errstr(stmt));
×
45
    } else {
46
      printf("stmt api error\n  sql : %s\n  stats : %d\n", pStmt->sql.sqlStr, pStmt->sql.status);
×
47
    }
48
    ASSERT_EQ(code, TSDB_CODE_SUCCESS);
×
49
  }
50
}
51

52
typedef struct AsyncArgs {
53
  int    async_affected_rows;
54
  tsem_t sem;
55
} AsyncArgs;
56

57
void stmtAsyncQueryCb(void* param, TAOS_RES* pRes, int code) {
12✔
58
  ((AsyncArgs*)param)->async_affected_rows = taos_affected_rows(pRes);
12✔
59
  ASSERT_EQ(tsem_post(&((AsyncArgs*)param)->sem), TSDB_CODE_SUCCESS);
12!
60
  return;
12✔
61
}
62

63
void getFieldsSuccess(TAOS* taos, const char* sql, TAOS_FIELD_ALL* expectedFields, int expectedFieldNum) {
23✔
64
  TAOS_STMT2_OPTION option = {0};
23✔
65
  TAOS_STMT2*       stmt = taos_stmt2_init(taos, &option);
23!
66
  ASSERT_NE(stmt, nullptr);
23!
67
  int code = taos_stmt2_prepare(stmt, sql, 0);
23!
68
  checkError(stmt, code);
23!
69

70
  int             fieldNum = 0;
23✔
71
  TAOS_FIELD_ALL* pFields = NULL;
23✔
72
  code = taos_stmt2_get_fields(stmt, &fieldNum, &pFields);
23!
73
  checkError(stmt, code);
23!
74
  ASSERT_EQ(fieldNum, expectedFieldNum);
23!
75

76
  for (int i = 0; i < fieldNum; i++) {
184✔
77
    ASSERT_STREQ(pFields[i].name, expectedFields[i].name);
161!
78
    ASSERT_EQ(pFields[i].type, expectedFields[i].type);
161!
79
    ASSERT_EQ(pFields[i].field_type, expectedFields[i].field_type);
161!
80
    ASSERT_EQ(pFields[i].precision, expectedFields[i].precision);
161!
81
    ASSERT_EQ(pFields[i].bytes, expectedFields[i].bytes);
161!
82
    ASSERT_EQ(pFields[i].scale, expectedFields[i].scale);
161!
83
  }
84
  taos_stmt2_free_fields(stmt, pFields);
23!
85
  taos_stmt2_close(stmt);
23!
86
}
87

88
void getFieldsError(TAOS* taos, const char* sql, int errorCode) {
21✔
89
  TAOS_STMT2_OPTION option = {0};
21✔
90
  TAOS_STMT2*       stmt = taos_stmt2_init(taos, &option);
21!
91
  ASSERT_NE(stmt, nullptr);
21!
92
  int code = taos_stmt2_prepare(stmt, sql, 0);
21!
93
  checkError(stmt, code);
21!
94

95
  int             fieldNum = 0;
21✔
96
  TAOS_FIELD_ALL* pFields = NULL;
21✔
97
  code = taos_stmt2_get_fields(stmt, &fieldNum, &pFields);
21!
98
  ASSERT_EQ(code, errorCode);
21!
99
  taos_stmt2_free_fields(stmt, pFields);
21!
100
  taos_stmt2_close(stmt);
21!
101
}
102

103
void getQueryFields(TAOS* taos, const char* sql, int expectedFieldNum) {
2✔
104
  TAOS_STMT2_OPTION option = {0};
2✔
105
  TAOS_STMT2*       stmt = taos_stmt2_init(taos, &option);
2!
106
  ASSERT_NE(stmt, nullptr);
2!
107
  int code = taos_stmt2_prepare(stmt, sql, 0);
2!
108
  checkError(stmt, code);
2!
109

110
  int             fieldNum = 0;
2✔
111
  TAOS_FIELD_ALL* pFields = NULL;
2✔
112
  code = taos_stmt2_get_fields(stmt, &fieldNum, NULL);
2!
113
  checkError(stmt, code);
2!
114
  ASSERT_EQ(fieldNum, expectedFieldNum);
2!
115
  taos_stmt2_free_fields(stmt, NULL);
2!
116
  taos_stmt2_close(stmt);
2!
117
}
118

119
void do_query(TAOS* taos, const char* sql) {
158✔
120
  TAOS_RES* result = taos_query(taos, sql);
158✔
121
  // printf("sql: %s\n", sql);
122
  int code = taos_errno(result);
158✔
123
  while (code == TSDB_CODE_MND_DB_IN_CREATING || code == TSDB_CODE_MND_DB_IN_DROPPING) {
158!
124
    taosMsleep(2000);
×
125
    result = taos_query(taos, sql);
×
126
    code = taos_errno(result);
×
127
  }
128
  if (code != TSDB_CODE_SUCCESS) {
158!
129
    printf("query failen  sql : %s\n  errstr : %s\n", sql, taos_errstr(result));
×
130
    ASSERT_EQ(taos_errno(result), TSDB_CODE_SUCCESS);
×
131
  }
132
  taos_free_result(result);
158✔
133
}
134

135
void do_stmt(const char* msg, TAOS* taos, TAOS_STMT2_OPTION* option, const char* sql, int CTB_NUMS, int ROW_NUMS,
15✔
136
             int CYC_NUMS, bool hastags, bool createTable) {
137
  printf("stmt2 [%s] : %s\n", msg, sql);
15!
138
  do_query(taos, "drop database if exists stmt2_testdb_1");
15!
139
  do_query(taos, "create database IF NOT EXISTS stmt2_testdb_1");
15!
140
  do_query(taos, "create stable stmt2_testdb_1.stb (ts timestamp, b binary(10)) tags(t1 int, t2 binary(10))");
15!
141

142
  TAOS_STMT2* stmt = taos_stmt2_init(taos, option);
15!
143
  ASSERT_NE(stmt, nullptr);
15!
144
  int code = taos_stmt2_prepare(stmt, sql, 0);
15!
145
  checkError(stmt, code);
15!
146
  int total_affected = 0;
15✔
147

148
  // tbname
149
  char** tbs = (char**)taosMemoryMalloc(CTB_NUMS * sizeof(char*));
15!
150
  for (int i = 0; i < CTB_NUMS; i++) {
60✔
151
    tbs[i] = (char*)taosMemoryMalloc(sizeof(char) * 20);
45!
152
    sprintf(tbs[i], "ctb_%d", i);
45✔
153
    if (createTable) {
45✔
154
      char* tmp = (char*)taosMemoryMalloc(sizeof(char) * 100);
30!
155
      sprintf(tmp, "create table stmt2_testdb_1.%s using stmt2_testdb_1.stb tags(0, 'after')", tbs[i]);
30✔
156
      do_query(taos, tmp);
30!
157
    }
158
  }
159
  for (int r = 0; r < CYC_NUMS; r++) {
60✔
160
    // col params
161
    int64_t** ts = (int64_t**)taosMemoryMalloc(CTB_NUMS * sizeof(int64_t*));
45!
162
    char**    b = (char**)taosMemoryMalloc(CTB_NUMS * sizeof(char*));
45!
163
    int*      ts_len = (int*)taosMemoryMalloc(ROW_NUMS * sizeof(int));
45!
164
    int*      b_len = (int*)taosMemoryMalloc(ROW_NUMS * sizeof(int));
45!
165
    for (int i = 0; i < ROW_NUMS; i++) {
180✔
166
      ts_len[i] = sizeof(int64_t);
135✔
167
      b_len[i] = 1;
135✔
168
    }
169
    for (int i = 0; i < CTB_NUMS; i++) {
180✔
170
      ts[i] = (int64_t*)taosMemoryMalloc(ROW_NUMS * sizeof(int64_t));
135!
171
      b[i] = (char*)taosMemoryMalloc(ROW_NUMS * sizeof(char));
135!
172
      for (int j = 0; j < ROW_NUMS; j++) {
540✔
173
        ts[i][j] = 1591060628000 + r * 100000 + j;
405✔
174
        b[i][j] = 'a' + j;
405✔
175
      }
176
    }
177
    // tag params
178
    int t1 = 0;
45✔
179
    int t1len = sizeof(int);
45✔
180
    int t2len = 3;
45✔
181
    //   TAOS_STMT2_BIND* tagv[2] = {&tags[0][0], &tags[1][0]};
182

183
    // bind params
184
    TAOS_STMT2_BIND** paramv = (TAOS_STMT2_BIND**)taosMemoryMalloc(CTB_NUMS * sizeof(TAOS_STMT2_BIND*));
45!
185
    TAOS_STMT2_BIND** tags = NULL;
45✔
186
    if (hastags) {
45✔
187
      tags = (TAOS_STMT2_BIND**)taosMemoryMalloc(CTB_NUMS * sizeof(TAOS_STMT2_BIND*));
27!
188
      for (int i = 0; i < CTB_NUMS; i++) {
108✔
189
        // create tags
190
        tags[i] = (TAOS_STMT2_BIND*)taosMemoryMalloc(2 * sizeof(TAOS_STMT2_BIND));
81!
191
        tags[i][0] = {TSDB_DATA_TYPE_INT, &t1, &t1len, NULL, 0};
81✔
192
        tags[i][1] = {TSDB_DATA_TYPE_BINARY, (void*)"after", &t2len, NULL, 0};
81✔
193
      }
194
    }
195

196
    for (int i = 0; i < CTB_NUMS; i++) {
180✔
197
      // create col params
198
      paramv[i] = (TAOS_STMT2_BIND*)taosMemoryMalloc(2 * sizeof(TAOS_STMT2_BIND));
135!
199
      paramv[i][0] = {TSDB_DATA_TYPE_TIMESTAMP, &ts[i][0], &ts_len[0], NULL, ROW_NUMS};
135✔
200
      paramv[i][1] = {TSDB_DATA_TYPE_BINARY, &b[i][0], &b_len[0], NULL, ROW_NUMS};
135✔
201
    }
202
    // bind
203
    TAOS_STMT2_BINDV bindv = {CTB_NUMS, tbs, tags, paramv};
45✔
204
    code = taos_stmt2_bind_param(stmt, &bindv, -1);
45!
205
    checkError(stmt, code);
45!
206

207
    // exec
208
    int affected = 0;
45✔
209
    code = taos_stmt2_exec(stmt, &affected);
45!
210
    if (option->asyncExecFn == NULL) {
45✔
211
      total_affected += affected;
33✔
212
    } else {
213
      AsyncArgs* params = (AsyncArgs*)option->userdata;
12✔
214
      code = tsem_wait(&params->sem);
12!
215
      ASSERT_EQ(code, TSDB_CODE_SUCCESS);
12!
216
      total_affected += params->async_affected_rows;
12✔
217
    }
218
    checkError(stmt, code);
45!
219

220
    for (int i = 0; i < CTB_NUMS; i++) {
180✔
221
      if (hastags) {
135✔
222
        taosMemoryFree(tags[i]);
81!
223
      }
224
      taosMemoryFree(paramv[i]);
135!
225
      taosMemoryFree(ts[i]);
135!
226
      taosMemoryFree(b[i]);
135!
227
    }
228
    taosMemoryFree(ts);
45!
229
    taosMemoryFree(b);
45!
230
    taosMemoryFree(ts_len);
45!
231
    taosMemoryFree(b_len);
45!
232
    taosMemoryFree(paramv);
45!
233
    if (hastags) {
45✔
234
      taosMemoryFree(tags);
27!
235
    }
236
  }
237
  ASSERT_EQ(total_affected, CYC_NUMS * ROW_NUMS * CTB_NUMS);
15!
238
  for (int i = 0; i < CTB_NUMS; i++) {
60✔
239
    taosMemoryFree(tbs[i]);
45!
240
  }
241
  taosMemoryFree(tbs);
15!
242

243
  taos_stmt2_close(stmt);
15!
244
}
245

246
}  // namespace
247

248
int main(int argc, char** argv) {
1✔
249
  testing::InitGoogleTest(&argc, argv);
1✔
250
  return RUN_ALL_TESTS();
1✔
251
}
252

253
TEST(stmt2Case, stmt2_test_limit) {
4✔
254
  TAOS* taos = taos_connect("localhost", "root", "taosdata", "", 0);
1!
255
  ASSERT_NE(taos, nullptr);
1!
256
  do_query(taos, "drop database if exists stmt2_testdb_7");
1!
257
  do_query(taos, "create database IF NOT EXISTS stmt2_testdb_7");
1!
258
  do_query(taos, "create stable stmt2_testdb_7.stb (ts timestamp, b binary(10)) tags(t1 int, t2 binary(10))");
1!
259
  do_query(taos,
1!
260
           "insert into stmt2_testdb_7.tb2 using stmt2_testdb_7.stb tags(2,'xyz') values(1591060628000, "
261
           "'abc'),(1591060628001,'def'),(1591060628004, 'hij')");
262
  do_query(taos, "use stmt2_testdb_7");
1!
263

264
  TAOS_STMT2_OPTION option = {0, true, true, NULL, NULL};
1✔
265

266
  TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
1!
267
  ASSERT_NE(stmt, nullptr);
1!
268

269
  const char* sql = "select * from stmt2_testdb_7.tb2 where ts > ? and ts < ? limit ?";
1✔
270
  int         code = taos_stmt2_prepare(stmt, sql, 0);
1!
271
  checkError(stmt, code);
1!
272

273
  int              t64_len[1] = {sizeof(int64_t)};
1✔
274
  int              b_len[1] = {3};
1✔
275
  int              x = 2;
1✔
276
  int              x_len = sizeof(int);
1✔
277
  int64_t          ts[2] = {1591060627000, 1591060628005};
1✔
278
  TAOS_STMT2_BIND  params[3] = {{TSDB_DATA_TYPE_TIMESTAMP, &ts[0], t64_len, NULL, 1},
1✔
279
                                {TSDB_DATA_TYPE_TIMESTAMP, &ts[1], t64_len, NULL, 1},
280
                                {TSDB_DATA_TYPE_INT, &x, &x_len, NULL, 1}};
1✔
281
  TAOS_STMT2_BIND* paramv = &params[0];
1✔
282
  TAOS_STMT2_BINDV bindv = {1, NULL, NULL, &paramv};
1✔
283
  code = taos_stmt2_bind_param(stmt, &bindv, -1);
1!
284
  checkError(stmt, code);
1!
285

286
  taos_stmt2_exec(stmt, NULL);
1!
287
  checkError(stmt, code);
1!
288

289
  TAOS_RES* pRes = taos_stmt2_result(stmt);
1!
290
  ASSERT_NE(pRes, nullptr);
1!
291

292
  int getRecordCounts = 0;
1✔
293
  while ((taos_fetch_row(pRes))) {
3!
294
    getRecordCounts++;
2✔
295
  }
296
  ASSERT_EQ(getRecordCounts, 2);
1!
297
  taos_stmt2_close(stmt);
1!
298
  do_query(taos, "drop database if exists stmt2_testdb_7");
1!
299
  taos_close(taos);
1!
300
}
301

302
TEST(stmt2Case, insert_stb_get_fields_Test) {
4✔
303
  TAOS* taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
1!
304
  ASSERT_NE(taos, nullptr);
1!
305

306
  do_query(taos, "drop database if exists stmt2_testdb_2");
1!
307
  do_query(taos, "create database IF NOT EXISTS stmt2_testdb_2 PRECISION 'ns'");
1!
308
  do_query(taos,
1!
309
           "create stable stmt2_testdb_2.stb (ts timestamp, b binary(10)) tags(t1 "
310
           "int, t2 binary(10))");
311
  do_query(
1!
312
      taos,
313
      "create stable if not exists stmt2_testdb_2.all_stb(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 "
314
      "bigint, "
315
      "v6 tinyint unsigned, v7 smallint unsigned, v8 int unsigned, v9 bigint unsigned, v10 float, v11 double, v12 "
316
      "binary(20), v13 varbinary(20), v14 geometry(100), v15 nchar(20))tags(tts timestamp, tv1 bool, tv2 tinyint, tv3 "
317
      "smallint, tv4 int, tv5 bigint, tv6 tinyint unsigned, tv7 smallint unsigned, tv8 int unsigned, tv9 bigint "
318
      "unsigned, tv10 float, tv11 double, tv12 binary(20), tv13 varbinary(20), tv14 geometry(100), tv15 nchar(20));");
319
  printf("support case \n");
1!
320

321
  // case 1 : test super table
322
  {
323
    const char*    sql = "insert into stmt2_testdb_2.stb(t1,t2,ts,b,tbname) values(?,?,?,?,?)";
1✔
324
    TAOS_FIELD_ALL expectedFields[5] = {{"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
1✔
325
                                        {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
326
                                        {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
327
                                        {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL},
328
                                        {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}};
329
    printf("case 1 : %s\n", sql);
1!
330
    getFieldsSuccess(taos, sql, expectedFields, 5);
1!
331
  }
332

333
  {
334
    // case 2 : no tag
335
    const char*    sql = "insert into stmt2_testdb_2.stb(ts,b,tbname) values(?,?,?)";
1✔
336
    TAOS_FIELD_ALL expectedFields[3] = {{"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
1✔
337
                                        {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL},
338
                                        {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}};
339
    printf("case 2 : %s\n", sql);
1!
340
    getFieldsSuccess(taos, sql, expectedFields, 3);
1!
341
  }
342

343
  // case 3 : random order
344
  {
345
    const char*    sql = "insert into stmt2_testdb_2.stb(tbname,ts,t2,b,t1) values(?,?,?,?,?)";
1✔
346
    TAOS_FIELD_ALL expectedFields[5] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
1✔
347
                                        {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
348
                                        {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
349
                                        {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL},
350
                                        {"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG}};
351
    printf("case 3 : %s\n", sql);
1!
352
    getFieldsSuccess(taos, sql, expectedFields, 5);
1!
353
  }
354

355
  // case 4 : random order 2
356
  {
357
    const char*    sql = "insert into stmt2_testdb_2.stb(ts,tbname,b,t2,t1) values(?,?,?,?,?)";
1✔
358
    TAOS_FIELD_ALL expectedFields[5] = {{"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
1✔
359
                                        {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
360
                                        {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL},
361
                                        {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
362
                                        {"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG}};
363
    printf("case 4 : %s\n", sql);
1!
364
    getFieldsSuccess(taos, sql, expectedFields, 5);
1!
365
  }
366

367
  // case 5 : 'db'.'stb'
368
  {
369
    const char*    sql = "insert into 'stmt2_testdb_2'.'stb'(t1,t2,ts,b,tbname) values(?,?,?,?,?)";
1✔
370
    TAOS_FIELD_ALL expectedFields[5] = {{"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
1✔
371
                                        {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
372
                                        {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
373
                                        {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL},
374
                                        {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}};
375
    printf("case 5 : %s\n", sql);
1!
376
    getFieldsSuccess(taos, sql, expectedFields, 5);
1!
377
  }
378

379
  // case 6 : use db
380
  {
381
    do_query(taos, "use stmt2_testdb_2");
1!
382
    const char*    sql = "insert into stb(t1,t2,ts,b,tbname) values(?,?,?,?,?)";
1✔
383
    TAOS_FIELD_ALL expectedFields[5] = {{"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
1✔
384
                                        {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
385
                                        {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
386
                                        {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL},
387
                                        {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}};
388
    printf("case 6 : %s\n", sql);
1!
389
    getFieldsSuccess(taos, sql, expectedFields, 5);
1!
390
  }
391

392
  // case 7 : less param
393
  {
394
    const char*    sql = "insert into stmt2_testdb_2.stb(ts,tbname) values(?,?)";
1✔
395
    TAOS_FIELD_ALL expectedFields[2] = {{"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
1✔
396
                                        {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}};
397
    printf("case 7 : %s\n", sql);
1!
398
    getFieldsSuccess(taos, sql, expectedFields, 2);
1!
399
  }
400

401
  // case 8 : test all types
402
  {
403
    const char* sql =
1✔
404
        "insert into "
405
        "all_stb(tbname,tts,tv1,tv2,tv3,tv4,tv5,tv6,tv7,tv8,tv9,tv10,tv11,tv12,tv13,tv14,tv15,ts,v1,v2,v3,v4,v5,v6,v7,"
406
        "v8,v9,v10,"
407
        "v11,v12,v13,v14,v15) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
408
    TAOS_FIELD_ALL expectedFields[33] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
1✔
409
                                         {"tts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_TAG},
410
                                         {"tv1", TSDB_DATA_TYPE_BOOL, 0, 0, 1, TAOS_FIELD_TAG},
411
                                         {"tv2", TSDB_DATA_TYPE_TINYINT, 0, 0, 1, TAOS_FIELD_TAG},
412
                                         {"tv3", TSDB_DATA_TYPE_SMALLINT, 0, 0, 2, TAOS_FIELD_TAG},
413
                                         {"tv4", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
414
                                         {"tv5", TSDB_DATA_TYPE_BIGINT, 0, 0, 8, TAOS_FIELD_TAG},
415
                                         {"tv6", TSDB_DATA_TYPE_UTINYINT, 0, 0, 1, TAOS_FIELD_TAG},
416
                                         {"tv7", TSDB_DATA_TYPE_USMALLINT, 0, 0, 2, TAOS_FIELD_TAG},
417
                                         {"tv8", TSDB_DATA_TYPE_UINT, 0, 0, 4, TAOS_FIELD_TAG},
418
                                         {"tv9", TSDB_DATA_TYPE_UBIGINT, 0, 0, 8, TAOS_FIELD_TAG},
419
                                         {"tv10", TSDB_DATA_TYPE_FLOAT, 0, 0, 4, TAOS_FIELD_TAG},
420
                                         {"tv11", TSDB_DATA_TYPE_DOUBLE, 0, 0, 8, TAOS_FIELD_TAG},
421
                                         {"tv12", TSDB_DATA_TYPE_VARCHAR, 0, 0, 22, TAOS_FIELD_TAG},
422
                                         {"tv13", TSDB_DATA_TYPE_VARBINARY, 0, 0, 22, TAOS_FIELD_TAG},
423
                                         {"tv14", TSDB_DATA_TYPE_GEOMETRY, 0, 0, 102, TAOS_FIELD_TAG},
424
                                         {"tv15", TSDB_DATA_TYPE_NCHAR, 0, 0, 82, TAOS_FIELD_TAG},
425
                                         {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
426
                                         {"v1", TSDB_DATA_TYPE_BOOL, 0, 0, 1, TAOS_FIELD_COL},
427
                                         {"v2", TSDB_DATA_TYPE_TINYINT, 0, 0, 1, TAOS_FIELD_COL},
428
                                         {"v3", TSDB_DATA_TYPE_SMALLINT, 0, 0, 2, TAOS_FIELD_COL},
429
                                         {"v4", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_COL},
430
                                         {"v5", TSDB_DATA_TYPE_BIGINT, 0, 0, 8, TAOS_FIELD_COL},
431
                                         {"v6", TSDB_DATA_TYPE_UTINYINT, 0, 0, 1, TAOS_FIELD_COL},
432
                                         {"v7", TSDB_DATA_TYPE_USMALLINT, 0, 0, 2, TAOS_FIELD_COL},
433
                                         {"v8", TSDB_DATA_TYPE_UINT, 0, 0, 4, TAOS_FIELD_COL},
434
                                         {"v9", TSDB_DATA_TYPE_UBIGINT, 0, 0, 8, TAOS_FIELD_COL},
435
                                         {"v10", TSDB_DATA_TYPE_FLOAT, 0, 0, 4, TAOS_FIELD_COL},
436
                                         {"v11", TSDB_DATA_TYPE_DOUBLE, 0, 0, 8, TAOS_FIELD_COL},
437
                                         {"v12", TSDB_DATA_TYPE_VARCHAR, 0, 0, 22, TAOS_FIELD_COL},
438
                                         {"v13", TSDB_DATA_TYPE_VARBINARY, 0, 0, 22, TAOS_FIELD_COL},
439
                                         {"v14", TSDB_DATA_TYPE_GEOMETRY, 0, 0, 102, TAOS_FIELD_COL},
440
                                         {"v15", TSDB_DATA_TYPE_NCHAR, 0, 0, 82, TAOS_FIELD_COL}};
441
    printf("case 8 : %s\n", sql);
1!
442
    getFieldsSuccess(taos, sql, expectedFields, 33);
1!
443
  }
444

445
  // not support case
446
  printf("not support case \n");
1!
447

448
  // case 1 : add in main TD-33353
449
  {
450
    const char* sql = "insert into stmt2_testdb_2.stb(t1,t2,ts,b,tbname) values(1,?,?,'abc',?)";
1✔
451
    printf("case 1dif : %s\n", sql);
1!
452
    getFieldsError(taos, sql, TSDB_CODE_PAR_INVALID_COLUMNS_NUM);
1!
453
  }
454

455
  // case 2 : no pk
456
  {
457
    const char* sql = "insert into stmt2_testdb_2.stb(b,tbname) values(?,?)";
1✔
458
    printf("case 2 : %s\n", sql);
1!
459
    getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION);
1!
460
  }
461

462
  // case 3 : no tbname and tag(not support bind)
463
  {
464
    const char* sql = "insert into stmt2_testdb_2.stb(ts,b) values(?,?)";
1✔
465
    printf("case 3 : %s\n", sql);
1!
466
    getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION);
1!
467
  }
468

469
  // case 4 : no col and tag(not support bind)
470
  {
471
    const char* sql = "insert into stmt2_testdb_2.stb(tbname) values(?)";
1✔
472
    printf("case 4 : %s\n", sql);
1!
473
    getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION);
1!
474
  }
475

476
  // case 5 : no field name
477
  {
478
    const char* sql = "insert into stmt2_testdb_2.stb(?,?,?,?,?)";
1✔
479
    printf("case 5 : %s\n", sql);
1!
480
    getFieldsError(taos, sql, TSDB_CODE_PAR_SYNTAX_ERROR);
1!
481
  }
482

483
  // case 6 :  test super table not exist
484
  {
485
    const char* sql = "insert into stmt2_testdb_2.nstb(?,?,?,?,?)";
1✔
486
    printf("case 6 : %s\n", sql);
1!
487
    getFieldsError(taos, sql, TSDB_CODE_PAR_SYNTAX_ERROR);
1!
488
  }
489

490
  // case 7 :  no col
491
  {
492
    const char* sql = "insert into stmt2_testdb_2.stb(t1,t2,tbname) values(?,?,?)";
1✔
493
    printf("case 7 : %s\n", sql);
1!
494
    getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION);
1!
495
  }
496

497
  // case 8 :   wrong para nums
498
  {
499
    const char* sql = "insert into stmt2_testdb_2.stb(ts,b,tbname) values(?,?,?,?,?)";
1✔
500
    printf("case 8 : %s\n", sql);
1!
501
    getFieldsError(taos, sql, TSDB_CODE_PAR_INVALID_COLUMNS_NUM);
1!
502
  }
503

504
  // case 9 :   wrong simbol
505
  {
506
    const char* sql = "insert into stmt2_testdb_2.stb(t1,t2,ts,b,tbname) values(*,*,*,*,*)";
1✔
507
    printf("case 9 : %s\n", sql);
1!
508
    getFieldsError(taos, sql, TSDB_CODE_PAR_INVALID_COLUMNS_NUM);
1!
509
  }
510

511
  do_query(taos, "drop database if exists stmt2_testdb_2");
1!
512
  taos_close(taos);
1!
513
}
514

515
TEST(stmt2Case, insert_ctb_using_get_fields_Test) {
4✔
516
  TAOS* taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
1!
517
  ASSERT_NE(taos, nullptr);
1!
518

519
  do_query(taos, "drop database if exists stmt2_testdb_3");
1!
520
  do_query(taos, "create database IF NOT EXISTS stmt2_testdb_3 PRECISION 'ns'");
1!
521
  do_query(taos,
1!
522
           "create stable stmt2_testdb_3.stb (ts timestamp, b binary(10)) tags(t1 "
523
           "int, t2 binary(10))");
524
  do_query(
1!
525
      taos,
526
      "create stable if not exists stmt2_testdb_3.all_stb(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 "
527
      "bigint, "
528
      "v6 tinyint unsigned, v7 smallint unsigned, v8 int unsigned, v9 bigint unsigned, v10 float, v11 double, v12 "
529
      "binary(20), v13 varbinary(20), v14 geometry(100), v15 nchar(20))tags(tts timestamp, tv1 bool, tv2 tinyint, tv3 "
530
      "smallint, tv4 int, tv5 bigint, tv6 tinyint unsigned, tv7 smallint unsigned, tv8 int unsigned, tv9 bigint "
531
      "unsigned, tv10 float, tv11 double, tv12 binary(20), tv13 varbinary(20), tv14 geometry(100), tv15 nchar(20));");
532
  do_query(taos, "CREATE TABLE stmt2_testdb_3.t0 USING stmt2_testdb_3.stb (t1,t2) TAGS (7,'Cali');");
1!
533

534
  printf("support case \n");
1!
535
  // case 1 : test child table already exist
536
  {
537
    const char*    sql = "INSERT INTO stmt2_testdb_3.t0(ts,b)using stmt2_testdb_3.stb (t1,t2) TAGS(?,?) VALUES(?,?)";
1✔
538
    TAOS_FIELD_ALL expectedFields[4] = {{"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
1✔
539
                                        {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
540
                                        {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
541
                                        {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}};
542
    printf("case 1 : %s\n", sql);
1!
543
    getFieldsSuccess(taos, sql, expectedFields, 4);
1!
544
  }
545

546
  // case 2 : insert clause
547
  {
548
    const char*    sql = "INSERT INTO stmt2_testdb_3.? using stmt2_testdb_3.stb (t1,t2) TAGS(?,?) (ts,b)VALUES(?,?)";
1✔
549
    TAOS_FIELD_ALL expectedFields[5] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
1✔
550
                                        {"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
551
                                        {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
552
                                        {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
553
                                        {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}};
554
    printf("case 2 : %s\n", sql);
1!
555
    getFieldsSuccess(taos, sql, expectedFields, 5);
1!
556
  }
557

558
  // case 3 : insert child table not exist
559
  {
560
    const char*    sql = "INSERT INTO stmt2_testdb_3.d1 using stmt2_testdb_3.stb (t1,t2)TAGS(?,?) (ts,b)VALUES(?,?)";
1✔
561
    TAOS_FIELD_ALL expectedFields[4] = {{"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
1✔
562
                                        {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
563
                                        {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
564
                                        {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}};
565
    printf("case 3 : %s\n", sql);
1!
566
    getFieldsSuccess(taos, sql, expectedFields, 4);
1!
567
  }
568

569
  // case 4 : random order
570
  {
571
    const char*    sql = "INSERT INTO stmt2_testdb_3.? using stmt2_testdb_3.stb (t2,t1)TAGS(?,?) (b,ts)VALUES(?,?)";
1✔
572
    TAOS_FIELD_ALL expectedFields[5] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
1✔
573
                                        {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
574
                                        {"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
575
                                        {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL},
576
                                        {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}};
577
    printf("case 4 : %s\n", sql);
1!
578
    getFieldsSuccess(taos, sql, expectedFields, 5);
1!
579
  }
580

581
  // case 5 : less para
582
  {
583
    const char*    sql = "insert into stmt2_testdb_3.? using stmt2_testdb_3.stb (t2)tags(?) (ts)values(?)";
1✔
584
    TAOS_FIELD_ALL expectedFields[3] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
1✔
585
                                        {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
586
                                        {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}};
587
    printf("case 5 : %s\n", sql);
1!
588
    getFieldsSuccess(taos, sql, expectedFields, 3);
1!
589
  }
590

591
  // case 6 : insert into db.? using db.stb tags(?, ?) values(?,?)
592
  // no field name
593
  {
594
    const char*    sql = "insert into stmt2_testdb_3.? using stmt2_testdb_3.stb tags(?, ?) values(?,?)";
1✔
595
    TAOS_FIELD_ALL expectedFields[5] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
1✔
596
                                        {"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
597
                                        {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
598
                                        {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
599
                                        {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}};
600
    printf("case 6 : %s\n", sql);
1!
601
    getFieldsSuccess(taos, sql, expectedFields, 5);
1!
602
  }
603

604
  // case 7 : insert into db.d0 (ts)values(?)
605
  //  less para
606
  {
607
    const char*    sql = "insert into stmt2_testdb_3.t0 (ts)values(?)";
1✔
608
    TAOS_FIELD_ALL expectedFields[1] = {{"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}};
1✔
609
    printf("case 7 : %s\n", sql);
1!
610
    getFieldsSuccess(taos, sql, expectedFields, 1);
1!
611
  }
612

613
  // case 8 : 'db' 'stb'
614
  {
615
    const char* sql = "INSERT INTO 'stmt2_testdb_3'.? using 'stmt2_testdb_3'.'stb' (t1,t2) TAGS(?,?)(ts,b)VALUES(?,?)";
1✔
616
    TAOS_FIELD_ALL expectedFields[5] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
1✔
617
                                        {"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
618
                                        {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
619
                                        {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
620
                                        {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}};
621
    printf("case 8 : %s\n", sql);
1!
622
    getFieldsSuccess(taos, sql, expectedFields, 5);
1!
623
  }
624

625
  // case 9 : use db
626
  {
627
    do_query(taos, "use stmt2_testdb_3");
1!
628
    const char*    sql = "INSERT INTO ? using stb (t1,t2) TAGS(?,?) (ts,b)VALUES(?,?)";
1✔
629
    TAOS_FIELD_ALL expectedFields[5] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
1✔
630
                                        {"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
631
                                        {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG},
632
                                        {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
633
                                        {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}};
634
    printf("case 9 : %s\n", sql);
1!
635
    getFieldsSuccess(taos, sql, expectedFields, 5);
1!
636
  }
637
  // case 11: TD-34097
638
  {
639
    do_query(taos, "use stmt2_testdb_3");
1!
640
    const char*    sql = "INSERT INTO ? using stb (t1,t2) TAGS(1,'abc') (ts,b)VALUES(?,?)";
1✔
641
    TAOS_FIELD_ALL expectedFields[3] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
1✔
642
                                        {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
643
                                        {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}};
644
    printf("case 11 : %s\n", sql);
1!
645
    getFieldsSuccess(taos, sql, expectedFields, 3);
1!
646
  }
647

648
  // case 10 : test all types
649
  {
650
    do_query(taos, "use stmt2_testdb_3");
1!
651
    const char* sql =
1✔
652
        "insert into ? using all_stb tags(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
653
    TAOS_FIELD_ALL expectedFields[33] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME},
1✔
654
                                         {"tts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_TAG},
655
                                         {"tv1", TSDB_DATA_TYPE_BOOL, 0, 0, 1, TAOS_FIELD_TAG},
656
                                         {"tv2", TSDB_DATA_TYPE_TINYINT, 0, 0, 1, TAOS_FIELD_TAG},
657
                                         {"tv3", TSDB_DATA_TYPE_SMALLINT, 0, 0, 2, TAOS_FIELD_TAG},
658
                                         {"tv4", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG},
659
                                         {"tv5", TSDB_DATA_TYPE_BIGINT, 0, 0, 8, TAOS_FIELD_TAG},
660
                                         {"tv6", TSDB_DATA_TYPE_UTINYINT, 0, 0, 1, TAOS_FIELD_TAG},
661
                                         {"tv7", TSDB_DATA_TYPE_USMALLINT, 0, 0, 2, TAOS_FIELD_TAG},
662
                                         {"tv8", TSDB_DATA_TYPE_UINT, 0, 0, 4, TAOS_FIELD_TAG},
663
                                         {"tv9", TSDB_DATA_TYPE_UBIGINT, 0, 0, 8, TAOS_FIELD_TAG},
664
                                         {"tv10", TSDB_DATA_TYPE_FLOAT, 0, 0, 4, TAOS_FIELD_TAG},
665
                                         {"tv11", TSDB_DATA_TYPE_DOUBLE, 0, 0, 8, TAOS_FIELD_TAG},
666
                                         {"tv12", TSDB_DATA_TYPE_VARCHAR, 0, 0, 22, TAOS_FIELD_TAG},
667
                                         {"tv13", TSDB_DATA_TYPE_VARBINARY, 0, 0, 22, TAOS_FIELD_TAG},
668
                                         {"tv14", TSDB_DATA_TYPE_GEOMETRY, 0, 0, 102, TAOS_FIELD_TAG},
669
                                         {"tv15", TSDB_DATA_TYPE_NCHAR, 0, 0, 82, TAOS_FIELD_TAG},
670
                                         {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL},
671
                                         {"v1", TSDB_DATA_TYPE_BOOL, 0, 0, 1, TAOS_FIELD_COL},
672
                                         {"v2", TSDB_DATA_TYPE_TINYINT, 0, 0, 1, TAOS_FIELD_COL},
673
                                         {"v3", TSDB_DATA_TYPE_SMALLINT, 0, 0, 2, TAOS_FIELD_COL},
674
                                         {"v4", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_COL},
675
                                         {"v5", TSDB_DATA_TYPE_BIGINT, 0, 0, 8, TAOS_FIELD_COL},
676
                                         {"v6", TSDB_DATA_TYPE_UTINYINT, 0, 0, 1, TAOS_FIELD_COL},
677
                                         {"v7", TSDB_DATA_TYPE_USMALLINT, 0, 0, 2, TAOS_FIELD_COL},
678
                                         {"v8", TSDB_DATA_TYPE_UINT, 0, 0, 4, TAOS_FIELD_COL},
679
                                         {"v9", TSDB_DATA_TYPE_UBIGINT, 0, 0, 8, TAOS_FIELD_COL},
680
                                         {"v10", TSDB_DATA_TYPE_FLOAT, 0, 0, 4, TAOS_FIELD_COL},
681
                                         {"v11", TSDB_DATA_TYPE_DOUBLE, 0, 0, 8, TAOS_FIELD_COL},
682
                                         {"v12", TSDB_DATA_TYPE_VARCHAR, 0, 0, 22, TAOS_FIELD_COL},
683
                                         {"v13", TSDB_DATA_TYPE_VARBINARY, 0, 0, 22, TAOS_FIELD_COL},
684
                                         {"v14", TSDB_DATA_TYPE_GEOMETRY, 0, 0, 102, TAOS_FIELD_COL},
685
                                         {"v15", TSDB_DATA_TYPE_NCHAR, 0, 0, 82, TAOS_FIELD_COL}};
686
    printf("case 10 : %s\n", sql);
1!
687
    getFieldsSuccess(taos, sql, expectedFields, 33);
1!
688
  }
689
  printf("not support case \n");
1!
690

691
  // case 1 : test super table not exist
692
  {
693
    const char* sql = "INSERT INTO stmt2_testdb_3.?(ts,b)using stmt2_testdb_3.nstb (t1,t2) TAGS(?,?) VALUES (?,?)";
1✔
694
    printf("case 1 : %s\n", sql);
1!
695
    getFieldsError(taos, sql, TSDB_CODE_PAR_SYNTAX_ERROR);
1!
696
  }
697

698
  // case 2 : no pk
699
  {
700
    const char* sql = "INSERT INTO stmt2_testdb_3.?(ts,b)using stmt2_testdb_3.nstb (t1,t2) TAGS(?,?) (n)VALUES (?)";
1✔
701
    printf("case 2 : %s\n", sql);
1!
702
    getFieldsError(taos, sql, TSDB_CODE_PAR_SYNTAX_ERROR);
1!
703
  }
704

705
  // case 3 : less param and no filed name
706
  {
707
    const char* sql = "INSERT INTO stmt2_testdb_3.?(ts,b)using stmt2_testdb_3.stb TAGS(?)VALUES (?,?)";
1✔
708
    printf("case 3 : %s\n", sql);
1!
709
    getFieldsError(taos, sql, TSDB_CODE_PAR_SYNTAX_ERROR);
1!
710
  }
711

712
  // case 4 :  none para for ctbname
713
  {
714
    const char* sql = "INSERT INTO stmt2_testdb_3.d0 using stmt2_testdb_3.stb values(?,?)";
1✔
715
    printf("case 4 : %s\n", sql);
1!
716
    getFieldsError(taos, sql, TSDB_CODE_TSC_SQL_SYNTAX_ERROR);
1!
717
  }
718

719
  // case 5 :  none para for ctbname
720
  {
721
    const char* sql = "insert into ! using stmt2_testdb_3.stb tags(?, ?) values(?,?)";
1✔
722
    printf("case 5 : %s\n", sql);
1!
723
    getFieldsError(taos, sql, TSDB_CODE_TSC_SQL_SYNTAX_ERROR);
1!
724
  }
725
  // case 6 : mix value and ?
726
  {
727
    do_query(taos, "use stmt2_testdb_3");
1!
728
    const char* sql = "INSERT INTO ? using stb (t1,t2) TAGS(1,?) (ts,b)VALUES(?,?)";
1✔
729
    printf("case 6 : %s\n", sql);
1!
730
    getFieldsError(taos, sql, TSDB_CODE_TSC_SQL_SYNTAX_ERROR);
1!
731
  }
732
  // case 7 : mix value and ?
733
  {
734
    do_query(taos, "use stmt2_testdb_3");
1!
735
    const char*    sql = "INSERT INTO ? using stb (t1,t2) TAGS(?,?) (ts,b)VALUES(15910606280001,?)";
1✔
736
    printf("case 7 : %s\n", sql);
1!
737
    getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION);
1!
738
  }
739
  // case 8 : mix value and ?
740
  {
741
    do_query(taos, "use stmt2_testdb_3");
1!
742
    const char* sql = "INSERT INTO ? using stb (t1,t2) TAGS(?,?) (ts,b)VALUES(15910606280001,'abc')";
1✔
743
    printf("case 8 : %s\n", sql);
1!
744
    getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION);
1!
745
  }
746
  do_query(taos, "drop database if exists stmt2_testdb_3");
1!
747
  taos_close(taos);
1!
748
}
749

750
TEST(stmt2Case, insert_ntb_get_fields_Test) {
4✔
751
  TAOS* taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
1!
752
  ASSERT_NE(taos, nullptr);
1!
753

754
  do_query(taos, "drop database if exists stmt2_testdb_4");
1!
755
  do_query(taos, "create database IF NOT EXISTS stmt2_testdb_4 PRECISION 'ms'");
1!
756
  do_query(taos, "CREATE TABLE stmt2_testdb_4.ntb(nts timestamp, nb binary(10),nvc varchar(16),ni int);");
1!
757
  do_query(
1!
758
      taos,
759
      "create table if not exists stmt2_testdb_4.all_ntb(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 "
760
      "bigint, v6 tinyint unsigned, v7 smallint unsigned, v8 int unsigned, v9 bigint unsigned, v10 float, v11 "
761
      "double, v12 binary(20), v13 varbinary(20), v14 geometry(100), v15 nchar(20));");
762

763
  printf("support case \n");
1!
764

765
  // case 1 : test normal table no field name
766
  {
767
    const char*    sql = "INSERT INTO stmt2_testdb_4.ntb VALUES(?,?,?,?)";
1✔
768
    TAOS_FIELD_ALL expectedFields[4] = {{"nts", TSDB_DATA_TYPE_TIMESTAMP, 0, 0, 8, TAOS_FIELD_COL},
1✔
769
                                        {"nb", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL},
770
                                        {"nvc", TSDB_DATA_TYPE_BINARY, 0, 0, 18, TAOS_FIELD_COL},
771
                                        {"ni", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_COL}};
772
    printf("case 1 : %s\n", sql);
1!
773
    getFieldsSuccess(taos, sql, expectedFields, 4);
1!
774
  }
775

776
  // case 2 : test random order
777
  {
778
    const char*    sql = "INSERT INTO stmt2_testdb_4.ntb (ni,nb,nvc,nts)VALUES(?,?,?,?)";
1✔
779
    TAOS_FIELD_ALL expectedFields[4] = {{"ni", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_COL},
1✔
780
                                        {"nb", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL},
781
                                        {"nvc", TSDB_DATA_TYPE_BINARY, 0, 0, 18, TAOS_FIELD_COL},
782
                                        {"nts", TSDB_DATA_TYPE_TIMESTAMP, 0, 0, 8, TAOS_FIELD_COL}};
783
    printf("case 2 : %s\n", sql);
1!
784
    getFieldsSuccess(taos, sql, expectedFields, 4);
1!
785
  }
786

787
  // case 3 : less param
788
  {
789
    const char*    sql = "INSERT INTO stmt2_testdb_4.ntb (nts)VALUES(?)";
1✔
790
    TAOS_FIELD_ALL expectedFields[1] = {{"nts", TSDB_DATA_TYPE_TIMESTAMP, 0, 0, 8, TAOS_FIELD_COL}};
1✔
791
    printf("case 3 : %s\n", sql);
1!
792
    getFieldsSuccess(taos, sql, expectedFields, 1);
1!
793
  }
794

795
  // case 4 : test all types
796
  {
797
    const char*    sql = "insert into stmt2_testdb_4.all_ntb values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
1✔
798
    TAOS_FIELD_ALL expectedFields[16] = {{"ts", TSDB_DATA_TYPE_TIMESTAMP, 0, 0, 8, TAOS_FIELD_COL},
1✔
799
                                         {"v1", TSDB_DATA_TYPE_BOOL, 0, 0, 1, TAOS_FIELD_COL},
800
                                         {"v2", TSDB_DATA_TYPE_TINYINT, 0, 0, 1, TAOS_FIELD_COL},
801
                                         {"v3", TSDB_DATA_TYPE_SMALLINT, 0, 0, 2, TAOS_FIELD_COL},
802
                                         {"v4", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_COL},
803
                                         {"v5", TSDB_DATA_TYPE_BIGINT, 0, 0, 8, TAOS_FIELD_COL},
804
                                         {"v6", TSDB_DATA_TYPE_UTINYINT, 0, 0, 1, TAOS_FIELD_COL},
805
                                         {"v7", TSDB_DATA_TYPE_USMALLINT, 0, 0, 2, TAOS_FIELD_COL},
806
                                         {"v8", TSDB_DATA_TYPE_UINT, 0, 0, 4, TAOS_FIELD_COL},
807
                                         {"v9", TSDB_DATA_TYPE_UBIGINT, 0, 0, 8, TAOS_FIELD_COL},
808
                                         {"v10", TSDB_DATA_TYPE_FLOAT, 0, 0, 4, TAOS_FIELD_COL},
809
                                         {"v11", TSDB_DATA_TYPE_DOUBLE, 0, 0, 8, TAOS_FIELD_COL},
810
                                         {"v12", TSDB_DATA_TYPE_VARCHAR, 0, 0, 22, TAOS_FIELD_COL},
811
                                         {"v13", TSDB_DATA_TYPE_VARBINARY, 0, 0, 22, TAOS_FIELD_COL},
812
                                         {"v14", TSDB_DATA_TYPE_GEOMETRY, 0, 0, 102, TAOS_FIELD_COL},
813
                                         {"v15", TSDB_DATA_TYPE_NCHAR, 0, 0, 82, TAOS_FIELD_COL}};
814
    printf("case 4 : %s\n", sql);
1!
815
    getFieldsSuccess(taos, sql, expectedFields, 16);
1!
816
  }
817

818
  printf("not support case \n");
1!
819

820
  // case 1 :  wrong db
821
  {
822
    const char* sql = "insert into ntb values(?,?,?,?)";
1✔
823
    printf("case 1 : %s\n", sql);
1!
824
    getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION);
1!
825
  }
826

827
  // case 2 :  normal table must have tbnam
828
  {
829
    const char* sql = "insert into stmt2_testdb_4.? values(?,?)";
1✔
830
    printf("case 2 : %s\n", sql);
1!
831
    getFieldsError(taos, sql, TSDB_CODE_TSC_STMT_TBNAME_ERROR);
1!
832
  }
833

834
  // case 3 :  wrong para nums
835
  {
836
    const char* sql = "insert into stmt2_testdb_4.ntb(nts,ni) values(?,?,?,?,?)";
1✔
837
    printf("case 3 : %s\n", sql);
1!
838
    getFieldsError(taos, sql, TSDB_CODE_PAR_INVALID_COLUMNS_NUM);
1!
839
  }
840

841
  do_query(taos, "drop database if exists stmt2_testdb_4");
1!
842
  taos_close(taos);
1!
843
}
844

845
TEST(stmt2Case, select_get_fields_Test) {
4✔
846
  TAOS* taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
1!
847
  ASSERT_NE(taos, nullptr);
1!
848
  do_query(taos, "drop database if exists stmt2_testdb_5");
1!
849
  do_query(taos, "create database IF NOT EXISTS stmt2_testdb_5 PRECISION 'ns'");
1!
850
  do_query(taos, "use stmt2_testdb_5");
1!
851
  do_query(taos, "CREATE TABLE stmt2_testdb_5.ntb(nts timestamp, nb binary(10),nvc varchar(16),ni int);");
1!
852
  {
853
    // case 1 :
854
    const char* sql = "select * from ntb where ts = ?";
1✔
855
    printf("case 1 : %s\n", sql);
1!
856
    getQueryFields(taos, sql, 1);
1!
857
  }
858

859
  {
860
    // case 2 :
861
    const char* sql = "select * from ntb where ts = ? and b = ?";
1✔
862
    printf("case 2 : %s\n", sql);
1!
863
    getQueryFields(taos, sql, 2);
1!
864
  }
865

866
  {
867
    // case 3 :
868
    const char* sql = "select * from ? where ts = ?";
1✔
869
    printf("case 3 : %s\n", sql);
1!
870
    getFieldsError(taos, sql, TSDB_CODE_PAR_SYNTAX_ERROR);
1!
871
  }
872

873
  do_query(taos, "drop database if exists stmt2_testdb_5");
1!
874
  taos_close(taos);
1!
875
}
876

877
TEST(stmt2Case, get_fields_error_Test) {
4✔
878
  // case 1 :
879
  {
880
    printf("case 1 : NULL param \n");
1!
881
    int code = taos_stmt2_get_fields(NULL, NULL, NULL);
1!
882
    ASSERT_EQ(code, TSDB_CODE_INVALID_PARA);
1!
883
  }
884
}
885

886
TEST(stmt2Case, stmt2_init_prepare_Test) {
4✔
887
  TAOS* taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
1!
888
  ASSERT_NE(taos, nullptr);
1!
889
  {
890
    (void)taos_stmt2_init(NULL, NULL);
1!
891
    ASSERT_EQ(terrno, TSDB_CODE_INVALID_PARA);
1!
892
    terrno = 0;
1!
893
  }
894

895
  {
896
    (void)taos_stmt2_prepare(NULL, NULL, 0);
1!
897
    ASSERT_EQ(terrno, TSDB_CODE_INVALID_PARA);
1!
898
    terrno = 0;
1!
899
  }
900

901
  {
902
    TAOS_STMT2_OPTION option = {0, true, true, NULL, NULL};
1✔
903
    TAOS_STMT2*       stmt = taos_stmt2_init(taos, &option);
1!
904
    ASSERT_EQ(terrno, 0);
1!
905
    ASSERT_NE(stmt, nullptr);
1!
906
    int code = taos_stmt2_prepare(stmt, "wrong sql", 0);
1!
907
    ASSERT_NE(stmt, nullptr);
1!
908
    ASSERT_EQ(((STscStmt2*)stmt)->db, nullptr);
1!
909

910
    code = taos_stmt2_prepare(stmt, "insert into 'stmt2_testdb_5'.stb(t1,t2,ts,b,tbname) values(?,?,?,?,?)", 0);
1!
911
    ASSERT_NE(stmt, nullptr);
1!
912
    ASSERT_STREQ(((STscStmt2*)stmt)->db, "stmt2_testdb_5");  // add in main TD-33332
1!
913
    taos_stmt2_close(stmt);
1!
914
  }
915

916
  {
917
    TAOS_STMT2_OPTION option = {0, true, false, NULL, NULL};
1✔
918
    TAOS_STMT2*       stmt = taos_stmt2_init(taos, &option);
1!
919
    ASSERT_NE(stmt, nullptr);
1!
920
    taos_stmt2_close(stmt);
1!
921
  }
922

923
  {
924
    TAOS_STMT2_OPTION option = {0, true, true, stmtAsyncQueryCb, NULL};
1✔
925
    TAOS_STMT2*       stmt = taos_stmt2_init(taos, &option);
1!
926
    ASSERT_NE(stmt, nullptr);
1!
927
    taos_stmt2_close(stmt);
1!
928
  }
929
  taos_close(taos);
1!
930
}
931

932
TEST(stmt2Case, stmt2_stb_insert) {
4✔
933
  TAOS* taos = taos_connect("localhost", "root", "taosdata", "", 0);
1!
934
  ASSERT_NE(taos, nullptr);
1!
935
  // normal
936
  TAOS_STMT2_OPTION option = {0, false, true, NULL, NULL};
1✔
937
  {
938
    do_stmt("no-interlcace", taos, &option, "insert into `stmt2_testdb_1`.`stb` (tbname,ts,b,t1,t2) values(?,?,?,?,?)",
1!
939
            3, 3, 3, true, true);
940
  }
941
  {
942
    do_stmt("no-interlcace", taos, &option,
1!
943
            "insert into `stmt2_testdb_1`.? using `stmt2_testdb_1`.`stb` tags(?,?) values(?,?)", 3, 3, 3, true, true);
944
  }
945

946
  // async
947
  AsyncArgs* aa = (AsyncArgs*)taosMemMalloc(sizeof(AsyncArgs));
1!
948
  aa->async_affected_rows = 0;
1✔
949
  ASSERT_EQ(tsem_init(&aa->sem, 0, 0), TSDB_CODE_SUCCESS);
1!
950
  void* param = aa;
1✔
951
  option = {0, false, true, stmtAsyncQueryCb, param};
1✔
952
  {
953
    do_stmt("no-interlcace & aync exec", taos, &option,
1!
954
            "insert into stmt2_testdb_1.stb (ts,b,tbname,t1,t2) values(?,?,?,?,?)", 3, 3, 3, true, true);
955
  }
956
  {
957
    do_stmt("no-interlcace & aync exec", taos, &option,
1!
958
            "insert into stmt2_testdb_1.? using stmt2_testdb_1.stb (t1,t2)tags(?,?) (ts,b)values(?,?)", 3, 3, 3, true,
959
            true);
960
  }
961
  // TD-34123 : interlace=0 with fixed tags
962
  {
963
    do_stmt("no-interlcace", taos, &option, "insert into `stmt2_testdb_1`.`stb` (tbname,ts,b,t1,t2) values(?,?,?,?,?)",
1!
964
            3, 3, 3, false, true);
965
  }
966

967
  // interlace = 0 & use db]
968
  do_query(taos, "use stmt2_testdb_1");
1!
969
  option = {0, false, false, NULL, NULL};
1✔
970
  {
971
    do_stmt("no-interlcace & no-db", taos, &option, "insert into stb (tbname,ts,b) values(?,?,?)", 3, 3, 3, false,
1!
972
            true);
973
  }
974
  {
975
    do_stmt("no-interlcace & no-db", taos, &option, "insert into ? using stb (t1,t2)tags(?,?) (ts,b)values(?,?)", 3, 3,
1!
976
            3, true, true);
977
  }
978
  { do_stmt("no-interlcace & no-db", taos, &option, "insert into ? values(?,?)", 3, 3, 3, false, true); }
1!
979

980
  // interlace = 1
981
  option = {0, true, true, stmtAsyncQueryCb, param};
1✔
982
  { do_stmt("interlcace & preCreateTB", taos, &option, "insert into ? values(?,?)", 3, 3, 3, false, true); }
1!
983
  option = {0, true, true, NULL, NULL};
1✔
984
  { do_stmt("interlcace & preCreateTB", taos, &option, "insert into ? values(?,?)", 3, 3, 3, false, true); }
1!
985

986
  //  auto create table
987
  // interlace = 1
988
  option = {0, true, true, NULL, NULL};
1✔
989
  {
990
    do_stmt("interlcace & no-preCreateTB", taos, &option, "insert into ? using stb (t1,t2)tags(?,?) (ts,b)values(?,?)",
1!
991
            3, 3, 3, true, false);
992
  }
993
  {
994
    do_stmt("interlcace & no-preCreateTB", taos, &option,
1!
995
            "insert into stmt2_testdb_1.? using stb (t1,t2)tags(1,'abc') (ts,b)values(?,?)", 3, 3, 3, false, false);
996
  }
997
  {
998
    do_stmt("interlcace & no-preCreateTB", taos, &option,
1!
999
            "insert into stmt2_testdb_1.stb (ts,b,tbname,t1,t2) values(?,?,?,?,?)", 3, 3, 3, true, false);
1000
  }
1001
  // interlace = 0
1002
  option = {0, false, false, NULL, NULL};
1✔
1003
  {
1004
    do_stmt("no-interlcace & no-preCreateTB", taos, &option,
1!
1005
            "insert into ? using stb (t1,t2)tags(?,?) (ts,b)values(?,?)", 3, 3, 3, true, false);
1006
  }
1007
  {
1008
    do_stmt("no-interlcace & no-preCreateTB", taos, &option,
1!
1009
            "insert into stmt2_testdb_1.stb (ts,b,tbname,t1,t2) values(?,?,?,?,?)", 3, 3, 3, true, false);
1010
  }
1011

1012
  do_query(taos, "drop database if exists stmt2_testdb_1");
1!
1013
  (void)tsem_destroy(&aa->sem);
1!
1014
  taosMemFree(aa);
1!
1015
  taos_close(taos);
1!
1016
}
1017

1018
// TD-33417
1019
TEST(stmt2Case, stmt2_insert_non_statndard) {
4✔
1020
  TAOS* taos = taos_connect("localhost", "root", "taosdata", "", 0);
1!
1021
  ASSERT_NE(taos, nullptr);
1!
1022
  do_query(taos, "drop database if exists stmt2_testdb_6");
1!
1023
  do_query(taos, "create database IF NOT EXISTS stmt2_testdb_6");
1!
1024
  do_query(taos,
1!
1025
           "create stable stmt2_testdb_6.stb1  (ts timestamp, int_col int,long_col bigint,double_col "
1026
           "double,bool_col bool,binary_col binary(20),nchar_col nchar(20),varbinary_col varbinary(20),geometry_col "
1027
           "geometry(200)) tags(int_tag int,long_tag bigint,double_tag double,bool_tag bool,binary_tag "
1028
           "binary(20),nchar_tag nchar(20),varbinary_tag varbinary(20),geometry_tag geometry(200));");
1029
  do_query(taos, "use stmt2_testdb_6");
1!
1030

1031
  TAOS_STMT2_OPTION option = {0, true, true, NULL, NULL};
1✔
1032

1033
  // less cols and tags using stb
1034
  {
1035
    TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
1!
1036
    ASSERT_NE(stmt, nullptr);
1!
1037
    const char* sql = "INSERT INTO stmt2_testdb_6.? using stmt2_testdb_6.stb1 (int_tag)tags(1) (ts)  VALUES (?)";
1✔
1038
    printf("stmt2 [%s] : %s\n", "less params", sql);
1!
1039
    int code = taos_stmt2_prepare(stmt, sql, 0);
1!
1040
    checkError(stmt, code);
1!
1041
    // test get fields
1042
    int             fieldNum = 0;
1✔
1043
    TAOS_FIELD_ALL* pFields = NULL;
1✔
1044
    code = taos_stmt2_get_fields(stmt, &fieldNum, &pFields);
1!
1045
    checkError(stmt, code);
1!
1046
    ASSERT_EQ(fieldNum, 2);
1!
1047
    ASSERT_STREQ(pFields[0].name, "tbname");
1!
1048
    ASSERT_STREQ(pFields[1].name, "ts");
1!
1049

1050
    int total_affect_rows = 0;
1✔
1051

1052
    int     t64_len[2] = {sizeof(int64_t), sizeof(int64_t)};
1✔
1053
    int     tag_i = 0;
1✔
1054
    int     tag_l = sizeof(int);
1✔
1055
    int64_t ts[2] = {1591060628000, 1591060628100};
1✔
1056
    for (int i = 0; i < 3; i++) {
4✔
1057
      ts[0] += 1000;
3✔
1058
      ts[1] += 1000;
3✔
1059

1060
      TAOS_STMT2_BIND tags1 = {TSDB_DATA_TYPE_INT, &tag_i, &tag_l, NULL, 1};
3✔
1061
      TAOS_STMT2_BIND tags2 = {TSDB_DATA_TYPE_INT, &tag_i, &tag_l, NULL, 1};
3✔
1062
      TAOS_STMT2_BIND params1 = {TSDB_DATA_TYPE_TIMESTAMP, &ts, &t64_len[0], NULL, 2};
3✔
1063
      TAOS_STMT2_BIND params2 = {TSDB_DATA_TYPE_TIMESTAMP, &ts, &t64_len[0], NULL, 2};
3✔
1064

1065
      TAOS_STMT2_BIND* tagv[2] = {&tags1, &tags2};
3✔
1066
      TAOS_STMT2_BIND* paramv[2] = {&params1, &params2};
3✔
1067
      char*            tbname[2] = {"tb1", "tb2"};
3✔
1068
      TAOS_STMT2_BINDV bindv = {2, &tbname[0], tagv, &paramv[0]};
3✔
1069
      code = taos_stmt2_bind_param(stmt, &bindv, -1);
3!
1070
      checkError(stmt, code);
3!
1071

1072
      code = taos_stmt2_get_fields(stmt, &fieldNum, &pFields);
3!
1073
      checkError(stmt, code);
3!
1074
      ASSERT_EQ(fieldNum, 2);
3!
1075
      ASSERT_STREQ(pFields[0].name, "tbname");
3!
1076
      ASSERT_STREQ(pFields[1].name, "ts");
3!
1077

1078
      int affected_rows;
1079
      taos_stmt2_exec(stmt, &affected_rows);
3!
1080
      total_affect_rows += affected_rows;
3✔
1081
      checkError(stmt, code);
3!
1082

1083
      code = taos_stmt2_get_fields(stmt, &fieldNum, &pFields);
3!
1084
      checkError(stmt, code);
3!
1085
      ASSERT_EQ(fieldNum, 2);
3!
1086
      ASSERT_STREQ(pFields[0].name, "tbname");
3!
1087
      ASSERT_STREQ(pFields[1].name, "ts");
3!
1088
    }
1089

1090
    ASSERT_EQ(total_affect_rows, 12);
1!
1091
    taos_stmt2_close(stmt);
1!
1092
  }
1093

1094
  // less cols and tags
1095
  {
1096
    TAOS_STMT2*       stmt = taos_stmt2_init(taos, &option);
1!
1097
    TAOS_STMT2_OPTION option = {0, false, false, NULL, NULL};
1✔
1098
    ASSERT_NE(stmt, nullptr);
1!
1099
    const char* sql = "INSERT INTO stmt2_testdb_6.stb1 (ts,int_tag,tbname)  VALUES (?,?,?)";
1✔
1100
    printf("stmt2 [%s] : %s\n", "less params", sql);
1!
1101
    int code = taos_stmt2_prepare(stmt, sql, 0);
1!
1102
    checkError(stmt, code);
1!
1103
    int total_affect_rows = 0;
1✔
1104

1105
    int     t64_len[2] = {sizeof(int64_t), sizeof(int64_t)};
1✔
1106
    int     tag_i = 0;
1✔
1107
    int     tag_l = sizeof(int);
1✔
1108
    int64_t ts[2] = {1591060628000, 1591060628100};
1✔
1109
    for (int i = 0; i < 3; i++) {
4✔
1110
      ts[0] += 1000;
3✔
1111
      ts[1] += 1000;
3✔
1112

1113
      TAOS_STMT2_BIND tags1 = {TSDB_DATA_TYPE_INT, &tag_i, &tag_l, NULL, 1};
3✔
1114
      TAOS_STMT2_BIND tags2 = {TSDB_DATA_TYPE_INT, &tag_i, &tag_l, NULL, 1};
3✔
1115
      TAOS_STMT2_BIND params1 = {TSDB_DATA_TYPE_TIMESTAMP, &ts, &t64_len[0], NULL, 2};
3✔
1116
      TAOS_STMT2_BIND params2 = {TSDB_DATA_TYPE_TIMESTAMP, &ts, &t64_len[0], NULL, 2};
3✔
1117

1118
      TAOS_STMT2_BIND* tagv[2] = {&tags1, &tags2};
3✔
1119
      TAOS_STMT2_BIND* paramv[2] = {&params1, &params2};
3✔
1120
      char*            tbname[2] = {"tb1", "tb2"};
3✔
1121
      TAOS_STMT2_BINDV bindv = {2, &tbname[0], &tagv[0], &paramv[0]};
3✔
1122
      code = taos_stmt2_bind_param(stmt, &bindv, -1);
3!
1123
      checkError(stmt, code);
3!
1124

1125
      int affected_rows;
1126
      taos_stmt2_exec(stmt, &affected_rows);
3!
1127
      total_affect_rows += affected_rows;
3✔
1128

1129
      checkError(stmt, code);
3!
1130
    }
1131

1132
    ASSERT_EQ(total_affect_rows, 12);
1!
1133
    taos_stmt2_close(stmt);
1!
1134
  }
1135

1136
  // disorder cols and tags
1137
  {
1138
    TAOS_STMT2_OPTION option = {0, false, false, NULL, NULL};
1✔
1139
    TAOS_STMT2*       stmt = taos_stmt2_init(taos, &option);
1!
1140
    ASSERT_NE(stmt, nullptr);
1!
1141
    do_query(taos,
1!
1142
             "INSERT INTO stmt2_testdb_6.stb1 (ts, int_tag, tbname)  VALUES (1591060627000, 5, 'tb5')(1591060627000, "
1143
             "6,'tb6')");
1144
    const char* sql = "INSERT INTO stmt2_testdb_6.stb1 (binary_tag,int_col,tbname,ts,int_tag)  VALUES (?,?,?,?,?)";
1✔
1145
    printf("stmt2 [%s] : %s\n", "disorder params", sql);
1!
1146
    int code = taos_stmt2_prepare(stmt, sql, 0);
1!
1147
    checkError(stmt, code);
1!
1148

1149
    int     tag_i = 0;
1✔
1150
    int     tag_l = sizeof(int);
1✔
1151
    int     tag_bl = 3;
1✔
1152
    int64_t ts[2] = {1591060628000, 1591060628100};
1✔
1153
    int64_t ts_2[2] = {1591060628800, 1591060628900};
1✔
1154
    int     t64_len[2] = {sizeof(int64_t), sizeof(int64_t)};
1✔
1155
    int     coli[2] = {1, 2};
1✔
1156
    int     coli_2[2] = {3, 4};
1✔
1157
    int     ilen[2] = {sizeof(int), sizeof(int)};
1✔
1158
    int     total_affect_rows = 0;
1✔
1159
    for (int i = 0; i < 3; i++) {
4✔
1160
      ts[0] += 1000;
3✔
1161
      ts[1] += 1000;
3✔
1162
      ts_2[0] += 1000;
3✔
1163
      ts_2[1] += 1000;
3✔
1164

1165
      TAOS_STMT2_BIND tags[2][2] = {
3✔
1166
          {{TSDB_DATA_TYPE_BINARY, (void*)"abc", &tag_bl, NULL, 1}, {TSDB_DATA_TYPE_INT, &tag_i, &tag_l, NULL, 1}},
1167
          {{TSDB_DATA_TYPE_BINARY, (void*)"def", &tag_bl, NULL, 1}, {TSDB_DATA_TYPE_INT, &tag_i, &tag_l, NULL, 1}}};
3✔
1168
      TAOS_STMT2_BIND params[2][2] = {
3✔
1169
          {{TSDB_DATA_TYPE_INT, &coli[0], &ilen[0], NULL, 2}, {TSDB_DATA_TYPE_TIMESTAMP, &ts[0], &t64_len[0], NULL, 2}},
1170
          {{TSDB_DATA_TYPE_INT, &coli_2[0], &ilen[0], NULL, 2},
1171
           {TSDB_DATA_TYPE_TIMESTAMP, &ts_2[0], &t64_len[0], NULL, 2}}};
3✔
1172

1173
      TAOS_STMT2_BIND* tagv[2] = {&tags[0][0], &tags[1][0]};
3✔
1174
      TAOS_STMT2_BIND* paramv[2] = {&params[0][0], &params[1][0]};
3✔
1175
      char*            tbname[2] = {"tb5", "tb6"};
3✔
1176
      TAOS_STMT2_BINDV bindv = {2, &tbname[0], &tagv[0], &paramv[0]};
3✔
1177
      code = taos_stmt2_bind_param(stmt, &bindv, -1);
3!
1178
      checkError(stmt, code);
3!
1179

1180
      int affected_rows;
1181
      taos_stmt2_exec(stmt, &affected_rows);
3!
1182
      total_affect_rows += affected_rows;
3✔
1183
      checkError(stmt, code);
3!
1184
    }
1185
    ASSERT_EQ(total_affect_rows, 12);
1!
1186
    taos_stmt2_close(stmt);
1!
1187
  }
1188

1189
  // pk error
1190
  {
1191
    TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
1!
1192
    ASSERT_NE(stmt, nullptr);
1!
1193
    const char* sql =
1✔
1194
        "INSERT INTO stmt2_testdb_6.? using  stmt2_testdb_6.stb1 (int_tag)tags(1) (int_col,ts)VALUES (?,?)";
1195
    printf("stmt2 [%s] : %s\n", "PK error", sql);
1!
1196
    int code = taos_stmt2_prepare(stmt, sql, 0);
1!
1197
    checkError(stmt, code);
1!
1198

1199
    int     tag_i = 0;
1✔
1200
    int     tag_l = sizeof(int);
1✔
1201
    int     tag_bl = 3;
1✔
1202
    int64_t ts[2] = {1591060628000, NULL};
1✔
1203
    int     t64_len[2] = {sizeof(int64_t), sizeof(int64_t)};
1✔
1204
    int     coli[2] = {1, 2};
1✔
1205
    int     ilen[2] = {sizeof(int), sizeof(int)};
1✔
1206
    int     total_affect_rows = 0;
1✔
1207
    char    is_null[2] = {1, 1};
1✔
1208

1209
    TAOS_STMT2_BIND params1[2] = {{TSDB_DATA_TYPE_INT, &coli, &ilen[0], is_null, 2},
1✔
1210
                                  {TSDB_DATA_TYPE_TIMESTAMP, &ts, &t64_len[0], is_null, 2}};
1✔
1211

1212
    TAOS_STMT2_BIND* paramv = &params1[0];
1✔
1213
    char*            tbname = "tb3";
1✔
1214
    TAOS_STMT2_BINDV bindv = {1, &tbname, NULL, &paramv};
1✔
1215
    code = taos_stmt2_bind_param(stmt, &bindv, -1);
1!
1216
    ASSERT_EQ(code, TSDB_CODE_PAR_PRIMARY_KEY_IS_NULL);
1!
1217

1218
    taos_stmt2_close(stmt);
1!
1219
  }
1220
  // TD-34123 disorder pk ts
1221
  {
1222
    do_query(taos, "create stable stmt2_testdb_6.stb2  (ts timestamp, int_col int PRIMARY KEY) tags(int_tag int);");
1!
1223
    TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
1!
1224
    ASSERT_NE(stmt, nullptr);
1!
1225
    const char* sql =
1✔
1226
        "INSERT INTO stmt2_testdb_6.? using  stmt2_testdb_6.stb2 (int_tag)tags(1) (ts,int_col)VALUES (?,?)";
1227
    printf("stmt2 [%s] : %s\n", "disorder pk ts", sql);
1!
1228
    int code = taos_stmt2_prepare(stmt, sql, 0);
1!
1229
    checkError(stmt, code);
1!
1230

1231
    int     tag_i = 0;
1✔
1232
    int     tag_l = sizeof(int);
1✔
1233
    int     tag_bl = 3;
1✔
1234
    int64_t ts[5] = {1591060628003, 1591060628002, 1591060628002, 1591060628002, 1591060628001};
1✔
1235
    int     t64_len[5] = {sizeof(int64_t), sizeof(int64_t), sizeof(int64_t), sizeof(int64_t), sizeof(int64_t)};
1✔
1236
    int     coli[5] = {1, 4, 4, 3, 2};
1✔
1237
    int     ilen[5] = {sizeof(int), sizeof(int), sizeof(int), sizeof(int), sizeof(int)};
1✔
1238
    int     total_affect_rows = 0;
1✔
1239
    char    is_null[2] = {1, 1};
1✔
1240

1241
    TAOS_STMT2_BIND params1[2] = {
1✔
1242
        {TSDB_DATA_TYPE_TIMESTAMP, &ts, &t64_len[0], NULL, 5},
1243
        {TSDB_DATA_TYPE_INT, &coli, &ilen[0], NULL, 5},
1244
    };
1✔
1245

1246
    TAOS_STMT2_BIND* paramv = &params1[0];
1✔
1247
    char*            tbname = "tb3";
1✔
1248
    TAOS_STMT2_BINDV bindv = {1, &tbname, NULL, &paramv};
1✔
1249
    code = taos_stmt2_bind_param(stmt, &bindv, -1);
1!
1250
    checkError(stmt, code);
1!
1251

1252
    int affected_rows;
1253
    taos_stmt2_exec(stmt, &affected_rows);
1!
1254
    checkError(stmt, code);
1!
1255
    ASSERT_EQ(affected_rows, 4);
1!
1256

1257
    taos_stmt2_close(stmt);
1!
1258
  }
1259

1260
  // get fields insert into ? valuse
1261
  {
1262
    TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
1!
1263
    ASSERT_NE(stmt, nullptr);
1!
1264
    do_query(taos, "create table stmt2_testdb_6.ntb(ts timestamp, b binary(10))");
1!
1265
    do_query(taos, "use stmt2_testdb_6");
1!
1266
    const char* sql = "INSERT INTO ? VALUES (?,?)";
1✔
1267
    printf("stmt2 [%s] : %s\n", "get fields", sql);
1!
1268
    int code = taos_stmt2_prepare(stmt, sql, 0);
1!
1269
    checkError(stmt, code);
1!
1270

1271
    char*            tbname = "ntb";
1✔
1272
    TAOS_STMT2_BINDV bindv = {1, &tbname, NULL, NULL};
1✔
1273
    code = taos_stmt2_bind_param(stmt, &bindv, -1);
1!
1274
    ASSERT_EQ(code, 0);
1!
1275

1276
    int             fieldNum = 0;
1✔
1277
    TAOS_FIELD_ALL* pFields = NULL;
1✔
1278
    code = taos_stmt2_get_fields(stmt, &fieldNum, &pFields);
1!
1279
    checkError(stmt, code);
1!
1280
    ASSERT_EQ(fieldNum, 3);
1!
1281
    ASSERT_STREQ(pFields[0].name, "tbname");
1!
1282
    ASSERT_STREQ(pFields[1].name, "ts");
1!
1283
    ASSERT_STREQ(pFields[2].name, "b");
1!
1284

1285
    taos_stmt2_close(stmt);
1!
1286
  }
1287

1288
  // get fields cache error
1289
  {
1290
    TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
1!
1291
    ASSERT_NE(stmt, nullptr);
1!
1292
    const char* sql = " INSERT INTO ? using stmt2_testdb_6.stb1(int_tag) tags(1)(ts) VALUES(?) ";
1✔
1293
    printf("stmt2 [%s] : %s\n", "get fields", sql);
1!
1294
    int code = taos_stmt2_prepare(stmt, sql, 0);
1!
1295
    checkError(stmt, code);
1!
1296

1297
    int             fieldNum = 0;
1✔
1298
    TAOS_FIELD_ALL* pFields = NULL;
1✔
1299
    code = taos_stmt2_get_fields(stmt, &fieldNum, &pFields);
1!
1300
    checkError(stmt, code);
1!
1301
    ASSERT_EQ(fieldNum, 2);
1!
1302
    ASSERT_STREQ(pFields[0].name, "tbname");
1!
1303
    ASSERT_STREQ(pFields[1].name, "ts");
1!
1304

1305
    char*            tbname = "stmt2_testdb_6.中文表名";
1✔
1306
    TAOS_STMT2_BINDV bindv = {1, &tbname, NULL, NULL};
1✔
1307
    code = taos_stmt2_bind_param(stmt, &bindv, -1);
1!
1308
    ASSERT_EQ(code, TSDB_CODE_INVALID_PARA);
1!
1309

1310
    taos_stmt2_close(stmt);
1!
1311
  }
1312

1313
  do_query(taos, "drop database if exists stmt2_testdb_6");
1!
1314
  taos_close(taos);
1!
1315
}
1316

1317
// TD-33419
1318
// TD-34075
1319
TEST(stmt2Case, stmt2_insert_db) {
4✔
1320
  TAOS* taos = taos_connect("localhost", "root", "taosdata", "", 0);
1!
1321
  ASSERT_NE(taos, nullptr);
1!
1322
  do_query(taos, "drop database if exists stmt2_testdb_12");
1!
1323
  do_query(taos, "create database IF NOT EXISTS stmt2_testdb_12");
1!
1324
  do_query(taos, "create stable `stmt2_testdb_12`.`stb1`(ts timestamp, int_col int) tags(int_tag int)");
1!
1325
  do_query(taos,
1!
1326
           "INSERT INTO `stmt2_testdb_12`.`stb1` (ts,int_tag,tbname)  VALUES "
1327
           "(1591060627000,1,'tb1')(1591060627000,2,'tb2')");
1328

1329
  TAOS_STMT2_OPTION option = {0, true, true, NULL, NULL};
1✔
1330

1331
  TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
1!
1332
  ASSERT_NE(stmt, nullptr);
1!
1333
  const char* sql = "INSERT INTO `stmt2_testdb_12`.`stb1` (ts,int_tag,tbname)  VALUES (?,?,?)";
1✔
1334
  int         code = taos_stmt2_prepare(stmt, sql, 0);
1!
1335
  checkError(stmt, code);
1!
1336

1337
  int     t64_len[2] = {sizeof(int64_t), sizeof(int64_t)};
1✔
1338
  int     tag_i = 0;
1✔
1339
  int     tag_l = sizeof(int);
1✔
1340
  int64_t ts[2] = {1591060628000, 1591060628100};
1✔
1341
  int     total_affect_rows = 0;
1✔
1342
  for (int i = 0; i < 3; i++) {
4✔
1343
    ts[0] += 1000;
3✔
1344
    ts[1] += 1000;
3✔
1345

1346
    TAOS_STMT2_BIND tags1 = {TSDB_DATA_TYPE_INT, &tag_i, &tag_l, NULL, 1};
3✔
1347
    TAOS_STMT2_BIND tags2 = {TSDB_DATA_TYPE_INT, &tag_i, &tag_l, NULL, 1};
3✔
1348
    TAOS_STMT2_BIND params1 = {TSDB_DATA_TYPE_TIMESTAMP, &ts, &t64_len[0], NULL, 2};
3✔
1349
    TAOS_STMT2_BIND params2 = {TSDB_DATA_TYPE_TIMESTAMP, &ts, &t64_len[0], NULL, 2};
3✔
1350

1351
    TAOS_STMT2_BIND* tagv[2] = {&tags1, &tags2};
3✔
1352
    TAOS_STMT2_BIND* paramv[2] = {&params1, &params2};
3✔
1353
    char*            tbname[2] = {"tb1", "tb2"};
3✔
1354
    TAOS_STMT2_BINDV bindv = {2, &tbname[0], &tagv[0], &paramv[0]};
3✔
1355
    code = taos_stmt2_bind_param(stmt, &bindv, -1);
3!
1356
    checkError(stmt, code);
3!
1357

1358
    int affected_rows;
1359
    taos_stmt2_exec(stmt, &affected_rows);
3!
1360
    total_affect_rows += affected_rows;
3✔
1361
    checkError(stmt, code);
3!
1362
  }
1363

1364
  ASSERT_EQ(total_affect_rows, 12);
1!
1365
  taos_stmt2_close(stmt);
1!
1366
  do_query(taos, "drop database if exists stmt2_testdb_12");
1!
1367
  taos_close(taos);
1!
1368
}
1369

1370
TEST(stmt2Case, stmt2_query) {
4✔
1371
  TAOS* taos = taos_connect("localhost", "root", "taosdata", "", 0);
1!
1372
  ASSERT_NE(taos, nullptr);
1!
1373
  do_query(taos, "drop database if exists stmt2_testdb_7");
1!
1374
  do_query(taos, "create database IF NOT EXISTS stmt2_testdb_7");
1!
1375
  do_query(taos, "create stable stmt2_testdb_7.stb (ts timestamp, b binary(10)) tags(t1 int, t2 binary(10))");
1!
1376
  do_query(taos,
1!
1377
           "insert into stmt2_testdb_7.tb1 using stmt2_testdb_7.stb tags(1,'abc') values(1591060628000, "
1378
           "'abc'),(1591060628001,'def'),(1591060628002, 'hij')");
1379
  do_query(taos,
1!
1380
           "insert into stmt2_testdb_7.tb2 using stmt2_testdb_7.stb tags(2,'xyz') values(1591060628000, "
1381
           "'abc'),(1591060628001,'def'),(1591060628004, 'hij')");
1382
  do_query(taos, "use stmt2_testdb_7");
1!
1383

1384
  TAOS_STMT2_OPTION option = {0, true, true, NULL, NULL};
1✔
1385

1386
  TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
1!
1387
  ASSERT_NE(stmt, nullptr);
1!
1388

1389
  const char* sql = "select * from stmt2_testdb_7.stb where ts = ?";
1✔
1390
  int         code = taos_stmt2_prepare(stmt, sql, 0);
1!
1391
  checkError(stmt, code);
1!
1392

1393
  int              t64_len[1] = {sizeof(int64_t)};
1✔
1394
  int              b_len[1] = {3};
1✔
1395
  int64_t          ts = 1591060628000;
1✔
1396
  TAOS_STMT2_BIND  params = {TSDB_DATA_TYPE_TIMESTAMP, &ts, t64_len, NULL, 1};
1✔
1397
  TAOS_STMT2_BIND* paramv = &params;
1✔
1398
  TAOS_STMT2_BINDV bindv = {1, NULL, NULL, &paramv};
1✔
1399
  code = taos_stmt2_bind_param(stmt, &bindv, -1);
1!
1400
  checkError(stmt, code);
1!
1401

1402
  taos_stmt2_exec(stmt, NULL);
1!
1403
  checkError(stmt, code);
1!
1404

1405
  TAOS_RES* pRes = taos_stmt2_result(stmt);
1!
1406
  ASSERT_NE(pRes, nullptr);
1!
1407

1408
  int getRecordCounts = 0;
1✔
1409
  while ((taos_fetch_row(pRes))) {
3!
1410
    getRecordCounts++;
2✔
1411
  }
1412
  ASSERT_EQ(getRecordCounts, 2);
1!
1413
  // test 1 result
1414
  ts = 1591060628004;
1✔
1415
  params = {TSDB_DATA_TYPE_TIMESTAMP, &ts, t64_len, NULL, 1};
1✔
1416
  code = taos_stmt2_bind_param(stmt, &bindv, -1);
1!
1417
  checkError(stmt, code);
1!
1418

1419
  taos_stmt2_exec(stmt, NULL);
1!
1420
  checkError(stmt, code);
1!
1421

1422
  pRes = taos_stmt2_result(stmt);
1!
1423
  ASSERT_NE(pRes, nullptr);
1!
1424

1425
  getRecordCounts = 0;
1✔
1426
  while ((taos_fetch_row(pRes))) {
2!
1427
    getRecordCounts++;
1✔
1428
  }
1429
  ASSERT_EQ(getRecordCounts, 1);
1!
1430
  // taos_free_result(pRes);
1431
  taos_stmt2_close(stmt);
1!
1432
  do_query(taos, "drop database if exists stmt2_testdb_7");
1!
1433
  taos_close(taos);
1!
1434
}
1435

1436
TEST(stmt2Case, stmt2_ntb_insert) {
4✔
1437
  TAOS* taos = taos_connect("localhost", "root", "taosdata", "", 0);
1!
1438
  ASSERT_NE(taos, nullptr);
1!
1439
  TAOS_STMT2_OPTION option = {0, true, true, NULL, NULL};
1✔
1440
  do_query(taos, "drop database if exists stmt2_testdb_8");
1!
1441
  do_query(taos, "create database IF NOT EXISTS stmt2_testdb_8");
1!
1442
  do_query(taos, "create table stmt2_testdb_8.ntb(ts timestamp, b binary(10))");
1!
1443
  do_query(taos, "use stmt2_testdb_8");
1!
1444
  TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
1!
1445
  ASSERT_NE(stmt, nullptr);
1!
1446

1447
  int total_affected_rows = 0;
1✔
1448

1449
  const char* sql = "insert into stmt2_testdb_8.ntb values(?,?)";
1✔
1450
  int         code = taos_stmt2_prepare(stmt, sql, 0);
1!
1451
  checkError(stmt, code);
1!
1452
  for (int i = 0; i < 3; i++) {
4✔
1453
    int64_t ts[3] = {1591060628000 + i * 3, 1591060628001 + i * 3, 1591060628002 + i * 3};
3✔
1454
    int     t64_len[3] = {sizeof(int64_t), sizeof(int64_t), sizeof(int64_t)};
3✔
1455
    int     b_len[3] = {5, 5, 5};
3✔
1456

1457
    TAOS_STMT2_BIND  params1 = {TSDB_DATA_TYPE_TIMESTAMP, &ts[0], &t64_len[0], NULL, 3};
3✔
1458
    TAOS_STMT2_BIND  params2 = {TSDB_DATA_TYPE_BINARY, (void*)"abcdefghijklmnopqrstuvwxyz", &b_len[0], NULL, 3};
3✔
1459
    TAOS_STMT2_BIND* paramv1 = &params1;
3✔
1460
    TAOS_STMT2_BIND* paramv2 = &params2;
3✔
1461

1462
    TAOS_STMT2_BINDV bindv1 = {1, NULL, NULL, &paramv1};
3✔
1463
    TAOS_STMT2_BINDV bindv2 = {1, NULL, NULL, &paramv2};
3✔
1464

1465
    code = taos_stmt2_bind_param(stmt, &bindv1, 0);
3!
1466
    code = taos_stmt2_bind_param(stmt, &bindv2, 1);
3!
1467
    checkError(stmt, code);
3!
1468

1469
    int affected_rows;
1470
    code = taos_stmt2_exec(stmt, &affected_rows);
3!
1471
    total_affected_rows += affected_rows;
3✔
1472
    checkError(stmt, code);
3!
1473
  }
1474
  ASSERT_EQ(total_affected_rows, 9);
1!
1475

1476
  taos_stmt2_close(stmt);
1!
1477
  do_query(taos, "drop database if exists stmt2_testdb_8");
1!
1478
  taos_close(taos);
1!
1479
}
1480

1481
TEST(stmt2Case, stmt2_status_Test) {
4✔
1482
  TAOS* taos = taos_connect("localhost", "root", "taosdata", "", 0);
1!
1483
  ASSERT_NE(taos, nullptr);
1!
1484
  TAOS_STMT2_OPTION option = {0, true, true, NULL, NULL};
1✔
1485
  TAOS_STMT2*       stmt = taos_stmt2_init(taos, &option);
1!
1486

1487
  int64_t ts[3] = {1591060628000, 1591060628001, 1591060628002};
1✔
1488
  int     t64_len[3] = {sizeof(int64_t), sizeof(int64_t), sizeof(int64_t)};
1✔
1489

1490
  TAOS_STMT2_BIND  params = {TSDB_DATA_TYPE_TIMESTAMP, &ts[0], &t64_len[0], NULL, 3};
1✔
1491
  TAOS_STMT2_BIND* paramv = &params;
1✔
1492
  TAOS_STMT2_BINDV bindv1 = {1, NULL, NULL, &paramv};
1✔
1493

1494
  int code = taos_stmt2_bind_param(stmt, &bindv1, 0);
1!
1495
  ASSERT_EQ(code, TSDB_CODE_TSC_STMT_BIND_NUMBER_ERROR);
1!
1496
  ASSERT_STREQ(taos_stmt2_error(stmt), "bind number out of range or not match");
1!
1497

1498
  code = taos_stmt2_exec(stmt, NULL);
1!
1499
  ASSERT_EQ(code, TSDB_CODE_TSC_STMT_API_ERROR);
1!
1500
  ASSERT_STREQ(taos_stmt2_error(stmt), "Stmt API usage error");
1!
1501

1502
  const char* sql = "insert into stmt2_testdb_9.ntb values(?,?)";
1✔
1503
  code = taos_stmt2_prepare(stmt, sql, 0);
1!
1504
  ASSERT_EQ(code, TSDB_CODE_TSC_STMT_API_ERROR);
1!
1505
  ASSERT_STREQ(taos_stmt2_error(stmt), "Stmt API usage error");
1!
1506

1507
  taos_stmt2_close(stmt);
1!
1508
  taos_close(taos);
1!
1509
}
1510

1511
TEST(stmt2Case, stmt2_nchar) {
4✔
1512
  TAOS* taos = taos_connect("localhost", "root", "taosdata", "", 0);
1!
1513
  do_query(taos, "drop database if exists stmt2_testdb_10;");
1!
1514
  do_query(taos, "create database IF NOT EXISTS stmt2_testdb_10;");
1!
1515
  do_query(taos, "use stmt2_testdb_10;");
1!
1516
  do_query(taos,
1!
1517
           "create table m1 (ts timestamp, blob2 nchar(10), blob nchar(10),blob3 nchar(10),blob4 nchar(10),blob5 "
1518
           "nchar(10))");
1519

1520
  // insert 10 records
1521
  struct {
1522
    int64_t ts[10];
1523
    char    blob[10][1];
1524
    char    blob2[10][1];
1525
    char    blob3[10][1];
1526
    char    blob4[10][1];
1527
    char    blob5[10][1];
1528

1529
  } v;
1530

1531
  int32_t* t64_len = (int32_t*)taosMemMalloc(sizeof(int32_t) * 10);
1!
1532
  int32_t* blob_len = (int32_t*)taosMemMalloc(sizeof(int32_t) * 10);
1!
1533
  int32_t* blob_len2 = (int32_t*)taosMemMalloc(sizeof(int32_t) * 10);
1!
1534
  int32_t* blob_len3 = (int32_t*)taosMemMalloc(sizeof(int32_t) * 10);
1!
1535
  int32_t* blob_len4 = (int32_t*)taosMemMalloc(sizeof(int32_t) * 10);
1!
1536
  int32_t* blob_len5 = (int32_t*)taosMemMalloc(sizeof(int32_t) * 10);
1!
1537

1538
  TAOS_STMT2_OPTION option = {0, true, true, NULL, NULL};
1✔
1539

1540
  TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
1!
1541
  ASSERT_NE(stmt, nullptr);
1!
1542
  TAOS_STMT2_BIND params[10];
1543
  char            is_null[10] = {0};
1✔
1544

1545
  params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
1✔
1546
  // params[0].buffer_length = sizeof(v.ts[0]);
1547
  params[0].buffer = v.ts;
1✔
1548
  params[0].length = t64_len;
1✔
1549
  params[0].is_null = is_null;
1✔
1550
  params[0].num = 10;
1✔
1551

1552
  params[1].buffer_type = TSDB_DATA_TYPE_NCHAR;
1✔
1553
  // params[8].buffer_length = sizeof(v.blob2[0]);
1554
  params[1].buffer = v.blob2;
1✔
1555
  params[1].length = blob_len2;
1✔
1556
  params[1].is_null = is_null;
1✔
1557
  params[1].num = 10;
1✔
1558

1559
  params[2].buffer_type = TSDB_DATA_TYPE_NCHAR;
1✔
1560
  // params[9].buffer_length = sizeof(v.blob[0]);
1561
  params[2].buffer = v.blob3;
1✔
1562
  params[2].length = blob_len;
1✔
1563
  params[2].is_null = is_null;
1✔
1564
  params[2].num = 10;
1✔
1565

1566
  params[3].buffer_type = TSDB_DATA_TYPE_NCHAR;
1✔
1567
  // params[9].buffer_length = sizeof(v.blob[0]);
1568
  params[3].buffer = v.blob4;
1✔
1569
  params[3].length = blob_len;
1✔
1570
  params[3].is_null = is_null;
1✔
1571
  params[3].num = 10;
1✔
1572

1573
  params[4].buffer_type = TSDB_DATA_TYPE_NCHAR;
1✔
1574
  // params[9].buffer_length = sizeof(v.blob[0]);
1575
  params[4].buffer = v.blob;
1✔
1576
  params[4].length = blob_len;
1✔
1577
  params[4].is_null = is_null;
1✔
1578
  params[4].num = 10;
1✔
1579

1580
  params[5].buffer_type = TSDB_DATA_TYPE_NCHAR;
1✔
1581
  // params[9].buffer_length = sizeof(v.blob[0]);
1582
  params[5].buffer = v.blob5;
1✔
1583
  params[5].length = blob_len;
1✔
1584
  params[5].is_null = is_null;
1✔
1585
  params[5].num = 10;
1✔
1586

1587
  int code = taos_stmt2_prepare(stmt, "insert into ? (ts, blob2, blob, blob3, blob4, blob5) values(?,?,?,?,?,?)", 0);
1!
1588
  checkError(stmt, code);
1!
1589

1590
  int64_t ts = 1591060628000;
1✔
1591
  for (int i = 0; i < 10; ++i) {
11✔
1592
    is_null[i] = 0;
10✔
1593

1594
    v.ts[i] = ts++;
10✔
1595

1596
    v.blob[i][0] = 'a' + i;
10✔
1597
    v.blob2[i][0] = 'f' + i;
10✔
1598
    v.blob3[i][0] = 't' + i;
10✔
1599
    v.blob4[i][0] = 'A' + i;
10✔
1600
    v.blob5[i][0] = 'G' + i;
10✔
1601

1602
    blob_len[i] = sizeof(char);
10✔
1603
    blob_len2[i] = sizeof(char);
10✔
1604
    blob_len3[i] = sizeof(char);
10✔
1605
    blob_len4[i] = sizeof(char);
10✔
1606
    blob_len5[i] = sizeof(char);
10✔
1607
  }
1608

1609
  char*            tbname = "m1";
1✔
1610
  TAOS_STMT2_BIND* bind_cols[1] = {&params[0]};
1✔
1611
  TAOS_STMT2_BINDV bindv = {1, &tbname, NULL, &bind_cols[0]};
1✔
1612
  code = taos_stmt2_bind_param(stmt, &bindv, -1);
1!
1613
  checkError(stmt, code);
1!
1614

1615
  int affected_rows;
1616
  code = taos_stmt2_exec(stmt, &affected_rows);
1!
1617
  checkError(stmt, code);
1!
1618
  ASSERT_EQ(affected_rows, 10);
1!
1619

1620
  taos_stmt2_close(stmt);
1!
1621
  do_query(taos, "drop database if exists stmt2_testdb_10;");
1!
1622
  taos_close(taos);
1!
1623
  taosMemoryFree(blob_len);
1!
1624
  taosMemoryFree(blob_len2);
1!
1625
  taosMemoryFree(blob_len5);
1!
1626
  taosMemoryFree(blob_len3);
1!
1627
  taosMemoryFree(blob_len4);
1!
1628
}
1629

1630
TEST(stmt2Case, all_type) {
4✔
1631
  TAOS* taos = taos_connect("localhost", "root", "taosdata", "", 0);
1!
1632
  ASSERT_NE(taos, nullptr);
1!
1633

1634
  do_query(taos, "drop database if exists stmt2_testdb_11");
1!
1635
  do_query(taos, "create database IF NOT EXISTS stmt2_testdb_11");
1!
1636
  do_query(
1!
1637
      taos,
1638
      "create stable stmt2_testdb_11.stb(ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 binary(8), c6 "
1639
      "smallint, c7 "
1640
      "tinyint, c8 bool, c9 nchar(8), c10 geometry(256))TAGS(tts timestamp, t1 int, t2 bigint, t3 float, t4 double, t5 "
1641
      "binary(8), t6 smallint, t7 tinyint, t8 bool, t9 nchar(8), t10 geometry(256))");
1642

1643
  TAOS_STMT2_OPTION option = {0};
1✔
1644
  TAOS_STMT2*       stmt = taos_stmt2_init(taos, &option);
1!
1645
  ASSERT_NE(stmt, nullptr);
1!
1646
  int       code = 0;
1✔
1647
  uintptr_t c10len = 0;
1✔
1648
  struct {
1649
    int64_t       c1;
1650
    int32_t       c2;
1651
    int64_t       c3;
1652
    float         c4;
1653
    double        c5;
1654
    unsigned char c6[8];
1655
    int16_t       c7;
1656
    int8_t        c8;
1657
    int8_t        c9;
1658
    char          c10[32];
1659
  } v = {1591060628000, 1, 2, 3.0, 4.0, "abcdef", 5, 6, 7, "ijnop"};
1✔
1660

1661
  struct {
1662
    int32_t c1;
1663
    int32_t c2;
1664
    int32_t c3;
1665
    int32_t c4;
1666
    int32_t c5;
1667
    int32_t c6;
1668
    int32_t c7;
1669
    int32_t c8;
1670
    int32_t c9;
1671
    int32_t c10;
1672
  } v_len = {sizeof(int64_t), sizeof(int32_t),
1✔
1673
             sizeof(int64_t), sizeof(float),
1674
             sizeof(double),  8,
1675
             sizeof(int16_t), sizeof(int8_t),
1676
             sizeof(int8_t),  8};
1677
  TAOS_STMT2_BIND params[11];
1678
  params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
1✔
1679
  params[0].length = (int32_t*)&v_len.c1;
1✔
1680
  params[0].buffer = &v.c1;
1✔
1681
  params[0].is_null = NULL;
1✔
1682
  params[0].num = 1;
1✔
1683

1684
  params[1].buffer_type = TSDB_DATA_TYPE_INT;
1✔
1685
  params[1].buffer = &v.c2;
1✔
1686
  params[1].length = (int32_t*)&v_len.c2;
1✔
1687
  params[1].is_null = NULL;
1✔
1688
  params[1].num = 1;
1✔
1689

1690
  params[2].buffer_type = TSDB_DATA_TYPE_BIGINT;
1✔
1691
  params[2].buffer = &v.c3;
1✔
1692
  params[2].length = (int32_t*)&v_len.c3;
1✔
1693
  params[2].is_null = NULL;
1✔
1694
  params[2].num = 1;
1✔
1695

1696
  params[3].buffer_type = TSDB_DATA_TYPE_FLOAT;
1✔
1697
  params[3].buffer = &v.c4;
1✔
1698
  params[3].length = (int32_t*)&v_len.c4;
1✔
1699
  params[3].is_null = NULL;
1✔
1700
  params[3].num = 1;
1✔
1701

1702
  params[4].buffer_type = TSDB_DATA_TYPE_DOUBLE;
1✔
1703
  params[4].buffer = &v.c5;
1✔
1704
  params[4].length = (int32_t*)&v_len.c5;
1✔
1705
  params[4].is_null = NULL;
1✔
1706
  params[4].num = 1;
1✔
1707

1708
  params[5].buffer_type = TSDB_DATA_TYPE_BINARY;
1✔
1709
  params[5].buffer = &v.c6;
1✔
1710
  params[5].length = (int32_t*)&v_len.c6;
1✔
1711
  params[5].is_null = NULL;
1✔
1712
  params[5].num = 1;
1✔
1713

1714
  params[6].buffer_type = TSDB_DATA_TYPE_SMALLINT;
1✔
1715
  params[6].buffer = &v.c7;
1✔
1716
  params[6].length = (int32_t*)&v_len.c7;
1✔
1717
  params[6].is_null = NULL;
1✔
1718
  params[6].num = 1;
1✔
1719

1720
  params[7].buffer_type = TSDB_DATA_TYPE_TINYINT;
1✔
1721
  params[7].buffer = &v.c8;
1✔
1722
  params[7].length = (int32_t*)&v_len.c8;
1✔
1723
  params[7].is_null = NULL;
1✔
1724
  params[7].num = 1;
1✔
1725

1726
  params[8].buffer_type = TSDB_DATA_TYPE_BOOL;
1✔
1727
  params[8].buffer = &v.c9;
1✔
1728
  params[8].length = (int32_t*)&v_len.c9;
1✔
1729
  params[8].is_null = NULL;
1✔
1730
  params[8].num = 1;
1✔
1731

1732
  params[9].buffer_type = TSDB_DATA_TYPE_NCHAR;
1✔
1733
  params[9].buffer = &v.c10;
1✔
1734
  params[9].length = (int32_t*)&v_len.c10;
1✔
1735
  params[9].is_null = NULL;
1✔
1736
  params[9].num = 1;
1✔
1737

1738
  unsigned char* outputGeom1;
1739
  size_t         size1;
1740
  initCtxMakePoint();
1!
1741
  code = doMakePoint(1.000, 2.000, &outputGeom1, &size1);
1!
1742
  checkError(stmt, code);
1!
1743
  params[10].buffer_type = TSDB_DATA_TYPE_GEOMETRY;
1✔
1744
  params[10].buffer = outputGeom1;
1✔
1745
  params[10].length = (int32_t*)&size1;
1✔
1746
  params[10].is_null = NULL;
1✔
1747
  params[10].num = 1;
1✔
1748

1749
  char* stmt_sql = "insert into stmt2_testdb_11.? using stb tags(?,?,?,?,?,?,?,?,?,?,?)values (?,?,?,?,?,?,?,?,?,?,?)";
1✔
1750
  code = taos_stmt2_prepare(stmt, stmt_sql, 0);
1!
1751
  checkError(stmt, code);
1!
1752

1753
  char*            tbname[1] = {"tb1"};
1✔
1754
  TAOS_STMT2_BIND* tags = &params[0];
1✔
1755
  TAOS_STMT2_BIND* cols = &params[0];
1✔
1756
  TAOS_STMT2_BINDV bindv = {1, &tbname[0], &tags, &cols};
1✔
1757
  code = taos_stmt2_bind_param(stmt, &bindv, -1);
1!
1758
  checkError(stmt, code);
1!
1759

1760
  int affected_rows;
1761
  code = taos_stmt2_exec(stmt, &affected_rows);
1!
1762
  checkError(stmt, code);
1!
1763
  ASSERT_EQ(affected_rows, 1);
1!
1764

1765
  geosFreeBuffer(outputGeom1);
1!
1766
  taos_stmt2_close(stmt);
1!
1767
  do_query(taos, "drop database if exists stmt2_testdb_11");
1!
1768
  taos_close(taos);
1!
1769
}
1770

1771
TEST(stmt2Case, geometry) {
4✔
1772
  TAOS* taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
1!
1773
  ASSERT_NE(taos, nullptr);
1!
1774

1775
  do_query(taos, "DROP DATABASE IF EXISTS stmt2_testdb_13");
1!
1776
  do_query(taos, "CREATE DATABASE IF NOT EXISTS stmt2_testdb_13");
1!
1777
  do_query(taos,
1!
1778
           "CREATE STABLE stmt2_testdb_13.stb (ts timestamp, c1 geometry(256)) tags(t1 timestamp,t2 geometry(256))");
1779
  do_query(taos, "CREATE TABLE stmt2_testdb_13.tb1(ts timestamp,c1 geometry(256))");
1!
1780

1781
  //  wrong wkb input
1782
  unsigned char wkb1[] = {
1✔
1783
      // 1
1784
      0x01,                                            // 字节顺序:小端字节序
1785
      0x01, 0x00, 0x00, 0x00,                          // 几何类型:Point (1)
1786
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F,  // p1
1787
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40,  // p2
1788
                                                       // 2
1789
      0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1790
      0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00,
1791
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00,
1792
      0x00, 0x00, 0xf0, 0x3f,
1793
      // 3
1794
      0x01, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00,
1795
      0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
1796
      0x00, 0x00, 0x40};
1797
  //  wrong wkb input
1798
  unsigned char wkb2[3][61] = {
1✔
1799
      {
1800
          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1801
          0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40,
1802
      },
1803
      {0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1804
       0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00,
1805
       0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
1806
       0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f},
1807
      {0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1808
       0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00,
1809
       0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40}};
1810

1811
  // unsigned char* wkb_all[3]{&wkb1[0], &wkb2[0], &wkb3[0]};
1812
  int32_t wkb_len[4] = {21, 61, 41, 0};
1✔
1813

1814
  int64_t         ts[4] = {1591060628000, 1591060628001, 1591060628002, 1591060628003};
1✔
1815
  int32_t         t64_len[4] = {sizeof(int64_t), sizeof(int64_t), sizeof(int64_t), sizeof(int64_t)};
1✔
1816
  char            is_null[4] = {0, 0, 0, 1};
1✔
1817
  TAOS_STMT2_BIND params[2];
1818
  params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
1✔
1819
  params[0].buffer = &ts[0];
1✔
1820
  params[0].length = &t64_len[0];
1✔
1821
  params[0].is_null = NULL;
1✔
1822
  params[0].num = 4;
1✔
1823

1824
  params[1].buffer_type = TSDB_DATA_TYPE_GEOMETRY;
1✔
1825
  params[1].buffer = &wkb1[0];
1✔
1826
  params[1].length = &wkb_len[0];
1✔
1827
  params[1].is_null = is_null;
1✔
1828
  params[1].num = 4;
1✔
1829

1830
  // case 1 : ntb
1831
  {
1832
    printf("  case 1 : ntb\n");
1!
1833
    TAOS_STMT2_OPTION option = {0};
1✔
1834
    TAOS_STMT2*       stmt = taos_stmt2_init(taos, &option);
1!
1835
    ASSERT_NE(stmt, nullptr);
1!
1836

1837
    char* stmt_sql = "insert into stmt2_testdb_13.tb1 (ts,c1)values(?,?)";
1✔
1838
    int   code = taos_stmt2_prepare(stmt, stmt_sql, 0);
1!
1839
    checkError(stmt, code);
1!
1840

1841
    TAOS_STMT2_BIND* cols = &params[0];
1✔
1842
    TAOS_STMT2_BINDV bindv = {1, NULL, NULL, &cols};
1✔
1843
    code = taos_stmt2_bind_param(stmt, &bindv, -1);
1!
1844
    checkError(stmt, code);
1!
1845

1846
    int affected_rows;
1847
    code = taos_stmt2_exec(stmt, &affected_rows);
1!
1848
    checkError(stmt, code);
1!
1849
    ASSERT_EQ(affected_rows, 4);
1!
1850
  }
1851
  // case 2 : interlace = 1
1852
  {
1853
    printf("  case 2 : interlace = 1\n");
1!
1854
    TAOS_STMT2_OPTION option = {0, true, true, NULL, NULL};
1✔
1855
    TAOS_STMT2*       stmt = taos_stmt2_init(taos, &option);
1!
1856
    ASSERT_NE(stmt, nullptr);
1!
1857

1858
    char* stmt_sql = "insert into stmt2_testdb_13.? using stmt2_testdb_13.stb tags(?,?)values(?,?)";
1✔
1859
    int   code = taos_stmt2_prepare(stmt, stmt_sql, 0);
1!
1860
    checkError(stmt, code);
1!
1861

1862
    char*            ctbname[1] = {"ctb1"};
1✔
1863
    TAOS_STMT2_BIND* cols = &params[0];
1✔
1864
    TAOS_STMT2_BINDV bindv = {1, ctbname, &cols, &cols};
1✔
1865
    code = taos_stmt2_bind_param(stmt, &bindv, -1);
1!
1866
    checkError(stmt, code);
1!
1867

1868
    int affected_rows;
1869
    code = taos_stmt2_exec(stmt, &affected_rows);
1!
1870
    checkError(stmt, code);
1!
1871
    ASSERT_EQ(affected_rows, 4);
1!
1872
    taos_stmt2_close(stmt);
1!
1873
  }
1874
  // case 3 : interlace = 0
1875
  {
1876
    printf("  case 3 : interlace = 0\n");
1!
1877
    TAOS_STMT2_OPTION option = {0, false, false, NULL, NULL};
1✔
1878
    TAOS_STMT2*       stmt = taos_stmt2_init(taos, &option);
1!
1879
    ASSERT_NE(stmt, nullptr);
1!
1880

1881
    char* stmt_sql = "insert into stmt2_testdb_13.? using stmt2_testdb_13.stb tags(?,?)values(?,?)";
1✔
1882
    int   code = taos_stmt2_prepare(stmt, stmt_sql, 0);
1!
1883
    checkError(stmt, code);
1!
1884

1885
    char*            ctbname[1] = {"ctb2"};
1✔
1886
    TAOS_STMT2_BIND* cols = &params[0];
1✔
1887
    TAOS_STMT2_BINDV bindv = {1, ctbname, &cols, &cols};
1✔
1888
    code = taos_stmt2_bind_param(stmt, &bindv, -1);
1!
1889
    checkError(stmt, code);
1!
1890

1891
    int affected_rows;
1892
    code = taos_stmt2_exec(stmt, &affected_rows);
1!
1893
    checkError(stmt, code);
1!
1894
    ASSERT_EQ(affected_rows, 4);
1!
1895
    taos_stmt2_close(stmt);
1!
1896
  }
1897
  // case 4 : error case
1898
  params[1].buffer = &wkb2[0];
1✔
1899
  {
1900
    printf("  case 4 : error format\n");
1!
1901
    TAOS_STMT2_OPTION option = {0, false, false, NULL, NULL};
1✔
1902
    TAOS_STMT2*       stmt = taos_stmt2_init(taos, &option);
1!
1903
    ASSERT_NE(stmt, nullptr);
1!
1904

1905
    char* stmt_sql = "insert into stmt2_testdb_13.? using stmt2_testdb_13.stb tags(?,?)values(?,?)";
1✔
1906
    int   code = taos_stmt2_prepare(stmt, stmt_sql, 0);
1!
1907
    checkError(stmt, code);
1!
1908

1909
    char*            ctbname[1] = {"ctb3"};
1✔
1910
    TAOS_STMT2_BIND* cols = &params[0];
1✔
1911
    TAOS_STMT2_BINDV bindv = {1, ctbname, &cols, &cols};
1✔
1912
    code = taos_stmt2_bind_param(stmt, &bindv, -1);
1!
1913
    ASSERT_EQ(code, TSDB_CODE_FUNC_FUNTION_PARA_VALUE);
1!
1914
    taos_stmt2_close(stmt);
1!
1915
  }
1916

1917
  do_query(taos, "DROP DATABASE IF EXISTS stmt2_testdb_13");
1!
1918
  taos_close(taos);
1!
1919
}
1920

1921
// TD-33582
1922
TEST(stmt2Case, errcode) {
4✔
1923
  TAOS* taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
1!
1924
  ASSERT_NE(taos, nullptr);
1!
1925
  do_query(taos, "DROP DATABASE IF EXISTS stmt2_testdb_14");
1!
1926
  do_query(taos, "CREATE DATABASE IF NOT EXISTS stmt2_testdb_14");
1!
1927
  do_query(taos, "use stmt2_testdb_14");
1!
1928

1929
  TAOS_STMT2_OPTION option = {0};
1✔
1930
  TAOS_STMT2*       stmt = taos_stmt2_init(taos, &option);
1!
1931
  ASSERT_NE(stmt, nullptr);
1!
1932
  char* sql = "select * from t where ts > ? and name = ? foo = ?";
1✔
1933
  int   code = taos_stmt2_prepare(stmt, sql, 0);
1!
1934
  checkError(stmt, code);
1!
1935

1936
  int             fieldNum = 0;
1✔
1937
  TAOS_FIELD_ALL* pFields = NULL;
1✔
1938
  code = taos_stmt2_get_fields(stmt, &fieldNum, &pFields);
1!
1939
  ASSERT_EQ(code, TSDB_CODE_PAR_SYNTAX_ERROR);
1!
1940

1941
  // get fail dont influence the next stmt prepare
1942
  sql = "nsert into ? (ts, name) values (?, ?)";
1✔
1943
  code = taos_stmt_prepare(stmt, sql, 0);
1!
1944
  checkError(stmt, code);
1!
1945
}
1946

1947
void stmtAsyncBindCb(void* param, TAOS_RES* pRes, int code) {
×
1948
  bool* finish = (bool*)param;
×
1949
  ASSERT_EQ(code, TSDB_CODE_SUCCESS);
×
1950
  taosMsleep(500);
×
1951
  *finish = true;
×
1952
  return;
×
1953
}
1954

1955
void stmtAsyncQueryCb2(void* param, TAOS_RES* pRes, int code) {
×
1956
  ASSERT_EQ(code, TSDB_CODE_SUCCESS);
×
1957
  taosMsleep(500);
×
1958
  return;
×
1959
}
1960

1961
void stmtAsyncBindCb2(void* param, TAOS_RES* pRes, int code) {
×
1962
  bool* finish = (bool*)param;
×
1963
  taosMsleep(500);
×
1964
  *finish = true;
×
1965
  return;
×
1966
}
1967

1968
void stmt2_async_test(std::atomic<bool>& stop_task) {
×
1969
  int CTB_NUMS = 2;
×
1970
  int ROW_NUMS = 2;
×
1971
  int CYC_NUMS = 2;
×
1972

1973
  TAOS*             taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
×
1974
  TAOS_STMT2_OPTION option = {0, true, true, stmtAsyncQueryCb2, NULL};
×
1975
  char*             sql = "insert into ? values(?,?)";
×
1976

1977
  do_query(taos, "drop database if exists stmt2_testdb_15");
×
1978
  do_query(taos, "create database IF NOT EXISTS stmt2_testdb_15");
×
1979
  do_query(taos, "create stable stmt2_testdb_15.stb (ts timestamp, b binary(10)) tags(t1 int, t2 binary(10))");
×
1980
  do_query(taos, "use stmt2_testdb_15");
×
1981

1982
  TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
×
1983
  ASSERT_NE(stmt, nullptr);
×
1984
  int code = taos_stmt2_prepare(stmt, sql, 0);
×
1985
  checkError(stmt, code);
×
1986
  int total_affected = 0;
×
1987

1988
  // tbname
1989
  char** tbs = (char**)taosMemoryMalloc(CTB_NUMS * sizeof(char*));
×
1990
  for (int i = 0; i < CTB_NUMS; i++) {
×
1991
    tbs[i] = (char*)taosMemoryMalloc(sizeof(char) * 20);
×
1992
    sprintf(tbs[i], "ctb_%d", i);
×
1993
    char* tmp = (char*)taosMemoryMalloc(sizeof(char) * 100);
×
1994
    sprintf(tmp, "create table stmt2_testdb_15.%s using stmt2_testdb_15.stb tags(0, 'after')", tbs[i]);
×
1995
    do_query(taos, tmp);
×
1996
  }
1997
  // params
1998
  TAOS_STMT2_BIND** paramv = (TAOS_STMT2_BIND**)taosMemoryMalloc(CTB_NUMS * sizeof(TAOS_STMT2_BIND*));
×
1999
  // col params
2000
  int64_t** ts = (int64_t**)taosMemoryMalloc(CTB_NUMS * sizeof(int64_t*));
×
2001
  char**    b = (char**)taosMemoryMalloc(CTB_NUMS * sizeof(char*));
×
2002
  int*      ts_len = (int*)taosMemoryMalloc(ROW_NUMS * sizeof(int));
×
2003
  int*      b_len = (int*)taosMemoryMalloc(ROW_NUMS * sizeof(int));
×
2004
  for (int i = 0; i < ROW_NUMS; i++) {
×
2005
    ts_len[i] = sizeof(int64_t);
×
2006
    b_len[i] = 1;
×
2007
  }
2008
  for (int i = 0; i < CTB_NUMS; i++) {
×
2009
    ts[i] = (int64_t*)taosMemoryMalloc(ROW_NUMS * sizeof(int64_t));
×
2010
    b[i] = (char*)taosMemoryMalloc(ROW_NUMS * sizeof(char));
×
2011
    for (int j = 0; j < ROW_NUMS; j++) {
×
2012
      ts[i][j] = 1591060628000 + 100000 + j;
×
2013
      b[i][j] = 'a' + j;
×
2014
    }
2015
  }
2016
  // bind params
2017
  for (int i = 0; i < CTB_NUMS; i++) {
×
2018
    // create col params
2019
    paramv[i] = (TAOS_STMT2_BIND*)taosMemoryMalloc(2 * sizeof(TAOS_STMT2_BIND));
×
2020
    paramv[i][0] = {TSDB_DATA_TYPE_TIMESTAMP, &ts[i][0], &ts_len[0], NULL, ROW_NUMS};
×
2021
    paramv[i][1] = {TSDB_DATA_TYPE_BINARY, &b[i][0], &b_len[0], NULL, ROW_NUMS};
×
2022
  }
2023

2024
  // case 1 : bind_a->exec_a->bind_a->exec_a->...
2025
  {
2026
    printf("case 1 : bind_a->exec_a->bind_a->exec_a->...\n");
×
2027
    for (int r = 0; r < CYC_NUMS; r++) {
×
2028
      // bind
2029
      TAOS_STMT2_BINDV bindv = {CTB_NUMS, tbs, NULL, paramv};
×
2030
      bool             finish = false;
×
2031
      code = taos_stmt2_bind_param_a(stmt, &bindv, -1, stmtAsyncBindCb, (void*)&finish);
×
2032

2033
      checkError(stmt, code);
×
2034

2035
      // exec
2036
      code = taos_stmt2_exec(stmt, NULL);
×
2037
      checkError(stmt, code);
×
2038
    }
2039
  }
2040

2041
  // case 2 : bind_a->bind_a->bind_a->exec_a->...
2042
  {
2043
    printf("case 2 : bind_a->bind_a->bind_a->exec_a->...\n");
×
2044
    for (int r = 0; r < CYC_NUMS; r++) {
×
2045
      // bind params
2046
      TAOS_STMT2_BIND** paramv = (TAOS_STMT2_BIND**)taosMemoryMalloc(CTB_NUMS * sizeof(TAOS_STMT2_BIND*));
×
2047
      for (int i = 0; i < CTB_NUMS; i++) {
×
2048
        // create col params
2049
        paramv[i] = (TAOS_STMT2_BIND*)taosMemoryMalloc(2 * sizeof(TAOS_STMT2_BIND));
×
2050
        paramv[i][0] = {TSDB_DATA_TYPE_TIMESTAMP, &ts[i][0], &ts_len[0], NULL, ROW_NUMS};
×
2051
        paramv[i][1] = {TSDB_DATA_TYPE_BINARY, &b[i][0], &b_len[0], NULL, ROW_NUMS};
×
2052
      }
2053
      // bind
2054
      TAOS_STMT2_BINDV bindv = {CTB_NUMS, tbs, NULL, paramv};
×
2055
      bool             finish = false;
×
2056
      code = taos_stmt2_bind_param_a(stmt, &bindv, -1, stmtAsyncBindCb, (void*)&finish);
×
2057
      while (!finish) {
×
2058
        taosMsleep(100);
×
2059
      }
2060
      checkError(stmt, code);
×
2061
    }
2062
    // exec
2063
    code = taos_stmt2_exec(stmt, NULL);
×
2064
    checkError(stmt, code);
×
2065
  }
2066

2067
  // case 3 : bind->exec_a->bind->exec_a->...
2068
  {
2069
    printf("case 3 : bind->exec_a->bind->exec_a->...\n");
×
2070
    for (int r = 0; r < CYC_NUMS; r++) {
×
2071
      // bind
2072
      TAOS_STMT2_BINDV bindv = {CTB_NUMS, tbs, NULL, paramv};
×
2073
      bool             finish = false;
×
2074
      code = taos_stmt2_bind_param(stmt, &bindv, -1);
×
2075

2076
      checkError(stmt, code);
×
2077

2078
      // exec
2079
      code = taos_stmt2_exec(stmt, NULL);
×
2080
      checkError(stmt, code);
×
2081
    }
2082
  }
2083

2084
  // case 4 : bind_a->close
2085
  {
2086
    printf("case 4 : bind_a->close\n");
×
2087
    // bind
2088
    TAOS_STMT2_BINDV bindv = {CTB_NUMS, tbs, NULL, paramv};
×
2089
    bool             finish = false;
×
2090
    code = taos_stmt2_bind_param_a(stmt, &bindv, -1, stmtAsyncBindCb, (void*)&finish);
×
2091
    checkError(stmt, code);
×
2092
    taos_stmt2_close(stmt);
×
2093
    checkError(stmt, code);
×
2094
  }
2095

2096
  // case 5 : bind_a->exec_a->close
2097
  {
2098
    printf("case 5 : bind_a->exec_a->close\n");
×
2099
    // init
2100
    TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
×
2101
    ASSERT_NE(stmt, nullptr);
×
2102
    int code = taos_stmt2_prepare(stmt, sql, 0);
×
2103
    checkError(stmt, code);
×
2104
    // bind
2105
    TAOS_STMT2_BINDV bindv = {CTB_NUMS, tbs, NULL, paramv};
×
2106
    bool             finish = false;
×
2107
    code = taos_stmt2_bind_param_a(stmt, &bindv, -1, stmtAsyncBindCb, (void*)&finish);
×
2108
    checkError(stmt, code);
×
2109
    // exec
2110
    code = taos_stmt2_exec(stmt, NULL);
×
2111
    checkError(stmt, code);
×
2112
    // close
2113
    taos_stmt2_close(stmt);
×
2114
    checkError(stmt, code);
×
2115
  }
2116

2117
  option = {0, false, false, NULL, NULL};
×
2118
  stmt = taos_stmt2_init(taos, &option);
×
2119
  ASSERT_NE(stmt, nullptr);
×
2120
  code = taos_stmt2_prepare(stmt, sql, 0);
×
2121
  checkError(stmt, code);
×
2122

2123
  // case 6 : bind_a->exec->bind_a->exec->...
2124
  {
2125
    printf("case 6 : bind_a->exec->bind_a->exec->...\n");
×
2126
    // init
2127

2128
    checkError(stmt, code);
×
2129
    for (int r = 0; r < CYC_NUMS; r++) {
×
2130
      // bind
2131
      TAOS_STMT2_BINDV bindv = {CTB_NUMS, tbs, NULL, paramv};
×
2132
      bool             finish = false;
×
2133
      code = taos_stmt2_bind_param_a(stmt, &bindv, -1, stmtAsyncBindCb, (void*)&finish);
×
2134
      checkError(stmt, code);
×
2135
      // exec
2136
      code = taos_stmt2_exec(stmt, NULL);
×
2137
      checkError(stmt, code);
×
2138
    }
2139
  }
2140

2141
  // case 7 (error:no wait error) : bind_a->bind_a
2142
  {
2143
    printf("case 7 (error:no wait error) : bind_a->bind_a\n");
×
2144
    // bind
2145
    TAOS_STMT2_BINDV bindv = {CTB_NUMS, tbs, NULL, paramv};
×
2146
    bool             finish = false;
×
2147
    code = taos_stmt2_bind_param_a(stmt, &bindv, -1, stmtAsyncBindCb2, (void*)&finish);
×
2148
    checkError(stmt, code);
×
2149
    taosMsleep(200);
×
2150
    code = taos_stmt2_bind_param_a(stmt, &bindv, -1, stmtAsyncBindCb2, (void*)&finish);
×
2151
    ASSERT_EQ(code, TSDB_CODE_TSC_STMT_API_ERROR);
×
2152
    while (!finish) {
×
2153
      taosMsleep(100);
×
2154
    }
2155
  }
2156
  // close
2157
  taos_stmt2_close(stmt);
×
2158

2159
  // free memory
2160
  for (int i = 0; i < CTB_NUMS; i++) {
×
2161
    taosMemoryFree(paramv[i]);
×
2162
    taosMemoryFree(ts[i]);
×
2163
    taosMemoryFree(b[i]);
×
2164
  }
2165
  taosMemoryFree(ts);
×
2166
  taosMemoryFree(b);
×
2167
  taosMemoryFree(ts_len);
×
2168
  taosMemoryFree(b_len);
×
2169
  taosMemoryFree(paramv);
×
2170
  for (int i = 0; i < CTB_NUMS; i++) {
×
2171
    taosMemoryFree(tbs[i]);
×
2172
  }
2173
  taosMemoryFree(tbs);
×
2174
  stop_task = true;
×
2175
}
2176

2177
// TEST(stmt2Case, async_order) {
2178
//   std::atomic<bool> stop_task(false);
2179
//   std::thread       t(stmt2_async_test, std::ref(stop_task));
2180

2181
//   // 等待 60 秒钟
2182
//   auto start_time = std::chrono::steady_clock::now();
2183
//   while (!stop_task) {
2184
//     auto elapsed_time = std::chrono::steady_clock::now() - start_time;
2185
//     if (std::chrono::duration_cast<std::chrono::seconds>(elapsed_time).count() > 100) {
2186
//       if (t.joinable()) {
2187
//         t.detach();
2188
//       }
2189
//       FAIL() << "Test[stmt2_async_test] timed out";
2190
//       break;
2191
//     }
2192
//     std::this_thread::sleep_for(std::chrono::seconds(1));  // 每 1s 检查一次
2193
//   }
2194
//   if (t.joinable()) {
2195
//     t.join();
2196
//   }
2197
// }
2198

2199
TEST(stmt2Case, rowformat_bind) {
4✔
2200
  TAOS* taos = taos_connect("localhost", "root", "taosdata", "", 0);
1!
2201
  ASSERT_NE(taos, nullptr);
1!
2202

2203
  do_query(taos, "drop database if exists stmt2_testdb_16");
1!
2204
  do_query(taos, "create database IF NOT EXISTS stmt2_testdb_16");
1!
2205
  do_query(
1!
2206
      taos,
2207
      "create stable stmt2_testdb_16.stb(ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 binary(8), c6 "
2208
      "smallint, c7 "
2209
      "tinyint, c8 bool, c9 nchar(8), c10 geometry(256))TAGS(tts timestamp, t1 int, t2 bigint, t3 float, t4 double, t5 "
2210
      "binary(8), t6 smallint, t7 tinyint, t8 bool, t9 nchar(8), t10 geometry(256))");
2211

2212
  TAOS_STMT2_OPTION option = {0};
1✔
2213
  TAOS_STMT2*       stmt = taos_stmt2_init(taos, &option);
1!
2214
  ASSERT_NE(stmt, nullptr);
1!
2215
  int       code = 0;
1✔
2216
  uintptr_t c10len = 0;
1✔
2217
  struct {
2218
    int64_t       c1;
2219
    int32_t       c2;
2220
    int64_t       c3;
2221
    float         c4;
2222
    double        c5;
2223
    unsigned char c6[8];
2224
    int16_t       c7;
2225
    int8_t        c8;
2226
    int8_t        c9;
2227
    char          c10[32];
2228
  } v = {1591060628000, 1, 2, 3.0, 4.0, "abcdef", 5, 6, 7, "ijnop"};
1✔
2229

2230
  struct {
2231
    int32_t c1;
2232
    int32_t c2;
2233
    int32_t c3;
2234
    int32_t c4;
2235
    int32_t c5;
2236
    int32_t c6;
2237
    int32_t c7;
2238
    int32_t c8;
2239
    int32_t c9;
2240
    int32_t c10;
2241
  } v_len = {sizeof(int64_t), sizeof(int32_t),
1✔
2242
             sizeof(int64_t), sizeof(float),
2243
             sizeof(double),  8,
2244
             sizeof(int16_t), sizeof(int8_t),
2245
             sizeof(int8_t),  8};
2246
  TAOS_STMT2_BIND params[11];
2247
  params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
1✔
2248
  params[0].length = (int32_t*)&v_len.c1;
1✔
2249
  params[0].buffer = &v.c1;
1✔
2250
  params[0].is_null = NULL;
1✔
2251
  params[0].num = 1;
1✔
2252

2253
  params[1].buffer_type = TSDB_DATA_TYPE_INT;
1✔
2254
  params[1].buffer = &v.c2;
1✔
2255
  params[1].length = (int32_t*)&v_len.c2;
1✔
2256
  params[1].is_null = NULL;
1✔
2257
  params[1].num = 1;
1✔
2258

2259
  params[2].buffer_type = TSDB_DATA_TYPE_BIGINT;
1✔
2260
  params[2].buffer = &v.c3;
1✔
2261
  params[2].length = (int32_t*)&v_len.c3;
1✔
2262
  params[2].is_null = NULL;
1✔
2263
  params[2].num = 1;
1✔
2264

2265
  params[3].buffer_type = TSDB_DATA_TYPE_FLOAT;
1✔
2266
  params[3].buffer = &v.c4;
1✔
2267
  params[3].length = (int32_t*)&v_len.c4;
1✔
2268
  params[3].is_null = NULL;
1✔
2269
  params[3].num = 1;
1✔
2270

2271
  params[4].buffer_type = TSDB_DATA_TYPE_DOUBLE;
1✔
2272
  params[4].buffer = &v.c5;
1✔
2273
  params[4].length = (int32_t*)&v_len.c5;
1✔
2274
  params[4].is_null = NULL;
1✔
2275
  params[4].num = 1;
1✔
2276

2277
  params[5].buffer_type = TSDB_DATA_TYPE_BINARY;
1✔
2278
  params[5].buffer = &v.c6;
1✔
2279
  params[5].length = (int32_t*)&v_len.c6;
1✔
2280
  params[5].is_null = NULL;
1✔
2281
  params[5].num = 1;
1✔
2282

2283
  params[6].buffer_type = TSDB_DATA_TYPE_SMALLINT;
1✔
2284
  params[6].buffer = &v.c7;
1✔
2285
  params[6].length = (int32_t*)&v_len.c7;
1✔
2286
  params[6].is_null = NULL;
1✔
2287
  params[6].num = 1;
1✔
2288

2289
  params[7].buffer_type = TSDB_DATA_TYPE_TINYINT;
1✔
2290
  params[7].buffer = &v.c8;
1✔
2291
  params[7].length = (int32_t*)&v_len.c8;
1✔
2292
  params[7].is_null = NULL;
1✔
2293
  params[7].num = 1;
1✔
2294

2295
  params[8].buffer_type = TSDB_DATA_TYPE_BOOL;
1✔
2296
  params[8].buffer = &v.c9;
1✔
2297
  params[8].length = (int32_t*)&v_len.c9;
1✔
2298
  params[8].is_null = NULL;
1✔
2299
  params[8].num = 1;
1✔
2300

2301
  params[9].buffer_type = TSDB_DATA_TYPE_NCHAR;
1✔
2302
  params[9].buffer = &v.c10;
1✔
2303
  params[9].length = (int32_t*)&v_len.c10;
1✔
2304
  params[9].is_null = NULL;
1✔
2305
  params[9].num = 1;
1✔
2306

2307
  unsigned char* outputGeom1;
2308
  size_t         size1;
2309
  initCtxMakePoint();
1!
2310
  code = doMakePoint(1.000, 2.000, &outputGeom1, &size1);
1!
2311
  checkError(stmt, code);
1!
2312
  params[10].buffer_type = TSDB_DATA_TYPE_GEOMETRY;
1✔
2313
  params[10].buffer = outputGeom1;
1✔
2314
  params[10].length = (int32_t*)&size1;
1✔
2315
  params[10].is_null = NULL;
1✔
2316
  params[10].num = 1;
1✔
2317

2318
  char* stmt_sql = "insert into stmt2_testdb_16.? using stb tags(?,?,?,?,?,?,?,?,?,?,?)values (?,?,?,?,?,?,?,?,?,?,?)";
1✔
2319
  code = taos_stmt2_prepare(stmt, stmt_sql, 0);
1!
2320
  checkError(stmt, code);
1!
2321

2322
  char*            tbname[1] = {"tb1"};
1✔
2323
  TAOS_STMT2_BIND* tags = &params[0];
1✔
2324
  TAOS_STMT2_BIND* cols = &params[0];
1✔
2325
  TAOS_STMT2_BINDV bindv = {1, &tbname[0], &tags, &cols};
1✔
2326
  code = taos_stmt2_bind_param(stmt, &bindv, -2);
1!
2327
  checkError(stmt, code);
1!
2328

2329
  int affected_rows;
2330
  code = taos_stmt2_exec(stmt, &affected_rows);
1!
2331
  checkError(stmt, code);
1!
2332
  ASSERT_EQ(affected_rows, 1);
1!
2333

2334
  int64_t ts2 = 1591060628000;
1✔
2335
  params[0].buffer = &ts2;
1✔
2336
  code = taos_stmt2_bind_param(stmt, &bindv, -2);
1!
2337
  checkError(stmt, code);
1!
2338

2339
  code = taos_stmt2_exec(stmt, &affected_rows);
1!
2340
  checkError(stmt, code);
1!
2341
  ASSERT_EQ(affected_rows, 1);
1!
2342

2343
  params[0].buffer = &ts2;
1✔
2344
  code = taos_stmt2_bind_param(stmt, &bindv, -1);
1!
2345
  ASSERT_EQ(code, TSDB_CODE_TSC_STMT_API_ERROR);
1!
2346

2347
  geosFreeBuffer(outputGeom1);
1!
2348
  taos_stmt2_close(stmt);
1!
2349
  do_query(taos, "drop database if exists stmt2_testdb_16");
1!
2350
  taos_close(taos);
1!
2351
}
2352

2353
#pragma GCC diagnostic pop
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc