batchprepare.c 89.1 KB
Newer Older
1 2 3 4 5 6 7
// TAOS standard API example. The same syntax as MySQL, but only a subet 
// to compile: gcc -o prepare prepare.c -ltaos

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
D
stmt  
dapan1121 已提交
8
#include <pthread.h>
9 10 11
#include <unistd.h>
#include "../../../include/client/taos.h"

D
dapan1121 已提交
12
#define FUNCTION_TEST_IDX 1
D
dapan1121 已提交
13 14 15
#define TIME_PRECISION_MILLI   0
#define TIME_PRECISION_MICRO   1
#define TIME_PRECISION_NANO    2
D
dapan1121 已提交
16

D
stmt  
dapan1121 已提交
17 18
int32_t shortColList[] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_INT};
int32_t fullColList[] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_BOOL, TSDB_DATA_TYPE_TINYINT, TSDB_DATA_TYPE_UTINYINT, TSDB_DATA_TYPE_SMALLINT, TSDB_DATA_TYPE_USMALLINT, TSDB_DATA_TYPE_INT, TSDB_DATA_TYPE_UINT, TSDB_DATA_TYPE_BIGINT, TSDB_DATA_TYPE_UBIGINT, TSDB_DATA_TYPE_FLOAT, TSDB_DATA_TYPE_DOUBLE, TSDB_DATA_TYPE_BINARY, TSDB_DATA_TYPE_NCHAR};
D
dapan1121 已提交
19 20
int32_t bindColTypeList[] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_NCHAR};
int32_t optrIdxList[] = {5, 11};
D
dapan1121 已提交
21 22 23 24 25 26 27

typedef struct {
  char*   oper;
  int32_t paramNum;
  bool    enclose;
} OperInfo;

D
dapan1121 已提交
28 29 30 31 32
typedef struct {
  char*   funcName;
  int32_t paramNum;
} FuncInfo;

D
dapan1121 已提交
33 34 35 36 37
typedef enum {
  BP_BIND_TAG = 1,
  BP_BIND_COL,
} BP_BIND_TYPE;

D
dapan1121 已提交
38 39
#define BP_BIND_TYPE_STR(t) (((t) == BP_BIND_COL) ? "column" : "tag")

D
dapan1121 已提交
40 41 42 43 44 45 46 47 48 49 50 51 52
OperInfo operInfo[] = {
  {">",        2, false},
  {">=",       2, false},  
  {"<",        2, false},
  {"<=",       2, false},  
  {"=",        2, false},  
  {"<>",       2, false},  
  {"in",       2, true},  
  {"not in",   2, true},  
  
  {"like",     2, false},  
  {"not like", 2, false},  
  {"match",    2, false},  
D
dapan1121 已提交
53
  {"nmatch",   2, false},  
D
dapan1121 已提交
54 55 56 57 58
};

int32_t operatorList[] = {0, 1, 2, 3, 4, 5, 6, 7};
int32_t varoperatorList[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};

D
dapan1121 已提交
59 60 61 62 63 64
FuncInfo funcInfo[] = {
  {"count", 1},
  {"sum",   1},
  {"min",   1},
};

D
dapan1121 已提交
65 66
#define BP_STARTUP_TS 1591060628000

D
dapan1121 已提交
67 68
char *bpStbPrefix = "st";
char *bpTbPrefix = "t";
D
dapan1121 已提交
69
int32_t bpDefaultStbId = 1;
D
dapan1121 已提交
70
int64_t bpTs;
D
dapan1121 已提交
71 72 73

//char *operatorList[] = {">", ">=", "<", "<=", "=", "<>", "in", "not in"};
//char *varoperatorList[] = {">", ">=", "<", "<=", "=", "<>", "in", "not in", "like", "not like", "match", "nmatch"};
D
stmt  
dapan1121 已提交
74 75

#define tListLen(x) (sizeof(x) / sizeof((x)[0]))
D
dapan1121 已提交
76 77 78 79
#define IS_SIGNED_NUMERIC_TYPE(_t)   ((_t) >= TSDB_DATA_TYPE_TINYINT && (_t) <= TSDB_DATA_TYPE_BIGINT)
#define IS_UNSIGNED_NUMERIC_TYPE(_t) ((_t) >= TSDB_DATA_TYPE_UTINYINT && (_t) <= TSDB_DATA_TYPE_UBIGINT)
#define IS_FLOAT_TYPE(_t)            ((_t) == TSDB_DATA_TYPE_FLOAT || (_t) == TSDB_DATA_TYPE_DOUBLE)
#define IS_NUMERIC_TYPE(_t) ((IS_SIGNED_NUMERIC_TYPE(_t)) || (IS_UNSIGNED_NUMERIC_TYPE(_t)) || (IS_FLOAT_TYPE(_t)))
D
stmt  
dapan1121 已提交
80

81
typedef struct {
D
dapan1121 已提交
82 83 84
  bool       singleTbInsert;
  int32_t    singleTbIdx;
  
D
stmt  
dapan1121 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
  int64_t*   tsData;
  bool*      boolData;
  int8_t*    tinyData;
  uint8_t*   utinyData;
  int16_t*   smallData;
  uint16_t*  usmallData;
  int32_t*   intData;
  uint32_t*  uintData;
  int64_t*   bigData;
  uint64_t*  ubigData;
  float*     floatData;
  double*    doubleData;
  char*      binaryData;
  char*      isNull;
  int32_t*   binaryLen;
D
dapan1121 已提交
100
  TAOS_MULTI_BIND* pBind;
D
dapan1121 已提交
101
  TAOS_MULTI_BIND* pTags;
D
stmt  
dapan1121 已提交
102 103 104 105 106 107 108 109
  char*         sql;
  int32_t*      colTypes;
  int32_t       colNum;
} BindData;

int32_t gVarCharSize = 10;
int32_t gVarCharLen = 5;

D
stmt  
dapan1121 已提交
110
int32_t gExecLoopTimes = 1; // no change
D
stmt  
dapan1121 已提交
111
int32_t gFullColNum = tListLen(fullColList);
D
stmt  
dapan1121 已提交
112

D
dapan1121 已提交
113 114 115 116 117 118 119
int insertMBSETest1(TAOS_STMT *stmt, TAOS *taos);
int insertMBSETest2(TAOS_STMT *stmt, TAOS *taos);
int insertMBMETest1(TAOS_STMT *stmt, TAOS *taos);
int insertMBMETest2(TAOS_STMT *stmt, TAOS *taos);
int insertMBMETest3(TAOS_STMT *stmt, TAOS *taos);
int insertMBMETest4(TAOS_STMT *stmt, TAOS *taos);
int insertMPMETest1(TAOS_STMT *stmt, TAOS *taos);
D
dapan1121 已提交
120
int insertAUTOTest1(TAOS_STMT *stmt, TAOS *taos);
121
int insertAUTOTest2(TAOS_STMT *stmt, TAOS *taos);
D
dapan1121 已提交
122
int insertAUTOTest3(TAOS_STMT *stmt, TAOS *taos);
D
fix bug  
dapan1121 已提交
123 124
int queryColumnTest(TAOS_STMT *stmt, TAOS *taos);
int queryMiscTest(TAOS_STMT *stmt, TAOS *taos);
D
dapan1121 已提交
125
int insertNonExistsTb(TAOS_STMT *stmt, TAOS *taos);
D
dapan1121 已提交
126
int insertVarLenErr(TAOS_STMT *stmt, TAOS *taos);
D
dapan1121 已提交
127 128 129

enum {
  TTYPE_INSERT = 1,
D
dapan1121 已提交
130
  TTYPE_INSERT_NG,
D
dapan1121 已提交
131 132
  TTYPE_QUERY,
};
D
stmt  
dapan1121 已提交
133 134 135 136

typedef struct {
  char     caseDesc[128];
  int32_t  colNum;
D
stmt  
dapan1121 已提交
137
  int32_t *colList;         // full table column list
D
dapan1121 已提交
138
  int32_t  testType;     
139
  int32_t  autoCreateTbl;
D
dapan1121 已提交
140
  bool     duplicateValue;
D
stmt  
dapan1121 已提交
141
  bool     fullCol;
D
dapan1121 已提交
142
  int32_t  (*runFn)(TAOS_STMT*, TAOS*);
D
stmt  
dapan1121 已提交
143 144 145
  int32_t  tblNum;
  int32_t  rowNum;
  int32_t  bindRowNum;
D
stmt  
dapan1121 已提交
146
  int32_t  bindColNum;      // equal colNum in full column case
D
dapan1121 已提交
147
  int32_t  bindTagNum;      // equal colNum in full column case
D
stmt  
dapan1121 已提交
148 149
  int32_t  bindNullNum;
  int32_t  runTimes;
D
dapan1121 已提交
150
  int32_t  preCaseIdx;
D
stmt  
dapan1121 已提交
151 152 153
} CaseCfg;

CaseCfg gCase[] = {
D
dapan1121 已提交
154 155
  {"insert:MBSE0-FULL", tListLen(shortColList), shortColList, TTYPE_INSERT, 0, false, true, insertMBSETest1,  1, 10, 10, 0, 0, 0, 1, -1},
  {"insert:MBSE0-FULL", tListLen(shortColList), shortColList, TTYPE_INSERT, 0, false, true, insertMBSETest1, 10, 100, 10, 0, 0, 0, 1, -1},
D
dapan1121 已提交
156

D
dapan1121 已提交
157 158 159
  {"insert:MBSE1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, true, insertMBSETest1, 10, 10, 2, 0, 0, 0, 1, -1},
  {"insert:MBSE1-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, false, insertMBSETest1, 10, 10, 2, 12, 0, 0, 1, -1},
  {"insert:MBSE1-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, false, insertMBSETest1, 10, 10, 2, 2, 0, 0, 1, -1},
D
dapan1121 已提交
160

D
dapan1121 已提交
161 162 163
  {"insert:MBSE2-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, true, insertMBSETest2, 10, 10, 2, 0, 0, 0, 1, -1},
  {"insert:MBSE2-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, false, insertMBSETest2, 10, 10, 2, 12, 0, 0, 1, -1},
  {"insert:MBSE2-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, false, insertMBSETest2, 10, 10, 2, 2, 0, 0, 1, -1},
D
stmt  
dapan1121 已提交
164

D
dapan1121 已提交
165 166 167
  {"insert:MBME1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, true, insertMBMETest1, 10, 10, 2, 0, 0, 0, 1, -1},
  {"insert:MBME1-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, false, insertMBMETest1, 10, 10, 2, 12, 0, 0, 1, -1},
  {"insert:MBME1-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, false, insertMBMETest1, 10, 10, 2, 2, 0, 0, 1, -1},
D
stmt  
dapan1121 已提交
168

D
dapan1121 已提交
169
  // 11
D
dapan1121 已提交
170 171 172
  {"insert:MBME2-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, true, insertMBMETest2, 10, 10, 2, 0, 0, 0, 1, -1},
  {"insert:MBME2-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, false, insertMBMETest2, 10, 10, 2, 12, 0, 0, 1, -1},
  {"insert:MBME2-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, false, insertMBMETest2, 10, 10, 2, 2, 0, 0, 1, -1},
D
stmt  
dapan1121 已提交
173

D
dapan1121 已提交
174 175 176
  {"insert:MBME3-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, true, insertMBMETest3, 10, 10, 2, 0, 0, 0, 1, -1},
  {"insert:MBME3-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, false, insertMBMETest3, 10, 10, 2, 12, 0, 0, 1, -1},
  {"insert:MBME3-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, false, insertMBMETest3, 10, 10, 2, 2, 0, 0, 1, -1},
D
stmt  
dapan1121 已提交
177

D
dapan1121 已提交
178 179 180
  {"insert:MBME4-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, true, insertMBMETest4, 10, 10, 2, 0, 0, 0, 1, -1},
  {"insert:MBME4-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, false, insertMBMETest4, 10, 10, 2, 12, 0, 0, 1, -1},
  {"insert:MBME4-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, false, insertMBMETest4, 10, 10, 2, 2, 0, 0, 1, -1},
D
stmt  
dapan1121 已提交
181

D
dapan1121 已提交
182 183
  {"insert:MPME1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, true, insertMPMETest1, 10, 10, 2, 0, 0, 0, 1, -1},
  {"insert:MPME1-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, false, false, insertMPMETest1, 10, 10, 2, 12, 0, 0, 1, -1},
D
stmt  
dapan1121 已提交
184

D
dapan1121 已提交
185
  // 22
D
dapan1121 已提交
186 187 188
  {"insert:AUTO1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, 1, false, true, insertAUTOTest1, 10, 10, 2, 0, 0, 0, 1, -1},
  {"insert:AUTO2-TBEXISTS", tListLen(fullColList), fullColList, TTYPE_INSERT, 3, false, true, insertAUTOTest2, 10, 10, 2, 0, 0, 0, 1, -1},
//  {"insert:AUTO3-NTB", tListLen(fullColList), fullColList, TTYPE_INSERT, 0, true, true, insertAUTOTest3, 10, 10, 2, 0, 0, 0, 1, -1},
D
dapan1121 已提交
189

D
dapan1121 已提交
190 191
  {"query:SUBT-COLUMN", tListLen(fullColList), fullColList, TTYPE_QUERY, 0, false, false, queryColumnTest, 10, 10, 1, 3, 0, 0, 1, 2},
  {"query:SUBT-MISC",   tListLen(fullColList), fullColList, TTYPE_QUERY, 0, false, false, queryMiscTest, 10, 10, 1, 3, 0, 0, 1, 2},
D
dapan1121 已提交
192

D
dapan1121 已提交
193
  {"query:NG-TBNEXISTS",tListLen(fullColList), fullColList, TTYPE_INSERT_NG,0, false, false, insertNonExistsTb, 10, 10, 1, 3, 0, 0, 1, -1},
D
dapan1121 已提交
194
  {"query:NG-VARLENERR",tListLen(fullColList), fullColList, TTYPE_INSERT_NG,0, false, true, insertVarLenErr, 10, 10, 1, 3, 0, 0, 1, -1},
D
dapan1121 已提交
195

D
dapan1121 已提交
196 197
//  {"query:SUBT-COLUMN", tListLen(fullColList), fullColList, TTYPE_QUERY, 0, false, false, queryColumnTest, 1, 10, 1, 1, 0, 0, 1, 2},
//  {"query:SUBT-MISC",   tListLen(fullColList), fullColList, TTYPE_QUERY, 0, false, false, queryMiscTest, 2, 10, 1, 1, 0, 0, 1, 2},
D
stmt  
dapan1121 已提交
198

D
stmt  
dapan1121 已提交
199 200 201
};

CaseCfg *gCurCase = NULL;
D
stmt  
dapan1121 已提交
202 203

typedef struct {
D
dapan1121 已提交
204
  char     caseCatalog[255];
D
stmt  
dapan1121 已提交
205 206
  int32_t  bindNullNum;
  bool     checkParamNum;
D
stmt  
dapan1121 已提交
207
  bool     printRes;
D
stmt  
dapan1121 已提交
208
  bool     printCreateTblSql;
D
dapan1121 已提交
209 210
  bool     printQuerySql;
  bool     printStmtSql;
D
dapan1121 已提交
211
  bool     printVerbose;
D
dapan 已提交
212
  bool     autoCreateTbl;
D
dapan1121 已提交
213
  bool     numericParam;
D
dapan1121 已提交
214
  uint8_t  precision;
D
stmt  
dapan1121 已提交
215
  int32_t  rowNum;               //row num for one table
D
stmt  
dapan1121 已提交
216
  int32_t  bindColNum;
D
dapan1121 已提交
217
  int32_t  bindTagNum;
D
stmt  
dapan1121 已提交
218
  int32_t  bindRowNum;           //row num for once bind
D
stmt  
dapan1121 已提交
219 220
  int32_t  bindColTypeNum;
  int32_t* bindColTypeList;
D
dapan1121 已提交
221 222
  int32_t  bindTagTypeNum;
  int32_t* bindTagTypeList;
D
dapan1121 已提交
223 224
  int32_t  optrIdxListNum;
  int32_t* optrIdxList;
D
dapan1121 已提交
225 226
  int32_t  funcIdxListNum;
  int32_t* funcIdxList;
D
stmt  
dapan1121 已提交
227
  int32_t  runTimes;
D
dapan1121 已提交
228 229 230 231
  int32_t  caseIdx;              // static case idx
  int32_t  caseNum;              // num in static case list
  int32_t  caseRunIdx;           // runtime case idx
  int32_t  caseRunNum;           // total run case num
D
stmt  
dapan1121 已提交
232 233
} CaseCtrl;

D
dapan1121 已提交
234
#if 0
D
dapan1121 已提交
235
CaseCtrl gCaseCtrl = {
D
dapan1121 已提交
236
  .precision = TIME_PRECISION_MICRO,
D
dapan1121 已提交
237
  .bindNullNum = 0,
238
  .printCreateTblSql = true,
D
dapan1121 已提交
239 240
  .printQuerySql = true,
  .printStmtSql = true,
D
dapan1121 已提交
241 242
  .printVerbose = true,
  .printRes = true,
D
dapan 已提交
243
  .autoCreateTbl = false,
D
dapan1121 已提交
244
  .numericParam = false,
D
dapan 已提交
245 246
  .rowNum = 0,
  .bindColNum = 0,
D
dapan1121 已提交
247
  .bindTagNum = 0,
D
dapan 已提交
248 249 250 251 252 253 254
  .bindRowNum = 0,
  .bindColTypeNum = 0,
  .bindColTypeList = NULL,
  .bindTagTypeNum = 0,
  .bindTagTypeList = NULL,
  .optrIdxListNum = 0,
  .optrIdxList = NULL,
D
dapan1121 已提交
255 256
  .funcIdxListNum = 0,
  .funcIdxList = NULL,
D
dapan 已提交
257 258
  .checkParamNum = false,
  .runTimes = 0,
D
dapan1121 已提交
259
  .caseIdx = 26,
260
  .caseNum = 1,
D
dapan 已提交
261 262 263 264 265 266
  .caseRunIdx = -1,
  .caseRunNum = -1,
};
#endif


D
dapan1121 已提交
267
#if 1
D
dapan1121 已提交
268
CaseCtrl gCaseCtrl = {  // default
D
dapan1121 已提交
269
  .precision = TIME_PRECISION_MILLI,
D
dapan 已提交
270
  .bindNullNum = 0,
D
dapan1121 已提交
271
  .printCreateTblSql = false,
D
dapan 已提交
272 273
  .printQuerySql = true,
  .printStmtSql = true,
D
dapan1121 已提交
274 275
  .printVerbose = false,
  .printRes = true,
D
dapan 已提交
276
  .autoCreateTbl = false,
D
dapan1121 已提交
277
  .numericParam = false,
D
dapan1121 已提交
278 279
  .rowNum = 0,
  .bindColNum = 0,
D
dapan1121 已提交
280
  .bindTagNum = 0,
D
dapan1121 已提交
281
  .bindRowNum = 0,
D
dapan1121 已提交
282 283
  .bindColTypeNum = 0,
  .bindColTypeList = NULL,
D
dapan1121 已提交
284 285
  .bindTagTypeNum = 0,
  .bindTagTypeList = NULL,
D
dapan1121 已提交
286 287 288 289
  .optrIdxListNum = 0,
  .optrIdxList = NULL,
  .funcIdxListNum = 0,
  .funcIdxList = NULL,
D
dapan1121 已提交
290 291
  .checkParamNum = false,
  .runTimes = 0,
D
dapan1121 已提交
292 293
  .caseIdx = -1,
  .caseNum = -1,
D
dapan1121 已提交
294
  .caseRunIdx = -1,
D
dapan1121 已提交
295
  .caseRunNum = -1,
D
dapan1121 已提交
296 297
};
#endif
D
dapan1121 已提交
298

D
dapan1121 已提交
299
#if 0
D
dapan1121 已提交
300
CaseCtrl gCaseCtrl = {  // query case with specified col&oper
D
dapan1121 已提交
301
  .bindNullNum = 1,
D
dapan1121 已提交
302 303 304 305 306 307
  .printCreateTblSql = false,
  .printQuerySql = true,
  .printStmtSql = true,
  .rowNum = 0,
  .bindColNum = 0,
  .bindRowNum = 0,
D
dapan1121 已提交
308 309 310 311
  .optrIdxListNum = tListLen(optrIdxList),
  .optrIdxList = optrIdxList,
  .bindColTypeNum = tListLen(bindColTypeList),
  .bindColTypeList = bindColTypeList,
D
dapan1121 已提交
312
  .checkParamNum = false,
D
dapan1121 已提交
313
  .printRes = true,
D
dapan1121 已提交
314 315
  .runTimes = 0,
  .caseRunIdx = -1,
D
dapan1121 已提交
316
  .caseIdx = 5,
D
dapan1121 已提交
317 318 319
  .caseNum = 1,
  .caseRunNum = 1,
};
D
dapan1121 已提交
320 321
#endif

D
dapan 已提交
322
#if 0
D
dapan1121 已提交
323
CaseCtrl gCaseCtrl = {  // query case with specified col&oper
D
dapan1121 已提交
324
  .bindNullNum = 0,
D
dapan1121 已提交
325
  .printCreateTblSql = true,
D
dapan1121 已提交
326 327
  .printQuerySql = true,
  .printStmtSql = true,
D
dapan 已提交
328
  .autoCreateTbl = true,
D
stmt  
dapan1121 已提交
329
  .rowNum = 0,
D
stmt  
dapan1121 已提交
330
  .bindColNum = 0,
D
dapan 已提交
331
  .bindTagNum = 0,
D
stmt  
dapan1121 已提交
332
  .bindRowNum = 0,
D
dapan1121 已提交
333
  .bindColTypeNum = 0,
D
dapan1121 已提交
334
  .bindColTypeList = bindColTypeList,
D
dapan1121 已提交
335
  .optrIdxListNum = 0,
D
dapan1121 已提交
336
  .optrIdxList = optrIdxList,
D
fix bug  
dapan1121 已提交
337
  .checkParamNum = false,
D
stmt  
dapan1121 已提交
338 339
  .printRes = true,
  .runTimes = 0,
D
dapan1121 已提交
340
  .caseRunIdx = -1,
D
dapan1121 已提交
341 342 343 344 345 346
  .optrIdxListNum = tListLen(optrIdxList),
  .optrIdxList = optrIdxList,
  .bindColTypeNum = tListLen(bindColTypeList),
  .bindColTypeList = bindColTypeList,
  .caseRunIdx = -1,
  .caseIdx = 24,
D
dapan1121 已提交
347
  .caseNum = 1,
D
dapan1121 已提交
348
  .caseRunNum = 1,
D
stmt  
dapan1121 已提交
349
};
D
dapan1121 已提交
350 351
#endif

D
stmt  
dapan1121 已提交
352 353
int32_t taosGetTimeOfDay(struct timeval *tv) {
  return gettimeofday(tv, NULL);
354
}
D
stmt  
dapan1121 已提交
355
void *taosMemoryMalloc(uint64_t size) {
D
stmt  
dapan1121 已提交
356 357 358
  return malloc(size);
}

D
stmt  
dapan1121 已提交
359 360 361 362 363
void *taosMemoryCalloc(int32_t num, int32_t size) {
  return calloc(num, size);
}
void taosMemoryFree(const void *ptr) {
  if (ptr == NULL) return;
364

D
stmt  
dapan1121 已提交
365 366
  return free((void*)ptr);
}
367

D
stmt  
dapan1121 已提交
368 369 370
static int64_t taosGetTimestampMs() {
  struct timeval systemTime;
  taosGetTimeOfDay(&systemTime);
wafwerar's avatar
wafwerar 已提交
371
  return (int64_t)systemTime.tv_sec * 1000LL + (int64_t)systemTime.tv_usec/1000;
D
stmt  
dapan1121 已提交
372 373
}

D
stmt  
dapan1121 已提交
374 375 376
static int64_t taosGetTimestampUs() {
  struct timeval systemTime;
  taosGetTimeOfDay(&systemTime);
wafwerar's avatar
wafwerar 已提交
377
  return (int64_t)systemTime.tv_sec * 1000000LL + (int64_t)systemTime.tv_usec;
D
stmt  
dapan1121 已提交
378
}
379

D
dapan1121 已提交
380
bool colExists(TAOS_MULTI_BIND* pBind, int32_t dataType) {
D
stmt  
dapan1121 已提交
381 382 383 384 385 386 387 388 389
  int32_t i = 0;
  while (true) {
    if (0 == pBind[i].buffer_type) {
      return false;
    }

    if (pBind[i].buffer_type == dataType) {
      return true;
    }
D
stmt  
dapan1121 已提交
390

D
stmt  
dapan1121 已提交
391 392 393 394
    ++i;
  }
}

D
stmt  
dapan1121 已提交
395
void generateInsertSQL(BindData *data) {
D
dapan1121 已提交
396 397
  int32_t len = 0;
  if (gCurCase->tblNum > 1) {
D
dapan1121 已提交
398 399 400 401 402
    if (data->singleTbInsert) {
      len = sprintf(data->sql, "insert into %s%d ", bpTbPrefix, data->singleTbIdx);
    } else {
      len = sprintf(data->sql, "insert into ? ");
    }
D
dapan1121 已提交
403 404 405
  } else {
    len = sprintf(data->sql, "insert into %s0 ", bpTbPrefix);
  }
D
dapan1121 已提交
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458

  if (gCurCase->bindTagNum > 0) {
    len += sprintf(data->sql + len, "using %s%d ", bpStbPrefix, bpDefaultStbId);

    if (!gCurCase->fullCol) {
      len += sprintf(data->sql + len, "(");
      for (int c = 0; c < gCurCase->bindTagNum; ++c) {
        if (c) {
          len += sprintf(data->sql + len, ",");
        }
        switch (data->pTags[c].buffer_type) {  
          case TSDB_DATA_TYPE_BOOL:
            len += sprintf(data->sql + len, "tbooldata");
            break;
          case TSDB_DATA_TYPE_TINYINT:
            len += sprintf(data->sql + len, "ttinydata");
            break;
          case TSDB_DATA_TYPE_SMALLINT:
            len += sprintf(data->sql + len, "tsmalldata");
            break;
          case TSDB_DATA_TYPE_INT:
            len += sprintf(data->sql + len, "tintdata");
            break;
          case TSDB_DATA_TYPE_BIGINT:
            len += sprintf(data->sql + len, "tbigdata");
            break;
          case TSDB_DATA_TYPE_FLOAT:
            len += sprintf(data->sql + len, "tfloatdata");
            break;
          case TSDB_DATA_TYPE_DOUBLE:
            len += sprintf(data->sql + len, "tdoubledata");
            break;
          case TSDB_DATA_TYPE_VARCHAR:
            len += sprintf(data->sql + len, "tbinarydata");
            break;
          case TSDB_DATA_TYPE_TIMESTAMP:
            len += sprintf(data->sql + len, "tts");
            break;
          case TSDB_DATA_TYPE_NCHAR:
            len += sprintf(data->sql + len, "tnchardata");
            break;
          case TSDB_DATA_TYPE_UTINYINT:
            len += sprintf(data->sql + len, "tutinydata");
            break;
          case TSDB_DATA_TYPE_USMALLINT:
            len += sprintf(data->sql + len, "tusmalldata");
            break;
          case TSDB_DATA_TYPE_UINT:
            len += sprintf(data->sql + len, "tuintdata");
            break;
          case TSDB_DATA_TYPE_UBIGINT:
            len += sprintf(data->sql + len, "tubigdata");
            break;
D
Dingle Zhang 已提交
459 460 461
          case TSDB_DATA_TYPE_GEOMETRY:
            len += sprintf(data->sql + len, "tgeometrydata");
            break;
D
dapan1121 已提交
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
          default:
            printf("!!!invalid tag type:%d", data->pTags[c].buffer_type);
            exit(1);
        }
      }
      
      len += sprintf(data->sql + len, ") ");
    }

    len += sprintf(data->sql + len, "tags (");
    for (int c = 0; c < gCurCase->bindTagNum; ++c) {
      if (c) {
        len += sprintf(data->sql + len, ",");
      }
      len += sprintf(data->sql + len, "?");
    }
    len += sprintf(data->sql + len, ") ");    
  }
  
D
stmt  
dapan1121 已提交
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529
  if (!gCurCase->fullCol) {
    len += sprintf(data->sql + len, "(");
    for (int c = 0; c < gCurCase->bindColNum; ++c) {
      if (c) {
        len += sprintf(data->sql + len, ",");
      }
      switch (data->pBind[c].buffer_type) {  
        case TSDB_DATA_TYPE_BOOL:
          len += sprintf(data->sql + len, "booldata");
          break;
        case TSDB_DATA_TYPE_TINYINT:
          len += sprintf(data->sql + len, "tinydata");
          break;
        case TSDB_DATA_TYPE_SMALLINT:
          len += sprintf(data->sql + len, "smalldata");
          break;
        case TSDB_DATA_TYPE_INT:
          len += sprintf(data->sql + len, "intdata");
          break;
        case TSDB_DATA_TYPE_BIGINT:
          len += sprintf(data->sql + len, "bigdata");
          break;
        case TSDB_DATA_TYPE_FLOAT:
          len += sprintf(data->sql + len, "floatdata");
          break;
        case TSDB_DATA_TYPE_DOUBLE:
          len += sprintf(data->sql + len, "doubledata");
          break;
        case TSDB_DATA_TYPE_VARCHAR:
          len += sprintf(data->sql + len, "binarydata");
          break;
        case TSDB_DATA_TYPE_TIMESTAMP:
          len += sprintf(data->sql + len, "ts");
          break;
        case TSDB_DATA_TYPE_NCHAR:
          len += sprintf(data->sql + len, "nchardata");
          break;
        case TSDB_DATA_TYPE_UTINYINT:
          len += sprintf(data->sql + len, "utinydata");
          break;
        case TSDB_DATA_TYPE_USMALLINT:
          len += sprintf(data->sql + len, "usmalldata");
          break;
        case TSDB_DATA_TYPE_UINT:
          len += sprintf(data->sql + len, "uintdata");
          break;
        case TSDB_DATA_TYPE_UBIGINT:
          len += sprintf(data->sql + len, "ubigdata");
          break;
D
Dingle Zhang 已提交
530 531 532
        case TSDB_DATA_TYPE_GEOMETRY:
          len += sprintf(data->sql + len, "tgeometrydata");
          break;
D
stmt  
dapan1121 已提交
533
        default:
D
dapan1121 已提交
534
          printf("!!!invalid col type:%d", data->pBind[c].buffer_type);
D
stmt  
dapan1121 已提交
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
          exit(1);
      }
    }
    
    len += sprintf(data->sql + len, ") ");
  }

  len += sprintf(data->sql + len, "values (");
  for (int c = 0; c < gCurCase->bindColNum; ++c) {
    if (c) {
      len += sprintf(data->sql + len, ",");
    }
    len += sprintf(data->sql + len, "?");
  }
  len += sprintf(data->sql + len, ")");
D
stmt  
dapan1121 已提交
550

D
dapan1121 已提交
551
  if (gCaseCtrl.printStmtSql) {
D
dapan1121 已提交
552
    printf("\tSQL: %s\n", data->sql);
D
stmt  
dapan1121 已提交
553
  }  
D
stmt  
dapan1121 已提交
554
}
D
stmt  
dapan1121 已提交
555

D
dapan1121 已提交
556
void bpAppendOperatorParam(BindData *data, int32_t *len, int32_t dataType, int32_t idx) {
D
dapan1121 已提交
557
  OperInfo *pInfo = NULL;
D
dapan1121 已提交
558 559 560

  if (gCaseCtrl.optrIdxListNum > 0) {
    pInfo = &operInfo[gCaseCtrl.optrIdxList[idx]];
D
dapan1121 已提交
561
  } else {
D
Dingle Zhang 已提交
562
    if (TSDB_DATA_TYPE_VARCHAR == dataType || TSDB_DATA_TYPE_NCHAR == dataType || TSDB_DATA_TYPE_GEOMETRY == dataType) {
D
dapan1121 已提交
563 564 565 566
      pInfo = &operInfo[varoperatorList[rand() % tListLen(varoperatorList)]];
    } else {
      pInfo = &operInfo[operatorList[rand() % tListLen(operatorList)]];
    }
D
dapan1121 已提交
567
  }
D
dapan1121 已提交
568
  
D
dapan1121 已提交
569 570 571 572 573 574 575 576 577
  switch (pInfo->paramNum) {
    case 2:
      if (pInfo->enclose) {
        *len += sprintf(data->sql + *len, " %s (?)", pInfo->oper);
      } else {
        *len += sprintf(data->sql + *len, " %s ?", pInfo->oper);
      }
      break;
    default:
D
dapan1121 已提交
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646
      printf("!!!invalid operator paramNum:%d\n", pInfo->paramNum);
      exit(1);
  }
}

void bpAppendFunctionParam(BindData *data, int32_t *len, int32_t dataType, int32_t idx) {
  FuncInfo *pInfo = NULL;

  if (gCaseCtrl.funcIdxListNum > 0) {
    pInfo = &funcInfo[gCaseCtrl.funcIdxList[idx]];
  } else {
    pInfo = &funcInfo[rand() % tListLen(funcInfo)];
  }
  
  switch (pInfo->paramNum) {
    case 1:
      *len += sprintf(data->sql + *len, " %s(?)", pInfo->funcName);
      break;
    default:
      printf("!!!invalid function  paramNum:%d\n", pInfo->paramNum);
      exit(1);
  }
}


int32_t bpAppendColumnName(BindData *data, int32_t type, int32_t len) {
  switch (type) {  
    case TSDB_DATA_TYPE_BOOL:
      return sprintf(data->sql + len, "booldata");
      break;
    case TSDB_DATA_TYPE_TINYINT:
      return sprintf(data->sql + len, "tinydata");
      break;
    case TSDB_DATA_TYPE_SMALLINT:
      return sprintf(data->sql + len, "smalldata");
      break;
    case TSDB_DATA_TYPE_INT:
      return sprintf(data->sql + len, "intdata");
      break;
    case TSDB_DATA_TYPE_BIGINT:
      return sprintf(data->sql + len, "bigdata");
      break;
    case TSDB_DATA_TYPE_FLOAT:
      return sprintf(data->sql + len, "floatdata");
      break;
    case TSDB_DATA_TYPE_DOUBLE:
      return sprintf(data->sql + len, "doubledata");
      break;
    case TSDB_DATA_TYPE_VARCHAR:
      return sprintf(data->sql + len, "binarydata");
      break;
    case TSDB_DATA_TYPE_TIMESTAMP:
      return sprintf(data->sql + len, "ts");
      break;
    case TSDB_DATA_TYPE_NCHAR:
      return sprintf(data->sql + len, "nchardata");
      break;
    case TSDB_DATA_TYPE_UTINYINT:
      return sprintf(data->sql + len, "utinydata");
      break;
    case TSDB_DATA_TYPE_USMALLINT:
      return sprintf(data->sql + len, "usmalldata");
      break;
    case TSDB_DATA_TYPE_UINT:
      return sprintf(data->sql + len, "uintdata");
      break;
    case TSDB_DATA_TYPE_UBIGINT:
      return sprintf(data->sql + len, "ubigdata");
      break;
D
Dingle Zhang 已提交
647 648 649
    case TSDB_DATA_TYPE_GEOMETRY:
      len += sprintf(data->sql + len, "tgeometrydata");
      break;
D
dapan1121 已提交
650 651
    default:
      printf("!!!invalid col type:%d", type);
D
dapan1121 已提交
652 653
      exit(1);
  }
D
dapan1121 已提交
654 655

  return 0;
D
dapan1121 已提交
656 657
}

D
dapan1121 已提交
658
void generateQueryCondSQL(BindData *data, int32_t tblIdx) {
D
dapan1121 已提交
659 660 661 662 663 664
  int32_t len = sprintf(data->sql, "select * from %s%d where ", bpTbPrefix, tblIdx);
  if (!gCurCase->fullCol) {
    for (int c = 0; c < gCurCase->bindColNum; ++c) {
      if (c) {
        len += sprintf(data->sql + len, " and ");
      }
D
dapan1121 已提交
665
      len += bpAppendColumnName(data, data->pBind[c].buffer_type, len);
D
dapan1121 已提交
666
      
D
dapan1121 已提交
667
      bpAppendOperatorParam(data, &len, data->pBind[c].buffer_type, c);
D
dapan1121 已提交
668 669 670 671
    }
  }

  if (gCaseCtrl.printStmtSql) {
D
dapan1121 已提交
672
    printf("\tSTMT SQL: %s\n", data->sql);
D
dapan1121 已提交
673 674 675
  }  
}

D
dapan1121 已提交
676 677 678 679 680 681 682 683 684 685 686 687 688
void bpGenerateConstInOpSQL(BindData *data, int32_t tblIdx) {
  int32_t len = 0;
  len = sprintf(data->sql, "select ");
  
  for (int c = 0; c < gCurCase->bindColNum; ++c) {
    if (c) {
      len += sprintf(data->sql + len, ", ");
    }
    
    len += bpAppendColumnName(data, data->pBind[c].buffer_type, len);
    
    bpAppendOperatorParam(data, &len, data->pBind[c].buffer_type, c);
  }
D
dapan1121 已提交
689

D
dapan1121 已提交
690 691 692 693 694 695 696 697 698 699 700
  len += sprintf(data->sql + len, " from %s%d", bpTbPrefix, tblIdx);
}


void bpGenerateConstInFuncSQL(BindData *data, int32_t tblIdx) {
  int32_t len = 0;
  len = sprintf(data->sql, "select ");
  
  for (int c = 0; c < gCurCase->bindColNum; ++c) {
    if (c) {
      len += sprintf(data->sql + len, ", ");
D
dapan1121 已提交
701
    }
D
dapan1121 已提交
702 703 704 705 706 707 708 709 710
    
    bpAppendFunctionParam(data, &len, data->pBind[c].buffer_type, c);
  }

  len += sprintf(data->sql + len, " from %s%d", bpTbPrefix, tblIdx);
}


void generateQueryMiscSQL(BindData *data, int32_t tblIdx) {
D
dapan1121 已提交
711 712 713 714 715 716 717 718 719 720
  if (tblIdx == FUNCTION_TEST_IDX && gCurCase->bindNullNum <= 0) {
    bpGenerateConstInFuncSQL(data, tblIdx);
  } else {
    switch(tblIdx) {
      case 0:
        //TODO FILL TEST
      default:
        bpGenerateConstInOpSQL(data, tblIdx);
        break;
    }
D
dapan1121 已提交
721 722 723 724 725 726 727 728
  }

  if (gCaseCtrl.printStmtSql) {
    printf("\tSTMT SQL: %s\n", data->sql);
  }  
}


729

D
dapan1121 已提交
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752
void generateErrorSQL(BindData *data, int32_t tblIdx) {
  int32_t len = 0;
  data->sql = taosMemoryCalloc(1, 1024);
  
  switch(tblIdx) {
    case 0:
      len = sprintf(data->sql, "insert into %s%d values (?, 1)", bpTbPrefix, tblIdx);
      break;
    case 1:
      len = sprintf(data->sql, "select * from ?");
      break;
    case 2:
      len = sprintf(data->sql, "select * from %s%d where ? = ?", bpTbPrefix, tblIdx);
      break;
    default:
      len = sprintf(data->sql, "select count(*) from %s%d group by ?", bpTbPrefix, tblIdx);
      break;    
  }

  if (gCaseCtrl.printStmtSql) {
    printf("\tSTMT SQL: %s\n", data->sql);
  }  
}
D
dapan1121 已提交
753

D
dapan1121 已提交
754
void generateColDataType(BindData *data, int32_t bindIdx, int32_t colIdx, int32_t *dataType) {
D
stmt  
dapan1121 已提交
755
  if (bindIdx < gCurCase->bindColNum) {
D
stmt  
dapan1121 已提交
756
    if (gCaseCtrl.bindColTypeNum) {
D
stmt  
dapan1121 已提交
757 758
      *dataType = gCaseCtrl.bindColTypeList[colIdx];
      return;
D
stmt  
dapan1121 已提交
759 760 761
    } else if (gCurCase->fullCol) {
      *dataType = gCurCase->colList[bindIdx];
      return;
D
dapan1121 已提交
762 763 764 765 766 767 768 769 770 771
    } else if (gCaseCtrl.numericParam) {
      while (true) {
        *dataType = rand() % (TSDB_DATA_TYPE_MAX - 1) + 1;
        if (!IS_NUMERIC_TYPE(*dataType)) {
          continue;
        }

        break;
      }
      return;
D
stmt  
dapan1121 已提交
772 773 774 775
    } else if (0 == colIdx) {
      *dataType = TSDB_DATA_TYPE_TIMESTAMP;
      return;
    } else {
D
stmt  
dapan1121 已提交
776 777 778 779 780 781 782
      while (true) {
        *dataType = rand() % (TSDB_DATA_TYPE_MAX - 1) + 1;
        if (*dataType == TSDB_DATA_TYPE_JSON || *dataType == TSDB_DATA_TYPE_DECIMAL 
         || *dataType == TSDB_DATA_TYPE_BLOB || *dataType == TSDB_DATA_TYPE_MEDIUMBLOB
         || *dataType == TSDB_DATA_TYPE_VARBINARY) {
          continue;
        }
D
stmt  
dapan1121 已提交
783

D
stmt  
dapan1121 已提交
784 785 786 787 788 789 790 791 792 793 794 795
        if (colExists(data->pBind, *dataType)) {
          continue;
        }
        
        break;
      }
    }
  } else {
    *dataType = data->pBind[bindIdx%gCurCase->bindColNum].buffer_type;
  }
}

D
dapan1121 已提交
796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826
void generateTagDataType(BindData *data, int32_t bindIdx, int32_t colIdx, int32_t *dataType) {
  if (bindIdx < gCurCase->bindTagNum) {
    if (gCaseCtrl.bindTagTypeNum) {
      *dataType = gCaseCtrl.bindTagTypeList[colIdx];
      return;
    } else if (gCurCase->fullCol) {
      *dataType = gCurCase->colList[bindIdx];
      return;
    } else {
      while (true) {
        *dataType = rand() % (TSDB_DATA_TYPE_MAX - 1) + 1;
        if (*dataType == TSDB_DATA_TYPE_JSON || *dataType == TSDB_DATA_TYPE_DECIMAL 
         || *dataType == TSDB_DATA_TYPE_BLOB || *dataType == TSDB_DATA_TYPE_MEDIUMBLOB
         || *dataType == TSDB_DATA_TYPE_VARBINARY) {
          continue;
        }

        if (colExists(data->pTags, *dataType)) {
          continue;
        }
        
        break;
      }
    }
  } else {
    *dataType = data->pTags[bindIdx%gCurCase->bindTagNum].buffer_type;
  }
}


int32_t prepareColData(BP_BIND_TYPE bType, BindData *data, int32_t bindIdx, int32_t rowIdx, int32_t colIdx) {
D
stmt  
dapan1121 已提交
827
  int32_t dataType = TSDB_DATA_TYPE_TIMESTAMP;
D
dapan1121 已提交
828 829 830 831 832 833 834 835 836
  TAOS_MULTI_BIND *pBase = NULL;
  
  if (bType == BP_BIND_TAG) {
    pBase = data->pTags;
    generateTagDataType(data, bindIdx, colIdx, &dataType);
  } else {
    pBase = data->pBind;
    generateColDataType(data, bindIdx, colIdx, &dataType);
  }
D
stmt  
dapan1121 已提交
837 838 839 840


  switch (dataType) {  
    case TSDB_DATA_TYPE_BOOL:
D
dapan1121 已提交
841 842 843 844
      pBase[bindIdx].buffer_length = sizeof(bool);
      pBase[bindIdx].buffer = data->boolData + rowIdx;
      pBase[bindIdx].length = NULL;
      pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
845 846
      break;
    case TSDB_DATA_TYPE_TINYINT:
D
dapan1121 已提交
847 848 849 850
      pBase[bindIdx].buffer_length = sizeof(int8_t);
      pBase[bindIdx].buffer = data->tinyData + rowIdx;
      pBase[bindIdx].length = NULL;
      pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
851 852
      break;
    case TSDB_DATA_TYPE_SMALLINT:
D
dapan1121 已提交
853 854 855 856
      pBase[bindIdx].buffer_length = sizeof(int16_t);
      pBase[bindIdx].buffer = data->smallData + rowIdx;
      pBase[bindIdx].length = NULL;
      pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
857 858
      break;
    case TSDB_DATA_TYPE_INT:
D
dapan1121 已提交
859 860 861 862
      pBase[bindIdx].buffer_length = sizeof(int32_t);
      pBase[bindIdx].buffer = data->intData + rowIdx;
      pBase[bindIdx].length = NULL;
      pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
863 864
      break;
    case TSDB_DATA_TYPE_BIGINT:
D
dapan1121 已提交
865 866 867 868
      pBase[bindIdx].buffer_length = sizeof(int64_t);
      pBase[bindIdx].buffer = data->bigData + rowIdx;
      pBase[bindIdx].length = NULL;
      pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
869 870
      break;
    case TSDB_DATA_TYPE_FLOAT:
D
dapan1121 已提交
871 872 873 874
      pBase[bindIdx].buffer_length = sizeof(float);
      pBase[bindIdx].buffer = data->floatData + rowIdx;
      pBase[bindIdx].length = NULL;
      pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
875 876
      break;
    case TSDB_DATA_TYPE_DOUBLE:
D
dapan1121 已提交
877 878 879 880
      pBase[bindIdx].buffer_length = sizeof(double);
      pBase[bindIdx].buffer = data->doubleData + rowIdx;
      pBase[bindIdx].length = NULL;
      pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
881 882
      break;
    case TSDB_DATA_TYPE_VARCHAR:
D
Dingle Zhang 已提交
883
    case TSDB_DATA_TYPE_GEOMETRY:
D
dapan1121 已提交
884 885 886 887
      pBase[bindIdx].buffer_length = gVarCharSize;
      pBase[bindIdx].buffer = data->binaryData + rowIdx * gVarCharSize;
      pBase[bindIdx].length = data->binaryLen;
      pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
888 889
      break;
    case TSDB_DATA_TYPE_TIMESTAMP:
D
dapan1121 已提交
890 891 892 893
      pBase[bindIdx].buffer_length = sizeof(int64_t);
      pBase[bindIdx].buffer = data->tsData + rowIdx;
      pBase[bindIdx].length = NULL;
      pBase[bindIdx].is_null = NULL;
D
stmt  
dapan1121 已提交
894 895
      break;
    case TSDB_DATA_TYPE_NCHAR:
D
dapan1121 已提交
896 897 898 899
      pBase[bindIdx].buffer_length = gVarCharSize;
      pBase[bindIdx].buffer = data->binaryData + rowIdx * gVarCharSize;
      pBase[bindIdx].length = data->binaryLen;
      pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
900 901
      break;
    case TSDB_DATA_TYPE_UTINYINT:
D
dapan1121 已提交
902 903 904 905
      pBase[bindIdx].buffer_length = sizeof(uint8_t);
      pBase[bindIdx].buffer = data->utinyData + rowIdx;
      pBase[bindIdx].length = NULL;
      pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
906 907
      break;
    case TSDB_DATA_TYPE_USMALLINT:
D
dapan1121 已提交
908 909 910 911
      pBase[bindIdx].buffer_length = sizeof(uint16_t);
      pBase[bindIdx].buffer = data->usmallData + rowIdx;
      pBase[bindIdx].length = NULL;
      pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
912 913
      break;
    case TSDB_DATA_TYPE_UINT:
D
dapan1121 已提交
914 915 916 917
      pBase[bindIdx].buffer_length = sizeof(uint32_t);
      pBase[bindIdx].buffer = data->uintData + rowIdx;
      pBase[bindIdx].length = NULL;
      pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
918 919
      break;
    case TSDB_DATA_TYPE_UBIGINT:
D
dapan1121 已提交
920 921 922 923
      pBase[bindIdx].buffer_length = sizeof(uint64_t);
      pBase[bindIdx].buffer = data->ubigData + rowIdx;
      pBase[bindIdx].length = NULL;
      pBase[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
924 925
      break;
    default:
D
dapan1121 已提交
926
      printf("!!!invalid col type:%d", dataType);
D
stmt  
dapan1121 已提交
927 928 929
      exit(1);
  }

D
dapan1121 已提交
930 931
  pBase[bindIdx].buffer_type = dataType;
  pBase[bindIdx].num = gCurCase->bindRowNum;
D
stmt  
dapan1121 已提交
932

D
dapan1121 已提交
933 934 935 936
  if (bType == BP_BIND_TAG) {
    pBase[bindIdx].num = 1;
  }
  
D
stmt  
dapan1121 已提交
937 938 939 940
  return 0;
}


D
dapan1121 已提交
941
int32_t prepareInsertData(BindData *data) {
D
stmt  
dapan1121 已提交
942 943 944 945 946
  uint64_t allRowNum = gCurCase->rowNum * gCurCase->tblNum;
  
  data->colNum = 0;
  data->colTypes = taosMemoryCalloc(30, sizeof(int32_t));
  data->sql = taosMemoryCalloc(1, 1024);
D
dapan1121 已提交
947
  data->pBind = taosMemoryCalloc((int32_t)(allRowNum/gCurCase->bindRowNum)*gCurCase->bindColNum, sizeof(TAOS_MULTI_BIND));
D
dapan1121 已提交
948
  data->pTags = taosMemoryCalloc(gCurCase->tblNum*gCurCase->bindTagNum, sizeof(TAOS_MULTI_BIND));
D
stmt  
dapan1121 已提交
949 950 951 952 953 954 955 956 957 958 959 960 961 962 963
  data->tsData = taosMemoryMalloc(allRowNum * sizeof(int64_t));
  data->boolData = taosMemoryMalloc(allRowNum * sizeof(bool));
  data->tinyData = taosMemoryMalloc(allRowNum * sizeof(int8_t));
  data->utinyData = taosMemoryMalloc(allRowNum * sizeof(uint8_t));
  data->smallData = taosMemoryMalloc(allRowNum * sizeof(int16_t));
  data->usmallData = taosMemoryMalloc(allRowNum * sizeof(uint16_t));
  data->intData = taosMemoryMalloc(allRowNum * sizeof(int32_t));
  data->uintData = taosMemoryMalloc(allRowNum * sizeof(uint32_t));
  data->bigData = taosMemoryMalloc(allRowNum * sizeof(int64_t));
  data->ubigData = taosMemoryMalloc(allRowNum * sizeof(uint64_t));
  data->floatData = taosMemoryMalloc(allRowNum * sizeof(float));
  data->doubleData = taosMemoryMalloc(allRowNum * sizeof(double));
  data->binaryData = taosMemoryMalloc(allRowNum * gVarCharSize);
  data->binaryLen = taosMemoryMalloc(allRowNum * sizeof(int32_t));
  if (gCurCase->bindNullNum) {
D
dapan1121 已提交
964
    data->isNull = taosMemoryCalloc((int32_t)allRowNum, sizeof(char));
D
stmt  
dapan1121 已提交
965 966 967
  }
  
  for (int32_t i = 0; i < allRowNum; ++i) {
D
dapan1121 已提交
968 969 970 971 972 973 974 975
    if (gCurCase->duplicateValue) {
      data->tsData[i] = bpTs;
      if (i % 2 == 1) {
        bpTs++;
      }
    } else {
      data->tsData[i] = bpTs++;
    }
D
dapan1121 已提交
976 977 978 979 980 981 982 983 984 985 986
    data->boolData[i] = (bool)(i % 2);
    data->tinyData[i] = (int8_t)i;
    data->utinyData[i] = (uint8_t)(i+1);
    data->smallData[i] = (int16_t)i;
    data->usmallData[i] = (uint16_t)(i+1);
    data->intData[i] = (int32_t)i;
    data->uintData[i] = (uint32_t)(i+1);
    data->bigData[i] = (int64_t)i;
    data->ubigData[i] = (uint64_t)(i+1);
    data->floatData[i] = (float)i;
    data->doubleData[i] = (double)(i+1);
D
stmt  
dapan1121 已提交
987 988
    memset(data->binaryData + gVarCharSize * i, 'a'+i%26, gVarCharLen);
    if (gCurCase->bindNullNum) {
D
dapan1121 已提交
989
      data->isNull[i] = (char)(i % 2);
D
stmt  
dapan1121 已提交
990 991 992 993 994 995
    }
    data->binaryLen[i] = gVarCharLen;
  }

  for (int b = 0; b < (allRowNum/gCurCase->bindRowNum); b++) {
    for (int c = 0; c < gCurCase->bindColNum; ++c) {
D
dapan1121 已提交
996 997 998 999 1000 1001 1002
      prepareColData(BP_BIND_COL, data, b*gCurCase->bindColNum+c, b*gCurCase->bindRowNum, c);
    }
  }

  for (int b = 0; b < gCurCase->tblNum; b++) {
    for (int c = 0; c < gCurCase->bindTagNum; ++c) {
      prepareColData(BP_BIND_TAG, data, b*gCurCase->bindTagNum+c, b, c);
D
stmt  
dapan1121 已提交
1003 1004 1005
    }
  }

D
dapan1121 已提交
1006

D
stmt  
dapan1121 已提交
1007
  generateInsertSQL(data);
D
stmt  
dapan1121 已提交
1008 1009 1010 1011
  
  return 0;
}

D
dapan1121 已提交
1012
int32_t prepareQueryCondData(BindData *data, int32_t tblIdx) {
D
dapan1121 已提交
1013 1014 1015 1016 1017
  uint64_t bindNum = gCurCase->rowNum / gCurCase->bindRowNum;
  
  data->colNum = 0;
  data->colTypes = taosMemoryCalloc(30, sizeof(int32_t));
  data->sql = taosMemoryCalloc(1, 1024);
D
dapan1121 已提交
1018
  data->pBind = taosMemoryCalloc((int32_t)bindNum*gCurCase->bindColNum, sizeof(TAOS_MULTI_BIND));
D
dapan1121 已提交
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033
  data->tsData = taosMemoryMalloc(bindNum * sizeof(int64_t));
  data->boolData = taosMemoryMalloc(bindNum * sizeof(bool));
  data->tinyData = taosMemoryMalloc(bindNum * sizeof(int8_t));
  data->utinyData = taosMemoryMalloc(bindNum * sizeof(uint8_t));
  data->smallData = taosMemoryMalloc(bindNum * sizeof(int16_t));
  data->usmallData = taosMemoryMalloc(bindNum * sizeof(uint16_t));
  data->intData = taosMemoryMalloc(bindNum * sizeof(int32_t));
  data->uintData = taosMemoryMalloc(bindNum * sizeof(uint32_t));
  data->bigData = taosMemoryMalloc(bindNum * sizeof(int64_t));
  data->ubigData = taosMemoryMalloc(bindNum * sizeof(uint64_t));
  data->floatData = taosMemoryMalloc(bindNum * sizeof(float));
  data->doubleData = taosMemoryMalloc(bindNum * sizeof(double));
  data->binaryData = taosMemoryMalloc(bindNum * gVarCharSize);
  data->binaryLen = taosMemoryMalloc(bindNum * sizeof(int32_t));
  if (gCurCase->bindNullNum) {
D
dapan1121 已提交
1034
    data->isNull = taosMemoryCalloc((int32_t)bindNum, sizeof(char));
D
dapan1121 已提交
1035 1036 1037
  }
  
  for (int32_t i = 0; i < bindNum; ++i) {
D
dapan1121 已提交
1038
    data->tsData[i] = bpTs + tblIdx*gCurCase->rowNum + rand()%gCurCase->rowNum;
D
dapan1121 已提交
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
    data->boolData[i] = (bool)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->tinyData[i] = (int8_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->utinyData[i] = (uint8_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->smallData[i] = (int16_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->usmallData[i] = (uint16_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->intData[i] = (int32_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->uintData[i] = (uint32_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->bigData[i] = (int64_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->ubigData[i] = (uint64_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->floatData[i] = (float)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->doubleData[i] = (double)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    memset(data->binaryData + gVarCharSize * i, 'a'+i%26, gVarCharLen);
    if (gCurCase->bindNullNum) {
D
dapan1121 已提交
1052
      data->isNull[i] = (char)(i % 2);
D
dapan1121 已提交
1053 1054 1055 1056 1057 1058
    }
    data->binaryLen[i] = gVarCharLen;
  }

  for (int b = 0; b < bindNum; b++) {
    for (int c = 0; c < gCurCase->bindColNum; ++c) {
D
dapan1121 已提交
1059
      prepareColData(BP_BIND_COL, data, b*gCurCase->bindColNum+c, b*gCurCase->bindRowNum, c);
D
dapan1121 已提交
1060 1061 1062
    }
  }

D
fix bug  
dapan1121 已提交
1063
  generateQueryCondSQL(data, tblIdx);
D
dapan1121 已提交
1064 1065 1066 1067 1068
  
  return 0;
}


D
dapan1121 已提交
1069 1070 1071 1072 1073 1074
int32_t prepareQueryMiscData(BindData *data, int32_t tblIdx) {
  uint64_t bindNum = gCurCase->rowNum / gCurCase->bindRowNum;
  
  data->colNum = 0;
  data->colTypes = taosMemoryCalloc(30, sizeof(int32_t));
  data->sql = taosMemoryCalloc(1, 1024);
D
dapan1121 已提交
1075
  data->pBind = taosMemoryCalloc((int32_t)bindNum*gCurCase->bindColNum, sizeof(TAOS_MULTI_BIND));
D
dapan1121 已提交
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
  data->tsData = taosMemoryMalloc(bindNum * sizeof(int64_t));
  data->boolData = taosMemoryMalloc(bindNum * sizeof(bool));
  data->tinyData = taosMemoryMalloc(bindNum * sizeof(int8_t));
  data->utinyData = taosMemoryMalloc(bindNum * sizeof(uint8_t));
  data->smallData = taosMemoryMalloc(bindNum * sizeof(int16_t));
  data->usmallData = taosMemoryMalloc(bindNum * sizeof(uint16_t));
  data->intData = taosMemoryMalloc(bindNum * sizeof(int32_t));
  data->uintData = taosMemoryMalloc(bindNum * sizeof(uint32_t));
  data->bigData = taosMemoryMalloc(bindNum * sizeof(int64_t));
  data->ubigData = taosMemoryMalloc(bindNum * sizeof(uint64_t));
  data->floatData = taosMemoryMalloc(bindNum * sizeof(float));
  data->doubleData = taosMemoryMalloc(bindNum * sizeof(double));
  data->binaryData = taosMemoryMalloc(bindNum * gVarCharSize);
  data->binaryLen = taosMemoryMalloc(bindNum * sizeof(int32_t));
  if (gCurCase->bindNullNum) {
D
dapan1121 已提交
1091
    data->isNull = taosMemoryCalloc((int32_t)bindNum, sizeof(char));
D
dapan1121 已提交
1092 1093 1094
  }
  
  for (int32_t i = 0; i < bindNum; ++i) {
D
dapan1121 已提交
1095
    data->tsData[i] = bpTs + tblIdx*gCurCase->rowNum + rand()%gCurCase->rowNum;
D
dapan1121 已提交
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108
    data->boolData[i] = (bool)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->tinyData[i] = (int8_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->utinyData[i] = (uint8_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->smallData[i] = (int16_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->usmallData[i] = (uint16_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->intData[i] = (int32_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->uintData[i] = (uint32_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->bigData[i] = (int64_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->ubigData[i] = (uint64_t)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->floatData[i] = (float)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    data->doubleData[i] = (double)(tblIdx*gCurCase->rowNum + rand() % gCurCase->rowNum);
    memset(data->binaryData + gVarCharSize * i, 'a'+i%26, gVarCharLen);
    if (gCurCase->bindNullNum) {
D
dapan1121 已提交
1109
      data->isNull[i] = (char)(i % 2);
D
dapan1121 已提交
1110 1111 1112 1113
    }
    data->binaryLen[i] = gVarCharLen;
  }

D
dapan1121 已提交
1114 1115
  if (tblIdx == FUNCTION_TEST_IDX) {
    gCaseCtrl.numericParam = true;
D
dapan1121 已提交
1116 1117
  } else {
    gCaseCtrl.numericParam = false;
D
dapan1121 已提交
1118 1119
  }
  
D
dapan1121 已提交
1120 1121
  for (int b = 0; b < bindNum; b++) {
    for (int c = 0; c < gCurCase->bindColNum; ++c) {
D
dapan1121 已提交
1122
      prepareColData(BP_BIND_COL, data, b*gCurCase->bindColNum+c, b*gCurCase->bindRowNum, c);
D
dapan1121 已提交
1123 1124 1125
    }
  }

D
dapan1121 已提交
1126 1127
  gCaseCtrl.numericParam = false;

D
dapan1121 已提交
1128
  generateQueryMiscSQL(data, tblIdx);
D
dapan1121 已提交
1129

D
dapan1121 已提交
1130 1131 1132
  return 0;
}

D
dapan1121 已提交
1133 1134


D
stmt  
dapan1121 已提交
1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151
void destroyData(BindData *data) {
  taosMemoryFree(data->tsData);
  taosMemoryFree(data->boolData);
  taosMemoryFree(data->tinyData);
  taosMemoryFree(data->utinyData);
  taosMemoryFree(data->smallData);
  taosMemoryFree(data->usmallData);
  taosMemoryFree(data->intData);
  taosMemoryFree(data->uintData);
  taosMemoryFree(data->bigData);
  taosMemoryFree(data->ubigData);
  taosMemoryFree(data->floatData);
  taosMemoryFree(data->doubleData);
  taosMemoryFree(data->binaryData);
  taosMemoryFree(data->binaryLen);
  taosMemoryFree(data->isNull);
  taosMemoryFree(data->pBind);
D
dapan1121 已提交
1152
  taosMemoryFree(data->pTags);
D
stmt  
dapan1121 已提交
1153
  taosMemoryFree(data->colTypes);
D
dapan1121 已提交
1154
  taosMemoryFree(data->sql);
D
stmt  
dapan1121 已提交
1155 1156
}

D
dapan1121 已提交
1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168
void bpFetchRows(TAOS_RES *result, bool printr, int32_t *rows) {
  TAOS_ROW    row;
  int         num_fields = taos_num_fields(result);
  TAOS_FIELD *fields = taos_fetch_fields(result);
  char        temp[256];

  // fetch the records row by row
  while ((row = taos_fetch_row(result))) {
    (*rows)++;
    if (printr) {
      memset(temp, 0, sizeof(temp));
      taos_print_row(temp, row, fields, num_fields);
D
dapan1121 已提交
1169
      printf("\t[%s]\n", temp);
D
dapan1121 已提交
1170 1171 1172 1173 1174 1175 1176 1177
    }
  }
}

void bpExecQuery(TAOS    * taos, char* sql, bool printr, int32_t *rows) {
  TAOS_RES *result = taos_query(taos, sql);
  int code = taos_errno(result);
  if (code != 0) {
D
dapan1121 已提交
1178
    printf("!!!failed to query table, reason:%s\n", taos_errstr(result));
D
dapan1121 已提交
1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225
    taos_free_result(result);
    exit(1);
  }

  bpFetchRows(result, printr, rows);

  taos_free_result(result);
}


int32_t bpAppendValueString(char *buf, int type, void *value, int32_t valueLen, int32_t *len) {
  switch (type) {
    case TSDB_DATA_TYPE_NULL:
      *len += sprintf(buf + *len, "null");
      break;

    case TSDB_DATA_TYPE_BOOL:
      *len += sprintf(buf + *len, (*(bool*)value) ? "true" : "false");
      break;

    case TSDB_DATA_TYPE_TINYINT:
      *len += sprintf(buf + *len, "%d", *(int8_t*)value);
      break;

    case TSDB_DATA_TYPE_SMALLINT:
      *len += sprintf(buf + *len, "%d", *(int16_t*)value);
      break;

    case TSDB_DATA_TYPE_INT:
      *len += sprintf(buf + *len, "%d", *(int32_t*)value);
      break;

    case TSDB_DATA_TYPE_BIGINT:
    case TSDB_DATA_TYPE_TIMESTAMP:
      *len += sprintf(buf + *len, "%ld", *(int64_t*)value);
      break;

    case TSDB_DATA_TYPE_FLOAT:
      *len += sprintf(buf + *len, "%e", *(float*)value);
      break;

    case TSDB_DATA_TYPE_DOUBLE:
      *len += sprintf(buf + *len, "%e", *(double*)value);
      break;

    case TSDB_DATA_TYPE_BINARY:
    case TSDB_DATA_TYPE_NCHAR:
D
Dingle Zhang 已提交
1226
    case TSDB_DATA_TYPE_GEOMETRY:
D
dapan1121 已提交
1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251
      buf[*len] = '\'';
      ++(*len);
      memcpy(buf + *len, value, valueLen);
      *len += valueLen;
      buf[*len] = '\'';
      ++(*len);
      break;

    case TSDB_DATA_TYPE_UTINYINT:
      *len += sprintf(buf + *len, "%d", *(uint8_t*)value);
      break;

    case TSDB_DATA_TYPE_USMALLINT:
      *len += sprintf(buf + *len, "%d", *(uint16_t*)value);
      break;

    case TSDB_DATA_TYPE_UINT:
      *len += sprintf(buf + *len, "%u", *(uint32_t*)value);
      break;

    case TSDB_DATA_TYPE_UBIGINT:
      *len += sprintf(buf + *len, "%lu", *(uint64_t*)value);
      break;

    default:
D
dapan1121 已提交
1252
      printf("!!!invalid data type:%d\n", type);
D
dapan1121 已提交
1253 1254 1255 1256 1257
      exit(1);
  }
}


D
stmt  
dapan1121 已提交
1258 1259


D
dapan1121 已提交
1260
void bpCheckIsInsert(TAOS_STMT *stmt, int32_t insert) {
D
stmt  
dapan1121 已提交
1261 1262
  int32_t isInsert = 0;
  if (taos_stmt_is_insert(stmt, &isInsert)) {
D
dapan1121 已提交
1263
    printf("!!!taos_stmt_is_insert error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1264 1265 1266
    exit(1);
  }

D
dapan1121 已提交
1267
  if (insert != isInsert) {
D
dapan1121 已提交
1268
    printf("!!!is insert failed\n");
D
stmt  
dapan1121 已提交
1269 1270 1271 1272 1273 1274 1275
    exit(1);
  }
}

void bpCheckParamNum(TAOS_STMT *stmt) {
  int32_t num = 0;
  if (taos_stmt_num_params(stmt, &num)) {
D
dapan1121 已提交
1276
    printf("!!!taos_stmt_num_params error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1277 1278 1279 1280
    exit(1);
  }

  if (gCurCase->bindColNum != num) {
D
dapan1121 已提交
1281
    printf("!!!is insert failed\n");
D
stmt  
dapan1121 已提交
1282 1283 1284 1285 1286 1287 1288
    exit(1);
  }
}

void bpCheckAffectedRows(TAOS_STMT *stmt, int32_t times) {
  int32_t rows = taos_stmt_affected_rows(stmt);
  int32_t insertNum = gCurCase->rowNum * gCurCase->tblNum * times;
D
dapan1121 已提交
1289 1290 1291
  if (gCurCase->duplicateValue) {
    insertNum /= 2;
  }
D
stmt  
dapan1121 已提交
1292
  if (insertNum != rows) {
D
dapan1121 已提交
1293
    printf("!!!affected rows %d mis-match with insert num %d\n", rows, insertNum);
D
stmt  
dapan1121 已提交
1294 1295
    exit(1);
  }
D
stmt  
dapan1121 已提交
1296 1297
}

D
dapan1121 已提交
1298 1299 1300
void bpCheckAffectedRowsOnce(TAOS_STMT *stmt, int32_t expectedNum) {
  int32_t rows = taos_stmt_affected_rows_once(stmt);
  if (expectedNum != rows) {
D
dapan1121 已提交
1301
    printf("!!!affected rows %d mis-match with expected num %d\n", rows, expectedNum);
D
dapan1121 已提交
1302 1303 1304 1305 1306
    exit(1);
  }
}

void bpCheckQueryResult(TAOS_STMT *stmt, TAOS *taos, char *stmtSql, TAOS_MULTI_BIND* bind) {
D
dapan1121 已提交
1307
  // query using sql
D
dapan1121 已提交
1308 1309 1310 1311
  char sql[1024];
  int32_t len = 0;
  char* p = stmtSql;
  char* s = NULL;
D
dapan1121 已提交
1312
  int32_t sqlResNum = 0;
D
dapan1121 已提交
1313 1314 1315 1316 1317 1318 1319 1320 1321

  for (int32_t i = 0; true; ++i, p=s+1) {
    s = strchr(p, '?');
    if (NULL == s) {
      strcpy(&sql[len], p);
      break;
    }

    memcpy(&sql[len], p, (int64_t)s - (int64_t)p);
D
dapan1121 已提交
1322
    len += (int32_t)((int64_t)s - (int64_t)p);
D
dapan1121 已提交
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332
    
    if (bind[i].is_null && bind[i].is_null[0]) {
      bpAppendValueString(sql, TSDB_DATA_TYPE_NULL, NULL, 0, &len);
      continue;
    }

    bpAppendValueString(sql, bind[i].buffer_type, bind[i].buffer, (bind[i].length ? bind[i].length[0] : 0), &len);
  }

  if (gCaseCtrl.printQuerySql) {
D
dapan1121 已提交
1333
    printf("\tQuery SQL: %s\n", sql);
D
dapan1121 已提交
1334 1335 1336
  }

  bpExecQuery(taos, sql, gCaseCtrl.printRes, &sqlResNum);
D
dapan1121 已提交
1337 1338 1339 1340 1341 1342

  // query using stmt
  TAOS_RES* res = taos_stmt_use_result(stmt);
  int32_t stmtResNum = 0;
  bpFetchRows(res, gCaseCtrl.printRes, &stmtResNum);

D
dapan1121 已提交
1343
  if (sqlResNum != stmtResNum) {
D
dapan1121 已提交
1344
    printf("!!!sql res num %d mis-match stmt res num %d\n", sqlResNum, stmtResNum);
D
dapan1121 已提交
1345 1346 1347
    exit(1);
  }

D
dapan1121 已提交
1348
  printf("***sql res num match stmt res num %d\n", stmtResNum);
D
dapan1121 已提交
1349
}
D
stmt  
dapan1121 已提交
1350

D
dapan1121 已提交
1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371
void bpCheckColTagFields(TAOS_STMT *stmt, int32_t fieldNum, TAOS_FIELD_E* pFields, int32_t expecteNum, TAOS_MULTI_BIND* pBind, BP_BIND_TYPE type) {
  int32_t code = 0;
  
  if (fieldNum != expecteNum) {
    printf("!!!%s field num %d mis-match expect num %d\n", BP_BIND_TYPE_STR(type),  fieldNum, expecteNum);
    exit(1);
  }

  if (type == BP_BIND_COL) {
    if (pFields[0].precision != gCaseCtrl.precision) {
      printf("!!!db precision %d mis-match expect %d\n", pFields[0].precision, gCaseCtrl.precision);
      exit(1);
    }
  }

  for (int32_t i = 0; i < fieldNum; ++i) {
    if (pFields[i].type != pBind[i].buffer_type) {
      printf("!!!%s %dth field type %d mis-match expect type %d\n", BP_BIND_TYPE_STR(type), i, pFields[i].type, pBind[i].buffer_type);
      exit(1);
    }

D
Dingle Zhang 已提交
1372
    if (pFields[i].type == TSDB_DATA_TYPE_BINARY || pFields[i].type == TSDB_DATA_TYPE_GEOMETRY) {
D
dapan1121 已提交
1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426
      if (pFields[i].bytes != (pBind[i].buffer_length + 2)) {
        printf("!!!%s %dth field len %d mis-match expect len %d\n", BP_BIND_TYPE_STR(type), i, pFields[i].bytes, (pBind[i].buffer_length + 2));
        exit(1);
      }
    } else if (pFields[i].type == TSDB_DATA_TYPE_NCHAR) {
      if (pFields[i].bytes != (pBind[i].buffer_length * 4 + 2)) {
        printf("!!!%s %dth field len %d mis-match expect len %d\n", BP_BIND_TYPE_STR(type), i, pFields[i].bytes, (pBind[i].buffer_length + 2));
        exit(1);
      }
    } else if (pFields[i].bytes != pBind[i].buffer_length) {
      printf("!!!%s %dth field len %d mis-match expect len %d\n", BP_BIND_TYPE_STR(type), i, pFields[i].bytes, pBind[i].buffer_length);
      exit(1);
    }
  }

  if (type == BP_BIND_COL) {
    int fieldType = 0;
    int fieldBytes = 0;
    for (int32_t i = 0; i < fieldNum; ++i) {    
      code = taos_stmt_get_param(stmt, i, &fieldType, &fieldBytes);
      if (code) {
        printf("!!!taos_stmt_get_param error:%s\n", taos_stmt_errstr(stmt));
        exit(1);
      }
      
      if (pFields[i].type != fieldType) {
        printf("!!!%s %dth field type %d mis-match expect type %d\n", BP_BIND_TYPE_STR(type), i, fieldType, pFields[i].type);
        exit(1);
      }
    
      if (pFields[i].bytes != fieldBytes) {
        printf("!!!%s %dth field len %d mis-match expect len %d\n", BP_BIND_TYPE_STR(type), i, fieldBytes, pFields[i].bytes);
        exit(1);
      }
    }
  }

  if (gCaseCtrl.printVerbose) {
    printf("%s fields check passed\n", BP_BIND_TYPE_STR(type));
  }
}


void bpCheckTagFields(TAOS_STMT *stmt, TAOS_MULTI_BIND* pBind) {
  int32_t code = 0;
  int fieldNum = 0;
  TAOS_FIELD_E* pFields = NULL;
  code = taos_stmt_get_tag_fields(stmt, &fieldNum, &pFields);
  if (code != 0){
    printf("!!!taos_stmt_get_tag_fields error:%s\n", taos_stmt_errstr(stmt));
    exit(1);
  }
  
  bpCheckColTagFields(stmt, fieldNum, pFields, gCurCase->bindTagNum, pBind, BP_BIND_TAG);
D
dapan1121 已提交
1427
  taosMemoryFree(pFields);
D
dapan1121 已提交
1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444
}

void bpCheckColFields(TAOS_STMT *stmt, TAOS_MULTI_BIND* pBind) {
  if (gCurCase->testType == TTYPE_QUERY) {
    return;
  }
  
  int32_t code = 0;
  int fieldNum = 0;
  TAOS_FIELD_E* pFields = NULL;
  code = taos_stmt_get_col_fields(stmt, &fieldNum, &pFields);
  if (code != 0){
    printf("!!!taos_stmt_get_col_fields error:%s\n", taos_stmt_errstr(stmt));
    exit(1);
  }
  
  bpCheckColTagFields(stmt, fieldNum, pFields, gCurCase->bindColNum, pBind, BP_BIND_COL);
D
dapan1121 已提交
1445
  taosMemoryFree(pFields);
D
dapan1121 已提交
1446 1447 1448 1449 1450
}

void bpShowBindParam(TAOS_MULTI_BIND *bind, int32_t num) {
  for (int32_t i = 0; i < num; ++i) {
    TAOS_MULTI_BIND* b = &bind[i];
D
dapan1121 已提交
1451
    printf("Bind %d: type[%d],buf[%p],buflen[%d],len[%d],null[%d],num[%d]\n", 
D
dapan1121 已提交
1452 1453 1454 1455
      i, b->buffer_type, b->buffer, b->buffer_length, b->length ? *b->length : 0, b->is_null ? *b->is_null : 0, b->num);
  }
}

D
dapan1121 已提交
1456
int32_t bpBindParam(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, bool expectFail) {
D
dapan1121 已提交
1457 1458
  static int32_t n = 0;

D
dapan1121 已提交
1459 1460 1461
  if (!expectFail) {
    bpCheckColFields(stmt, bind);
  }
D
dapan1121 已提交
1462 1463 1464 1465
  
  if (gCurCase->bindRowNum > 1) {
    if (0 == (n++%2)) {
      if (taos_stmt_bind_param_batch(stmt, bind)) {
D
dapan1121 已提交
1466
        if (expectFail) return 0;
D
dapan1121 已提交
1467 1468 1469 1470 1471 1472 1473
        printf("!!!taos_stmt_bind_param_batch error:%s\n", taos_stmt_errstr(stmt));
        bpShowBindParam(bind, gCurCase->bindColNum);
        exit(1);
      }
    } else {
      for (int32_t i = 0; i < gCurCase->bindColNum; ++i) {
        if (taos_stmt_bind_single_param_batch(stmt, bind+i, i)) {
D
dapan1121 已提交
1474
          if (expectFail) continue;
D
dapan1121 已提交
1475 1476 1477 1478 1479 1480 1481 1482 1483
          printf("!!!taos_stmt_bind_single_param_batch %d error:%s\n", taos_stmt_errstr(stmt), i);
          bpShowBindParam(bind, gCurCase->bindColNum);
          exit(1);
        }
      }
    }
  } else {
    if (0 == (n++%2)) {
      if (taos_stmt_bind_param_batch(stmt, bind)) {
D
dapan1121 已提交
1484
        if (expectFail) return 0;
D
dapan1121 已提交
1485 1486 1487 1488 1489 1490
        printf("!!!taos_stmt_bind_param_batch error:%s\n", taos_stmt_errstr(stmt));
        bpShowBindParam(bind, gCurCase->bindColNum);
        exit(1);
      }
    } else {
      if (taos_stmt_bind_param(stmt, bind)) {
D
dapan1121 已提交
1491
        if (expectFail) return 0;
D
dapan1121 已提交
1492 1493 1494 1495 1496 1497 1498 1499 1500 1501
        printf("!!!taos_stmt_bind_param error:%s\n", taos_stmt_errstr(stmt));
        bpShowBindParam(bind, gCurCase->bindColNum);        
        exit(1);
      }
    }
  }

  return 0;
}

D
dapan 已提交
1502
int32_t bpSetTableNameTags(BindData *data, int32_t tblIdx, char *tblName, TAOS_STMT *stmt) {
D
dapan1121 已提交
1503
  int32_t code = 0;
D
dapan 已提交
1504
  if (gCurCase->bindTagNum > 0) {
D
dapan1121 已提交
1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517
    if ((rand() % 2) == 0) {
      code = taos_stmt_set_tbname(stmt, tblName);
      if (code != 0){
        printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
        exit(1);
      }

      bpCheckTagFields(stmt, data->pTags + tblIdx * gCurCase->bindTagNum);
      
      return taos_stmt_set_tags(stmt, data->pTags + tblIdx * gCurCase->bindTagNum);
    } else {
      return taos_stmt_set_tbname_tags(stmt, tblName, data->pTags + tblIdx * gCurCase->bindTagNum);  
    }
D
dapan 已提交
1518 1519 1520 1521 1522 1523
  } else {
    return taos_stmt_set_tbname(stmt, tblName);
  }
}


D
stmt  
dapan1121 已提交
1524
/* prepare [settbname [bind add]] exec */
D
dapan1121 已提交
1525
int insertMBSETest1(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1526
  BindData data = {0};
D
dapan1121 已提交
1527
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1528 1529

  int code = taos_stmt_prepare(stmt, data.sql, 0);
D
stmt  
dapan1121 已提交
1530
  if (code != 0){
D
dapan1121 已提交
1531
    printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1532
    exit(1);
D
stmt  
dapan1121 已提交
1533 1534
  }

D
dapan1121 已提交
1535
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1536

D
stmt  
dapan1121 已提交
1537 1538 1539 1540 1541
  int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum;
  for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
    if (gCurCase->tblNum > 1) {
      char buf[32];
      sprintf(buf, "t%d", t);
D
dapan 已提交
1542
      code = bpSetTableNameTags(&data, t, buf, stmt);
D
stmt  
dapan1121 已提交
1543
      if (code != 0){
D
dapan1121 已提交
1544
        printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1545 1546 1547
        exit(1);
      }  
    }
D
stmt  
dapan1121 已提交
1548 1549 1550 1551

    if (gCaseCtrl.checkParamNum) {
      bpCheckParamNum(stmt);
    }
D
stmt  
dapan1121 已提交
1552 1553
    
    for (int32_t b = 0; b <bindTimes; ++b) {
D
dapan1121 已提交
1554
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum, false)) {
D
stmt  
dapan1121 已提交
1555 1556 1557 1558
        exit(1);
      }
      
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1559
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1560 1561 1562 1563 1564 1565
        exit(1);
      }
    }
  }

  if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1566
    printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1567 1568 1569
    exit(1);
  }

D
dapan1121 已提交
1570
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1571 1572 1573 1574
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);

D
stmt  
dapan1121 已提交
1575 1576 1577 1578
  return 0;
}


D
stmt  
dapan1121 已提交
1579
/* prepare [settbname bind add] exec  */
D
dapan1121 已提交
1580
int insertMBSETest2(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1581
  BindData data = {0};
D
dapan1121 已提交
1582
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1583 1584 1585

  int code = taos_stmt_prepare(stmt, data.sql, 0);
  if (code != 0){
D
dapan1121 已提交
1586
    printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1587 1588 1589
    exit(1);
  }

D
dapan1121 已提交
1590
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1591

D
stmt  
dapan1121 已提交
1592 1593 1594 1595 1596 1597 1598
  int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum;

  for (int32_t b = 0; b <bindTimes; ++b) {
    for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
      if (gCurCase->tblNum > 1) {
        char buf[32];
        sprintf(buf, "t%d", t);
D
dapan 已提交
1599
        code = bpSetTableNameTags(&data, t, buf, stmt);
D
stmt  
dapan1121 已提交
1600
        if (code != 0){
D
dapan1121 已提交
1601
          printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1602 1603 1604 1605
          exit(1);
        }  
      }
    
D
dapan1121 已提交
1606
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum, false)) {
D
stmt  
dapan1121 已提交
1607 1608
        exit(1);
      }
D
stmt  
dapan1121 已提交
1609 1610 1611 1612 1613

      if (gCaseCtrl.checkParamNum) {
        bpCheckParamNum(stmt);
      }
    
D
stmt  
dapan1121 已提交
1614
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1615
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1616 1617 1618 1619 1620 1621
        exit(1);
      }
    }
  }

  if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1622
    printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1623 1624 1625
    exit(1);
  }

D
dapan1121 已提交
1626
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1627 1628 1629 1630
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);

D
stmt  
dapan1121 已提交
1631 1632 1633 1634
  return 0;
}

/* prepare [settbname [bind add] exec] */
D
dapan1121 已提交
1635
int insertMBMETest1(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1636
  BindData data = {0};
D
dapan1121 已提交
1637
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1638 1639 1640
  
  int code = taos_stmt_prepare(stmt, data.sql, 0);
  if (code != 0){
D
dapan1121 已提交
1641
    printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1642 1643
    exit(1);
  }
D
stmt  
dapan1121 已提交
1644

D
dapan1121 已提交
1645
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1646

D
stmt  
dapan1121 已提交
1647 1648 1649 1650 1651
  int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum;
  for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
    if (gCurCase->tblNum > 1) {
      char buf[32];
      sprintf(buf, "t%d", t);
D
dapan 已提交
1652
      code = bpSetTableNameTags(&data, t, buf, stmt);
D
stmt  
dapan1121 已提交
1653
      if (code != 0){
D
dapan1121 已提交
1654
        printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1655 1656 1657
        exit(1);
      }  
    }
D
stmt  
dapan1121 已提交
1658 1659 1660 1661

    if (gCaseCtrl.checkParamNum) {
      bpCheckParamNum(stmt);
    }
D
stmt  
dapan1121 已提交
1662 1663
    
    for (int32_t b = 0; b <bindTimes; ++b) {
D
dapan1121 已提交
1664
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum, false)) {
D
stmt  
dapan1121 已提交
1665 1666 1667 1668
        exit(1);
      }
      
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1669
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1670 1671 1672
        exit(1);
      }
    }
D
stmt  
dapan1121 已提交
1673

D
stmt  
dapan1121 已提交
1674
    if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1675
      printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1676 1677
      exit(1);
    }
D
stmt  
dapan1121 已提交
1678 1679
  }

D
dapan1121 已提交
1680
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1681 1682 1683
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);
D
stmt  
dapan1121 已提交
1684

D
stmt  
dapan1121 已提交
1685 1686 1687
  return 0;
}

D
stmt  
dapan1121 已提交
1688
/* prepare [settbname [bind add exec]] */
D
dapan1121 已提交
1689
int insertMBMETest2(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1690
  BindData data = {0};
D
dapan1121 已提交
1691
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1692 1693 1694

  int code = taos_stmt_prepare(stmt, data.sql, 0);
  if (code != 0){
D
dapan1121 已提交
1695
    printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1696 1697 1698
    exit(1);
  }

D
dapan1121 已提交
1699
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1700

D
stmt  
dapan1121 已提交
1701 1702 1703 1704 1705
  int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum;
  for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
    if (gCurCase->tblNum > 1) {
      char buf[32];
      sprintf(buf, "t%d", t);
D
dapan 已提交
1706
      code = bpSetTableNameTags(&data, t, buf, stmt);
D
stmt  
dapan1121 已提交
1707
      if (code != 0){
D
dapan1121 已提交
1708
        printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1709 1710 1711 1712 1713
        exit(1);
      }  
    }
    
    for (int32_t b = 0; b <bindTimes; ++b) {
D
dapan1121 已提交
1714
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum, false)) {
D
stmt  
dapan1121 已提交
1715 1716
        exit(1);
      }
D
stmt  
dapan1121 已提交
1717 1718 1719 1720 1721

      if (gCaseCtrl.checkParamNum) {
        bpCheckParamNum(stmt);
      }
    
D
stmt  
dapan1121 已提交
1722
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1723
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1724 1725 1726 1727
        exit(1);
      }

      if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1728
        printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1729 1730 1731 1732 1733
        exit(1);
      }
    }
  }

D
dapan1121 已提交
1734
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1735 1736 1737
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);
D
stmt  
dapan1121 已提交
1738 1739 1740 1741

  return 0;
}

D
stmt  
dapan1121 已提交
1742
/* prepare [settbname [settbname bind add exec]] */
D
dapan1121 已提交
1743
int insertMBMETest3(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1744
  BindData data = {0};
D
dapan1121 已提交
1745
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1746 1747 1748

  int code = taos_stmt_prepare(stmt, data.sql, 0);
  if (code != 0){
D
dapan1121 已提交
1749
    printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1750 1751 1752
    exit(1);
  }

D
dapan1121 已提交
1753
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1754

D
stmt  
dapan1121 已提交
1755 1756 1757 1758 1759
  int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum;
  for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
    if (gCurCase->tblNum > 1) {
      char buf[32];
      sprintf(buf, "t%d", t);
D
dapan 已提交
1760
      code = bpSetTableNameTags(&data, t, buf, stmt);
D
stmt  
dapan1121 已提交
1761
      if (code != 0){
D
dapan1121 已提交
1762
        printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1763 1764 1765
        exit(1);
      }  
    }
D
stmt  
dapan1121 已提交
1766 1767 1768 1769

    if (gCaseCtrl.checkParamNum) {
      bpCheckParamNum(stmt);
    }
D
stmt  
dapan1121 已提交
1770 1771 1772 1773 1774
    
    for (int32_t b = 0; b <bindTimes; ++b) {
      if (gCurCase->tblNum > 1) {
        char buf[32];
        sprintf(buf, "t%d", t);
D
dapan 已提交
1775
        code = bpSetTableNameTags(&data, t, buf, stmt);
D
stmt  
dapan1121 已提交
1776
        if (code != 0){
D
dapan1121 已提交
1777
          printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1778 1779 1780 1781
          exit(1);
        }  
      }
      
D
dapan1121 已提交
1782
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum, false)) {
D
stmt  
dapan1121 已提交
1783 1784 1785 1786
        exit(1);
      }
      
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1787
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1788 1789 1790 1791
        exit(1);
      }

      if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1792
        printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1793 1794 1795 1796 1797
        exit(1);
      }
    }
  }

D
dapan1121 已提交
1798
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1799 1800 1801
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);
D
stmt  
dapan1121 已提交
1802 1803 1804 1805 1806 1807

  return 0;
}


/* prepare [settbname bind add exec]   */
D
dapan1121 已提交
1808
int insertMBMETest4(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1809
  BindData data = {0};
D
dapan1121 已提交
1810
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1811 1812 1813

  int code = taos_stmt_prepare(stmt, data.sql, 0);
  if (code != 0){
D
dapan1121 已提交
1814
    printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1815 1816 1817
    exit(1);
  }

D
dapan1121 已提交
1818
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1819

D
stmt  
dapan1121 已提交
1820 1821 1822 1823 1824 1825 1826
  int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum;

  for (int32_t b = 0; b <bindTimes; ++b) {
    for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
      if (gCurCase->tblNum > 1) {
        char buf[32];
        sprintf(buf, "t%d", t);
D
dapan 已提交
1827
        code = bpSetTableNameTags(&data, t, buf, stmt);
D
stmt  
dapan1121 已提交
1828
        if (code != 0){
D
dapan1121 已提交
1829
          printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1830 1831 1832 1833
          exit(1);
        }  
      }
    
D
dapan1121 已提交
1834
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum, false)) {
D
stmt  
dapan1121 已提交
1835 1836
        exit(1);
      }
D
stmt  
dapan1121 已提交
1837 1838 1839 1840 1841

      if (gCaseCtrl.checkParamNum) {
        bpCheckParamNum(stmt);
      }
    
D
stmt  
dapan1121 已提交
1842
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1843
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1844 1845 1846 1847
        exit(1);
      }

      if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1848
        printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1849 1850 1851 1852 1853
        exit(1);
      }
    }
  }

D
dapan1121 已提交
1854
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1855 1856 1857 1858 1859 1860 1861 1862
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);

  return 0;
}

/* [prepare [settbname [bind add] exec]]   */
D
dapan1121 已提交
1863
int insertMPMETest1(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1864 1865 1866 1867
  int32_t loop = 0;
  
  while (gCurCase->bindColNum >= 2) {
    BindData data = {0};
D
dapan1121 已提交
1868
    prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1869 1870 1871

    int code = taos_stmt_prepare(stmt, data.sql, 0);
    if (code != 0){
D
dapan1121 已提交
1872
      printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1873 1874 1875
      exit(1);
    }

D
dapan1121 已提交
1876
    bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1877 1878 1879 1880 1881 1882

    int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum;
    for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
      if (gCurCase->tblNum > 1) {
        char buf[32];
        sprintf(buf, "t%d", t);
D
dapan 已提交
1883
        code = bpSetTableNameTags(&data, t, buf, stmt);
D
stmt  
dapan1121 已提交
1884
        if (code != 0){
D
dapan1121 已提交
1885
          printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1886 1887 1888 1889 1890 1891 1892 1893 1894
          exit(1);
        }  
      }

      if (gCaseCtrl.checkParamNum) {
        bpCheckParamNum(stmt);
      }
      
      for (int32_t b = 0; b <bindTimes; ++b) {
D
dapan1121 已提交
1895
        if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum, false)) {
D
stmt  
dapan1121 已提交
1896 1897 1898 1899
          exit(1);
        }
        
        if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1900
          printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1901 1902 1903 1904 1905
          exit(1);
        }
      }

      if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1906
        printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1907 1908 1909 1910
        exit(1);
      }
    }

D
dapan1121 已提交
1911
    bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1912 1913 1914 1915

    destroyData(&data);

    gCurCase->bindColNum -= 2;
D
stmt  
dapan1121 已提交
1916
    gCurCase->fullCol = false;
D
stmt  
dapan1121 已提交
1917 1918 1919 1920 1921 1922 1923
    loop++;
  }

  bpCheckAffectedRows(stmt, loop);

  gExecLoopTimes = loop;
  
D
stmt  
dapan1121 已提交
1924 1925 1926
  return 0;
}

D
dapan 已提交
1927

D
dapan1121 已提交
1928 1929 1930 1931
/* [prepare [settbnametag [bind add] exec]]   */
int insertAUTOTest1(TAOS_STMT *stmt, TAOS *taos) {
  int32_t loop = 0;
  
D
dapan 已提交
1932
  while (gCurCase->bindTagNum > 0 && gCurCase->bindColNum > 0) {
D
dapan1121 已提交
1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948
    BindData data = {0};
    prepareInsertData(&data);

    int code = taos_stmt_prepare(stmt, data.sql, 0);
    if (code != 0){
      printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
      exit(1);
    }

    bpCheckIsInsert(stmt, 1);

    int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum;
    for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
      if (gCurCase->tblNum > 1) {
        char buf[32];
        sprintf(buf, "t%d", t);
D
dapan1121 已提交
1949
        code = bpSetTableNameTags(&data, t, buf, stmt);
D
dapan1121 已提交
1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960
        if (code != 0){
          printf("!!!taos_stmt_set_tbname_tags error:%s\n", taos_stmt_errstr(stmt));
          exit(1);
        }  
      }

      if (gCaseCtrl.checkParamNum) {
        bpCheckParamNum(stmt);
      }
      
      for (int32_t b = 0; b <bindTimes; ++b) {
D
dapan1121 已提交
1961
        if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum, false)) {
D
dapan1121 已提交
1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994
          exit(1);
        }
        
        if (taos_stmt_add_batch(stmt)) {
          printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
          exit(1);
        }
      }

      if (taos_stmt_execute(stmt) != 0) {
        printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
        exit(1);
      }
    }

    bpCheckIsInsert(stmt, 1);

    destroyData(&data);

    gCurCase->bindColNum -= 2;
    gCurCase->bindTagNum -= 2;
    gCurCase->fullCol = false;
    loop++;
  }

  bpCheckAffectedRows(stmt, loop);

  gExecLoopTimes = loop;
  
  return 0;
}


1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027

/* [prepare [settbnametag [bind add exec]]]   */
int insertAUTOTest2(TAOS_STMT *stmt, TAOS *taos) {
  int32_t loop = 0;
  
  while (gCurCase->bindTagNum > 0 && gCurCase->bindColNum > 0) {
    BindData data = {0};
    prepareInsertData(&data);

    int code = taos_stmt_prepare(stmt, data.sql, 0);
    if (code != 0){
      printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
      exit(1);
    }

    bpCheckIsInsert(stmt, 1);

    int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum;
    for (int32_t b = 0; b <bindTimes; ++b) {
      for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
        if (gCurCase->tblNum > 1) {
          char buf[32];
          sprintf(buf, "t%d", t);
          code = bpSetTableNameTags(&data, t, buf, stmt);
          if (code != 0){
            printf("!!!taos_stmt_set_tbname_tags error:%s\n", taos_stmt_errstr(stmt));
            exit(1);
          }  
        }
      
        if (gCaseCtrl.checkParamNum) {
          bpCheckParamNum(stmt);
        }
D
dapan1121 已提交
2028
        if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum, false)) {
2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060
          exit(1);
        }
        
        if (taos_stmt_add_batch(stmt)) {
          printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
          exit(1);
        }
        
        if (taos_stmt_execute(stmt) != 0) {
          printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
          exit(1);
        }
      }
    }

    bpCheckIsInsert(stmt, 1);

    destroyData(&data);

    gCurCase->bindColNum -= 2;
    gCurCase->bindTagNum -= 2;
    gCurCase->fullCol = false;
    loop++;
  }

  bpCheckAffectedRows(stmt, loop);

  gExecLoopTimes = loop;
  
  return 0;
}

D
dapan1121 已提交
2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087
/* normal table [prepare [bind add exec]]   */
int insertAUTOTest3(TAOS_STMT *stmt, TAOS *taos) {
  int32_t loop = 0;
  
  while (gCurCase->bindColNum > 0) {
    BindData data = {0};
    data.singleTbInsert = true;
    prepareInsertData(&data);

    int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum;
    for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
      data.singleTbIdx = t;        
      generateInsertSQL(&data);
      
      int code = taos_stmt_prepare(stmt, data.sql, 0);
      if (code != 0){
        printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
        exit(1);
      }
      
      for (int32_t b = 0; b <bindTimes; ++b) {
        bpCheckIsInsert(stmt, 1);
      
        if (gCaseCtrl.checkParamNum) {
          bpCheckParamNum(stmt);
        }
        
D
dapan1121 已提交
2088
        if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum, false)) {
D
dapan1121 已提交
2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119
          exit(1);
        }
        
        if (taos_stmt_add_batch(stmt)) {
          printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
          exit(1);
        }
        
        if (taos_stmt_execute(stmt) != 0) {
          printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
          exit(1);
        }
      }
    }

    bpCheckIsInsert(stmt, 1);

    destroyData(&data);

    gCurCase->bindColNum -= 2;
    gCurCase->fullCol = false;
    loop++;
  }

  bpCheckAffectedRows(stmt, loop);

  gExecLoopTimes = loop;
  
  return 0;
}

2120

D
dapan1121 已提交
2121
/* select * from table */
D
fix bug  
dapan1121 已提交
2122
int queryColumnTest(TAOS_STMT *stmt, TAOS *taos) {
D
dapan1121 已提交
2123 2124 2125 2126
  BindData data = {0};

  for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
    memset(&data, 0, sizeof(data));
D
dapan1121 已提交
2127
    prepareQueryCondData(&data, t);
D
dapan1121 已提交
2128 2129 2130

    int code = taos_stmt_prepare(stmt, data.sql, 0);
    if (code != 0){
D
dapan1121 已提交
2131
      printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
D
dapan1121 已提交
2132 2133 2134 2135 2136 2137 2138 2139 2140 2141
      exit(1);
    }

    for (int32_t n = 0; n< (gCurCase->rowNum/gCurCase->bindRowNum); ++n) {
      bpCheckIsInsert(stmt, 0);

      if (gCaseCtrl.checkParamNum) {
        bpCheckParamNum(stmt);
      }
      
D
dapan1121 已提交
2142
      if (bpBindParam(stmt, data.pBind + n * gCurCase->bindColNum, false)) {
D
dapan1121 已提交
2143 2144
        exit(1);
      }
D
dapan1121 已提交
2145 2146 2147 2148 2149 2150

      if (rand() % 2 == 0) {
        if (taos_stmt_add_batch(stmt)) {
          printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
          exit(1);
        }
D
dapan1121 已提交
2151 2152 2153
      }

      if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
2154
        printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
dapan1121 已提交
2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168
        exit(1);
      }

      bpCheckQueryResult(stmt, taos, data.sql, data.pBind + n * gCurCase->bindColNum);    
    }
    
    bpCheckIsInsert(stmt, 0);

    destroyData(&data);
  }

  return 0;
}

D
dapan1121 已提交
2169
/* value in query sql */
D
fix bug  
dapan1121 已提交
2170
int queryMiscTest(TAOS_STMT *stmt, TAOS *taos) {
D
dapan1121 已提交
2171 2172 2173 2174
  BindData data = {0};

  for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
    memset(&data, 0, sizeof(data));
D
dapan1121 已提交
2175
    prepareQueryMiscData(&data, t);
D
dapan1121 已提交
2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189

    int code = taos_stmt_prepare(stmt, data.sql, 0);
    if (code != 0){
      printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
      exit(1);
    }

    for (int32_t n = 0; n< (gCurCase->rowNum/gCurCase->bindRowNum); ++n) {
      bpCheckIsInsert(stmt, 0);

      if (gCaseCtrl.checkParamNum) {
        bpCheckParamNum(stmt);
      }
      
D
dapan1121 已提交
2190
      if (bpBindParam(stmt, data.pBind + n * gCurCase->bindColNum, false)) {
D
dapan1121 已提交
2191 2192
        exit(1);
      }
D
dapan1121 已提交
2193 2194 2195 2196 2197 2198

      if (rand() % 2 == 0) {      
        if (taos_stmt_add_batch(stmt)) {
          printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
          exit(1);
        }
D
dapan1121 已提交
2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217
      }

      if (taos_stmt_execute(stmt) != 0) {
        printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
        exit(1);
      }

      bpCheckQueryResult(stmt, taos, data.sql, data.pBind + n * gCurCase->bindColNum);    
    }
    
    bpCheckIsInsert(stmt, 0);

    destroyData(&data);
  }

  return 0;
}


D
dapan1121 已提交
2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256
int insertNonExistsTb(TAOS_STMT *stmt, TAOS *taos) {
  BindData data = {0};
  prepareInsertData(&data);
  
  int code = taos_stmt_prepare(stmt, data.sql, 0);
  if (code != 0){
    printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
    exit(1);
  }

  bpCheckIsInsert(stmt, 1);

  char *buf = "tbnexist";
  code = bpSetTableNameTags(&data, 0, buf, stmt);
  if (code == 0){
    printf("!!!taos_stmt_set_tbname expected error not occurred\n");
    exit(1);
  }  

  if (0 == taos_stmt_bind_param_batch(stmt, data.pBind)) {
    printf("!!!taos_stmt_bind_param_batch expected error not occurred\n");
    exit(1);
  }
  
  if (0 == taos_stmt_add_batch(stmt)) {
    printf("!!!taos_stmt_add_batch expected error not occurred\n");
    exit(1);
  }

  if (0 == taos_stmt_execute(stmt)) {
    printf("!!!taos_stmt_execute expected error not occurred\n");
    exit(1);
  }

  destroyData(&data);

  return 0;
}

D
dapan1121 已提交
2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292
void bpAddWrongVarBuffLen(TAOS_MULTI_BIND* pBind) {
  for (int32_t i = 0; i < gCurCase->bindColNum; ++i) {
    if (pBind[i].buffer_type == TSDB_DATA_TYPE_BINARY || pBind[i].buffer_type == TSDB_DATA_TYPE_NCHAR) {
      *pBind[i].length += 100;
    }
  }
}

int insertVarLenErr(TAOS_STMT *stmt, TAOS *taos) {
  BindData data = {0};
  prepareInsertData(&data);

  int code = taos_stmt_prepare(stmt, data.sql, 0);
  if (code != 0){
    printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
    exit(1);
  }

  bpCheckIsInsert(stmt, 1);

  code = bpSetTableNameTags(&data, 0, "t0", stmt);
  if (code != 0){
    printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
    exit(1);
  }  
  
  bpAddWrongVarBuffLen(data.pBind);

  if (bpBindParam(stmt, data.pBind, true)) {
    exit(1);
  }

  destroyData(&data);

  return 0;
}
D
dapan1121 已提交
2293 2294


D
dapan1121 已提交
2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315
int errorSQLTest1(TAOS_STMT *stmt, TAOS *taos) {
  BindData data = {0};

  for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
    memset(&data, 0, sizeof(data));
    generateErrorSQL(&data, t);

    int code = taos_stmt_prepare(stmt, data.sql, 0);
    if (code != 0){
      printf("*taos_stmt_prepare error as expected, error:%s\n", taos_stmt_errstr(stmt));
    } else {
      printf("!!!taos_stmt_prepare succeed, which should be error\n");
      exit(1);
    }

    destroyData(&data);
  }

  return 0;
}

D
dapan1121 已提交
2316
void prepareCheckResultImpl(TAOS     * taos, char *tname, bool printr, int expected, bool silent) {
D
dapan1121 已提交
2317 2318 2319 2320
  if (TTYPE_INSERT_NG == gCurCase->testType) {
    return;
  }
  
D
dapan1121 已提交
2321 2322 2323
  char sql[255] = "SELECT * FROM ";
  int32_t rows = 0;
  
2324
  strcat(sql, tname);
D
dapan1121 已提交
2325
  bpExecQuery(taos, sql, printr, &rows);
2326 2327
  
  if (rows == expected) {
D
dapan1121 已提交
2328
    if (!silent) {
D
dapan1121 已提交
2329
      printf("***%d rows are fetched as expected from %s\n", rows, tname);
D
dapan1121 已提交
2330
    }
2331
  } else {
D
dapan1121 已提交
2332
    printf("!!!expect rows %d mis-match rows %d fetched from %s\n", expected, rows, tname);
D
dapan1121 已提交
2333
    exit(1);
2334 2335 2336 2337
  }
}


D
dapan1121 已提交
2338
void prepareCheckResult(TAOS     *taos, bool silent) {
D
stmt  
dapan1121 已提交
2339 2340 2341
  char buf[32];
  for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
    if (gCurCase->tblNum > 1) {
D
dapan1121 已提交
2342
      sprintf(buf, "%s%d", bpTbPrefix, t);
D
stmt  
dapan1121 已提交
2343
    } else {
D
dapan1121 已提交
2344
      sprintf(buf, "%s%d", bpTbPrefix, 0);
D
stmt  
dapan1121 已提交
2345 2346
    }

D
dapan1121 已提交
2347
    prepareCheckResultImpl(taos, buf, gCaseCtrl.printRes, gCurCase->duplicateValue ? (gCurCase->rowNum * gExecLoopTimes / 2) : (gCurCase->rowNum * gExecLoopTimes), silent);
D
stmt  
dapan1121 已提交
2348
  }
D
stmt  
dapan1121 已提交
2349 2350

  gExecLoopTimes = 1;
D
stmt  
dapan1121 已提交
2351 2352 2353
}


2354 2355 2356 2357 2358 2359 2360

//120table 60 record each table
int sql_perf1(TAOS     *taos) {
  char *sql[3000] = {0};
  TAOS_RES *result;

  for (int i = 0; i < 3000; i++) {
wafwerar's avatar
wafwerar 已提交
2361
    sql[i] = taosMemoryCalloc(1, 1048576);
2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376
  }

  int len = 0;
  int tss = 0;
  for (int l = 0; l < 3000; ++l) {
    len = sprintf(sql[l], "insert into ");
    for (int t = 0; t < 120; ++t) {
      len += sprintf(sql[l] + len, "m%d values ", t);
      for (int m = 0; m < 60; ++m) {
        len += sprintf(sql[l] + len, "(%d, %d, %d, %d, %d, %d, %f, %f, \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\", \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\") ", tss++, m, m, m, m, m, m+1.0, m+1.0);
      }
    }
  }


D
stmt  
dapan1121 已提交
2377
  int64_t starttime = taosGetTimestampUs();
2378 2379 2380 2381
  for (int i = 0; i < 3000; ++i) {
      result = taos_query(taos, sql[i]);
      int code = taos_errno(result);
      if (code != 0) {
D
dapan1121 已提交
2382
        printf("%d failed to query table, reason:%s\n", taos_errstr(result));
2383 2384 2385 2386 2387 2388
        taos_free_result(result);
        exit(1);
    }

    taos_free_result(result);
  }
D
stmt  
dapan1121 已提交
2389
  int64_t endtime = taosGetTimestampUs();
2390 2391 2392
  printf("insert total %d records, used %u seconds, avg:%.1f useconds\n", 3000*120*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*120*60));

  for (int i = 0; i < 3000; i++) {
wafwerar's avatar
wafwerar 已提交
2393
    taosMemoryFree(sql[i]);
2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404
  }

  return 0;
}





//one table 60 records one time
int sql_perf_s1(TAOS     *taos) {
D
stmt  
dapan1121 已提交
2405
  char **sql = calloc(1, sizeof(char*) * 360000);
2406 2407 2408
  TAOS_RES *result;

  for (int i = 0; i < 360000; i++) {
wafwerar's avatar
wafwerar 已提交
2409
    sql[i] = taosMemoryCalloc(1, 9000);
2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429
  }

  int len = 0;
  int tss = 0;
  int id = 0;
  for (int t = 0; t < 120; ++t) {
    for (int l = 0; l < 3000; ++l) {
      len = sprintf(sql[id], "insert into m%d values ", t);
      for (int m = 0; m < 60; ++m) {
        len += sprintf(sql[id] + len, "(%d, %d, %d, %d, %d, %d, %f, %f, \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\", \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\") ", tss++, m, m, m, m, m, m+1.0, m+1.0);
      }
      if (len >= 9000) {
        printf("sql:%s,len:%d\n", sql[id], len);
        exit(1);
      }
      ++id;
    }
  }


D
stmt  
dapan1121 已提交
2430
  unsigned long long starttime = taosGetTimestampUs();
2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441
  for (int i = 0; i < 360000; ++i) {
      result = taos_query(taos, sql[i]);
      int code = taos_errno(result);
      if (code != 0) {
        printf("failed to query table, reason:%s\n", taos_errstr(result));
        taos_free_result(result);
        exit(1);
    }

    taos_free_result(result);
  }
D
stmt  
dapan1121 已提交
2442
  unsigned long long endtime = taosGetTimestampUs();
2443 2444 2445
  printf("insert total %d records, used %u seconds, avg:%.1f useconds\n", 3000*120*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*120*60));

  for (int i = 0; i < 360000; i++) {
wafwerar's avatar
wafwerar 已提交
2446
    taosMemoryFree(sql[i]);
2447 2448
  }

wafwerar's avatar
wafwerar 已提交
2449
  taosMemoryFree(sql);
2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460

  return 0;
}


//small record size
int sql_s_perf1(TAOS     *taos) {
  char *sql[3000] = {0};
  TAOS_RES *result;

  for (int i = 0; i < 3000; i++) {
wafwerar's avatar
wafwerar 已提交
2461
    sql[i] = taosMemoryCalloc(1, 1048576);
2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476
  }

  int len = 0;
  int tss = 0;
  for (int l = 0; l < 3000; ++l) {
    len = sprintf(sql[l], "insert into ");
    for (int t = 0; t < 120; ++t) {
      len += sprintf(sql[l] + len, "m%d values ", t);
      for (int m = 0; m < 60; ++m) {
        len += sprintf(sql[l] + len, "(%d, %d) ", tss++, m%2);
      }
    }
  }


D
stmt  
dapan1121 已提交
2477
  unsigned long long starttime = taosGetTimestampUs();
2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488
  for (int i = 0; i < 3000; ++i) {
      result = taos_query(taos, sql[i]);
      int code = taos_errno(result);
      if (code != 0) {
        printf("failed to query table, reason:%s\n", taos_errstr(result));
        taos_free_result(result);
        exit(1);
    }

    taos_free_result(result);
  }
D
stmt  
dapan1121 已提交
2489
  unsigned long long endtime = taosGetTimestampUs();
2490 2491 2492
  printf("insert total %d records, used %u seconds, avg:%.1f useconds\n", 3000*120*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*120*60));

  for (int i = 0; i < 3000; i++) {
wafwerar's avatar
wafwerar 已提交
2493
    taosMemoryFree(sql[i]);
2494 2495 2496 2497 2498
  }

  return 0;
}

2499
void generateCreateTableSQL(char *buf, int32_t tblIdx, int32_t colNum, int32_t *colList, int32_t tableType) {
D
stmt  
dapan1121 已提交
2500
  int32_t blen = 0;
2501
  blen = sprintf(buf, "create table %s%d ", (1 == tableType ? bpStbPrefix : bpTbPrefix), tblIdx);
D
stmt  
dapan1121 已提交
2502

2503 2504
  if (tableType == 3) {
    blen += sprintf(buf + blen, "using %s%d", bpStbPrefix, bpDefaultStbId);
D
stmt  
dapan1121 已提交
2505 2506
  }

2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557
  if (tableType == 0 || tableType == 1) {
    blen += sprintf(buf + blen, " (");
    
    for (int c = 0; c < colNum; ++c) {
      if (c > 0) {
        blen += sprintf(buf + blen, ",");
      }
    
      switch (colList[c]) {  
        case TSDB_DATA_TYPE_BOOL:
          blen += sprintf(buf + blen, "booldata bool");
          break;
        case TSDB_DATA_TYPE_TINYINT:
          blen += sprintf(buf + blen, "tinydata tinyint");
          break;
        case TSDB_DATA_TYPE_SMALLINT:
          blen += sprintf(buf + blen, "smalldata smallint");
          break;
        case TSDB_DATA_TYPE_INT:
          blen += sprintf(buf + blen, "intdata int");
          break;
        case TSDB_DATA_TYPE_BIGINT:
          blen += sprintf(buf + blen, "bigdata bigint");
          break;
        case TSDB_DATA_TYPE_FLOAT:
          blen += sprintf(buf + blen, "floatdata float");
          break;
        case TSDB_DATA_TYPE_DOUBLE:
          blen += sprintf(buf + blen, "doubledata double");
          break;
        case TSDB_DATA_TYPE_VARCHAR:
          blen += sprintf(buf + blen, "binarydata binary(%d)", gVarCharSize);
          break;
        case TSDB_DATA_TYPE_TIMESTAMP:
          blen += sprintf(buf + blen, "ts timestamp");
          break;
        case TSDB_DATA_TYPE_NCHAR:
          blen += sprintf(buf + blen, "nchardata nchar(%d)", gVarCharSize);
          break;
        case TSDB_DATA_TYPE_UTINYINT:
          blen += sprintf(buf + blen, "utinydata tinyint unsigned");
          break;
        case TSDB_DATA_TYPE_USMALLINT:
          blen += sprintf(buf + blen, "usmalldata smallint unsigned");
          break;
        case TSDB_DATA_TYPE_UINT:
          blen += sprintf(buf + blen, "uintdata int unsigned");
          break;
        case TSDB_DATA_TYPE_UBIGINT:
          blen += sprintf(buf + blen, "ubigdata bigint unsigned");
          break;
D
Dingle Zhang 已提交
2558 2559 2560
        case TSDB_DATA_TYPE_GEOMETRY:
          blen += sprintf(buf + blen, "geometrydata geometry(%d)", gVarCharSize);
          break;
2561 2562 2563 2564 2565
        default:
          printf("invalid col type:%d", colList[c]);
          exit(1);
      }      
    }
D
stmt  
dapan1121 已提交
2566

2567 2568 2569 2570 2571
    blen += sprintf(buf + blen, ")");
  }
  
  if (1 == tableType) {
    blen += sprintf(buf + blen, " tags (");
D
dapan1121 已提交
2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618
    for (int c = 0; c < colNum; ++c) {
      if (c > 0) {
        blen += sprintf(buf + blen, ",");
      }
      switch (colList[c]) {  
        case TSDB_DATA_TYPE_BOOL:
          blen += sprintf(buf + blen, "tbooldata bool");
          break;
        case TSDB_DATA_TYPE_TINYINT:
          blen += sprintf(buf + blen, "ttinydata tinyint");
          break;
        case TSDB_DATA_TYPE_SMALLINT:
          blen += sprintf(buf + blen, "tsmalldata smallint");
          break;
        case TSDB_DATA_TYPE_INT:
          blen += sprintf(buf + blen, "tintdata int");
          break;
        case TSDB_DATA_TYPE_BIGINT:
          blen += sprintf(buf + blen, "tbigdata bigint");
          break;
        case TSDB_DATA_TYPE_FLOAT:
          blen += sprintf(buf + blen, "tfloatdata float");
          break;
        case TSDB_DATA_TYPE_DOUBLE:
          blen += sprintf(buf + blen, "tdoubledata double");
          break;
        case TSDB_DATA_TYPE_VARCHAR:
          blen += sprintf(buf + blen, "tbinarydata binary(%d)", gVarCharSize);
          break;
        case TSDB_DATA_TYPE_TIMESTAMP:
          blen += sprintf(buf + blen, "tts timestamp");
          break;
        case TSDB_DATA_TYPE_NCHAR:
          blen += sprintf(buf + blen, "tnchardata nchar(%d)", gVarCharSize);
          break;
        case TSDB_DATA_TYPE_UTINYINT:
          blen += sprintf(buf + blen, "tutinydata tinyint unsigned");
          break;
        case TSDB_DATA_TYPE_USMALLINT:
          blen += sprintf(buf + blen, "tusmalldata smallint unsigned");
          break;
        case TSDB_DATA_TYPE_UINT:
          blen += sprintf(buf + blen, "tuintdata int unsigned");
          break;
        case TSDB_DATA_TYPE_UBIGINT:
          blen += sprintf(buf + blen, "tubigdata bigint unsigned");
          break;
D
Dingle Zhang 已提交
2619 2620 2621
        case TSDB_DATA_TYPE_GEOMETRY:
          blen += sprintf(buf + blen, "tgeometrydata geometry(%d)", gVarCharSize);
          break;
D
dapan1121 已提交
2622 2623 2624
        default:
          printf("invalid col type:%d", colList[c]);
          exit(1);
D
Dingle Zhang 已提交
2625
      }
D
dapan1121 已提交
2626 2627
    }

D
Dingle Zhang 已提交
2628
    blen += sprintf(buf + blen, ")");
D
dapan1121 已提交
2629 2630
  }

2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679
  if (3 == tableType) {
    blen += sprintf(buf + blen, " tags (");
    for (int c = 0; c < colNum; ++c) {
      if (c > 0) {
        blen += sprintf(buf + blen, ",");
      }
      switch (colList[c]) {  
        case TSDB_DATA_TYPE_BOOL:
          blen += sprintf(buf + blen, "%s", rand() % 2 ? "true": "false");
          break;
        case TSDB_DATA_TYPE_TINYINT:
          blen += sprintf(buf + blen, "%d", rand() % 128);
          break;
        case TSDB_DATA_TYPE_SMALLINT:
          blen += sprintf(buf + blen, "%d", rand() % 128);
          break;
        case TSDB_DATA_TYPE_INT:
          blen += sprintf(buf + blen, "%d", rand() % 128);
          break;
        case TSDB_DATA_TYPE_BIGINT:
          blen += sprintf(buf + blen, "%d", rand() % 128);
          break;
        case TSDB_DATA_TYPE_FLOAT:
          blen += sprintf(buf + blen, "%f", rand() % 128);
          break;
        case TSDB_DATA_TYPE_DOUBLE:
          blen += sprintf(buf + blen, "%f", rand() % 128);
          break;
        case TSDB_DATA_TYPE_VARCHAR:
          blen += sprintf(buf + blen, "'var%d'", rand() % 128);
          break;
        case TSDB_DATA_TYPE_TIMESTAMP:
          blen += sprintf(buf + blen, "%lld", bpTs);
          break;
        case TSDB_DATA_TYPE_NCHAR:
          blen += sprintf(buf + blen, "'nch%d'", rand() % 128);
          break;
        case TSDB_DATA_TYPE_UTINYINT:
          blen += sprintf(buf + blen, "%d", rand() % 128);
          break;
        case TSDB_DATA_TYPE_USMALLINT:
          blen += sprintf(buf + blen, "%d", rand() % 128);
          break;
        case TSDB_DATA_TYPE_UINT:
          blen += sprintf(buf + blen, "%d", rand() % 128);
          break;
        case TSDB_DATA_TYPE_UBIGINT:
          blen += sprintf(buf + blen, "%d", rand() % 128);
          break;
D
Dingle Zhang 已提交
2680 2681 2682
        case TSDB_DATA_TYPE_GEOMETRY:
          blen += sprintf(buf + blen, "'geo%d'", rand() % 128);
          break;
2683 2684 2685 2686 2687 2688 2689 2690 2691
        default:
          printf("invalid col type:%d", colList[c]);
          exit(1);
      }      
    }

    blen += sprintf(buf + blen, ")");       
  }

D
stmt  
dapan1121 已提交
2692
  if (gCaseCtrl.printCreateTblSql) {
D
dapan1121 已提交
2693
    printf("\tCreate Table SQL:%s\n", buf);
D
stmt  
dapan1121 已提交
2694
  }
D
stmt  
dapan1121 已提交
2695
}
2696

D
dapan1121 已提交
2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726
char *bpPrecisionStr(uint8_t precision) {
  switch (precision) {
    case TIME_PRECISION_MILLI:
      return "ms";
    case TIME_PRECISION_MICRO:
      return "us";
    case TIME_PRECISION_NANO:
      return "ns";
    default:
      return "unknwon";
  }
}

void bpSetStartupTs() {
  switch (gCaseCtrl.precision) {
    case TIME_PRECISION_MILLI:
      bpTs = BP_STARTUP_TS;
      break;
    case TIME_PRECISION_MICRO:
      bpTs = BP_STARTUP_TS * 1000;
      break;
    case TIME_PRECISION_NANO:
      bpTs = BP_STARTUP_TS * 1000000;
      break;
    default:
      bpTs = BP_STARTUP_TS;
      break;
  }
}

D
dapan1121 已提交
2727
void prepare(TAOS     *taos, int32_t colNum, int32_t *colList, int prepareStb) {
2728 2729
  TAOS_RES *result;
  int      code;
D
dapan1121 已提交
2730
  char createDbSql[128] = {0};
2731 2732 2733 2734

  result = taos_query(taos, "drop database demo"); 
  taos_free_result(result);

D
dapan1121 已提交
2735 2736 2737 2738
  sprintf(createDbSql, "create database demo keep 36500 precision \"%s\"", bpPrecisionStr(gCaseCtrl.precision));
  printf("\tCreate Database SQL:%s\n", createDbSql);
  
  result = taos_query(taos, createDbSql);
2739 2740
  code = taos_errno(result);
  if (code != 0) {
D
dapan1121 已提交
2741
    printf("!!!failed to create database, reason:%s\n", taos_errstr(result));
2742 2743 2744 2745 2746 2747 2748 2749
    taos_free_result(result);
    exit(1);
  }
  taos_free_result(result);

  result = taos_query(taos, "use demo");
  taos_free_result(result);

2750
  if (0 == prepareStb) {
2751
    // create table
D
stmt  
dapan1121 已提交
2752
    for (int i = 0 ; i < 10; i++) {
2753
      char buf[1024];
2754
      generateCreateTableSQL(buf, i, colNum, colList, 0);
2755 2756 2757
      result = taos_query(taos, buf);
      code = taos_errno(result);
      if (code != 0) {
D
dapan1121 已提交
2758
        printf("!!!failed to create table, reason:%s\n", taos_errstr(result));
2759 2760 2761 2762 2763 2764
        taos_free_result(result);
        exit(1);
      }
      taos_free_result(result);
    }
  } else {
2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775
    if (1 == prepareStb || 3 == prepareStb) {
      char buf[1024];
      generateCreateTableSQL(buf, bpDefaultStbId, colNum, colList, 1);
      
      result = taos_query(taos, buf);
      code = taos_errno(result);
      if (code != 0) {
        printf("!!!failed to create table, reason:%s\n", taos_errstr(result));
        taos_free_result(result);
        exit(1);
      }
2776 2777
      taos_free_result(result);
    }
2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793

    
    if (3 == prepareStb) {
      for (int i = 0 ; i < 10; i++) {
        char buf[1024];
        generateCreateTableSQL(buf, i, colNum, colList, 3);
        result = taos_query(taos, buf);
        code = taos_errno(result);
        if (code != 0) {
          printf("!!!failed to create table, reason:%s\n", taos_errstr(result));
          taos_free_result(result);
          exit(1);
        }
        taos_free_result(result);
      }
    }
2794 2795 2796 2797
  }

}

D
dapan1121 已提交
2798
int32_t runCase(TAOS *taos, int32_t caseIdx, int32_t caseRunIdx, bool silent) {
D
stmt  
dapan1121 已提交
2799
  TAOS_STMT *stmt = NULL;
D
dapan1121 已提交
2800 2801
  int64_t beginUs, endUs, totalUs;  
  CaseCfg cfg = gCase[caseIdx];
D
dapan1121 已提交
2802
  CaseCfg cfgBk;
D
dapan1121 已提交
2803
  gCurCase = &cfg;
D
dapan1121 已提交
2804 2805

  bpSetStartupTs();
D
dapan1121 已提交
2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818
  
  if ((gCaseCtrl.bindColTypeNum || gCaseCtrl.bindColNum) && (gCurCase->colNum != gFullColNum)) {
    return 1;
  }

  if (gCurCase->preCaseIdx >= 0) {
    bool printRes = gCaseCtrl.printRes;
    bool printStmtSql = gCaseCtrl.printStmtSql;
    gCaseCtrl.printRes = false;
    gCaseCtrl.printStmtSql = false;
    runCase(taos, gCurCase->preCaseIdx, caseRunIdx, true);
    gCaseCtrl.printRes = printRes;
    gCaseCtrl.printStmtSql = printStmtSql;
D
dapan1121 已提交
2819
    
D
stmt  
dapan1121 已提交
2820
    gCurCase = &cfg;
D
dapan1121 已提交
2821 2822 2823 2824 2825 2826 2827 2828 2829
  }
  
  if (gCaseCtrl.runTimes) {
    gCurCase->runTimes = gCaseCtrl.runTimes;
  }
  
  if (gCaseCtrl.rowNum) {
    gCurCase->rowNum = gCaseCtrl.rowNum;
  }
D
dapan 已提交
2830 2831 2832

  if (gCaseCtrl.autoCreateTbl) {
    if (gCurCase->testType == TTYPE_INSERT && gCurCase->tblNum > 1) {
2833
      gCurCase->autoCreateTbl = 1;
D
dapan 已提交
2834 2835 2836 2837 2838 2839 2840
      if (gCurCase->bindTagNum <= 0) {
        gCurCase->bindTagNum = gCurCase->colNum;
      }
    } else {
      return 1;
    }
  }
D
dapan1121 已提交
2841 2842 2843
  
  if (gCurCase->fullCol) {
    gCurCase->bindColNum = gCurCase->colNum;
D
dapan 已提交
2844 2845 2846
    if (gCurCase->autoCreateTbl) {
      gCurCase->bindTagNum = gCurCase->colNum;
    }
D
dapan1121 已提交
2847 2848 2849 2850 2851 2852 2853
  }
  
  gCurCase->bindNullNum = gCaseCtrl.bindNullNum;
  if (gCaseCtrl.bindColNum) {
    gCurCase->bindColNum = gCaseCtrl.bindColNum;
    gCurCase->fullCol = false;
  }
D
dapan1121 已提交
2854 2855 2856 2857
  if (gCaseCtrl.bindTagNum) {
    gCurCase->bindTagNum = gCaseCtrl.bindTagNum;
    gCurCase->fullCol = false;
  }
D
dapan1121 已提交
2858 2859 2860 2861 2862 2863 2864
  if (gCaseCtrl.bindRowNum) {
    gCurCase->bindRowNum = gCaseCtrl.bindRowNum;
  }
  if (gCaseCtrl.bindColTypeNum) {
    gCurCase->bindColNum = gCaseCtrl.bindColTypeNum;
    gCurCase->fullCol = false;
  }
D
dapan1121 已提交
2865 2866 2867 2868
  if (gCaseCtrl.bindTagTypeNum) {
    gCurCase->bindTagNum = gCaseCtrl.bindTagTypeNum;
    gCurCase->fullCol = false;
  }
D
stmt  
dapan1121 已提交
2869

D
dapan1121 已提交
2870 2871 2872 2873 2874
  if (!silent) {
    printf("* Case %d - [%s]%s Begin *\n", caseRunIdx, gCaseCtrl.caseCatalog, gCurCase->caseDesc);
  }
  
  totalUs = 0;
D
dapan1121 已提交
2875
  cfgBk = cfg;
D
dapan1121 已提交
2876 2877
  for (int32_t n = 0; n < gCurCase->runTimes; ++n) {
    if (gCurCase->preCaseIdx < 0) {
D
dapan 已提交
2878
      prepare(taos, gCurCase->colNum, gCurCase->colList, gCurCase->autoCreateTbl);
D
stmt  
dapan1121 已提交
2879 2880
    }
    
D
dapan1121 已提交
2881 2882 2883 2884
    beginUs = taosGetTimestampUs();
   
    stmt = taos_stmt_init(taos);
    if (NULL == stmt) {
D
dapan1121 已提交
2885
      printf("!!!taos_stmt_init failed, error:%s\n", taos_stmt_errstr(stmt));
D
dapan1121 已提交
2886
      exit(1);
D
stmt  
dapan1121 已提交
2887
    }
D
dapan1121 已提交
2888 2889 2890 2891 2892 2893 2894
  
    (*gCurCase->runFn)(stmt, taos);
  
    taos_stmt_close(stmt);
  
    endUs = taosGetTimestampUs();
    totalUs += (endUs - beginUs);
D
dapan1121 已提交
2895

D
dapan1121 已提交
2896
    prepareCheckResult(taos, silent);
D
dapan1121 已提交
2897 2898

    cfg = cfgBk;
D
dapan1121 已提交
2899
  }
D
dapan1121 已提交
2900

D
dapan1121 已提交
2901 2902 2903 2904 2905 2906
  if (!silent) {  
    printf("* Case %d - [%s]%s [AvgTime:%.3fms] End *\n", caseRunIdx, gCaseCtrl.caseCatalog, gCurCase->caseDesc, ((double)totalUs)/1000/gCurCase->runTimes);
  }
  
  return 0;
}
D
dapan1121 已提交
2907

D
dapan1121 已提交
2908 2909 2910 2911 2912
void* runCaseList(TAOS *taos) {
  static int32_t caseRunIdx = 0;
  static int32_t caseRunNum = 0;
  int32_t caseNum = 0;
  int32_t caseIdx = (gCaseCtrl.caseIdx >= 0) ? gCaseCtrl.caseIdx : 0;
2913

D
dapan1121 已提交
2914 2915 2916 2917
  for (int32_t i = caseIdx; i < sizeof(gCase)/sizeof(gCase[0]); ++i) {
    if (gCaseCtrl.caseNum > 0 && caseNum >= gCaseCtrl.caseNum) {
      break;
    }
2918

D
dapan1121 已提交
2919 2920 2921
    if (gCaseCtrl.caseRunNum > 0 && caseRunNum >= gCaseCtrl.caseRunNum) {
      break;
    }
D
dapan1121 已提交
2922

D
dapan1121 已提交
2923 2924 2925 2926
    if (gCaseCtrl.caseRunIdx >= 0 && caseRunIdx < gCaseCtrl.caseRunIdx) {
      caseRunIdx++;
      continue;
    }
D
dapan1121 已提交
2927

D
dapan1121 已提交
2928 2929
    if (runCase(taos, i, caseRunIdx, false)) {
      continue;
2930
    }
D
stmt  
dapan1121 已提交
2931

D
dapan1121 已提交
2932 2933
    caseRunIdx++;
    caseNum++;
D
dapan1121 已提交
2934
    caseRunNum++;
D
stmt  
dapan1121 已提交
2935
  }
2936

D
stmt  
dapan1121 已提交
2937 2938
  return NULL;
}
D
stmt  
dapan1121 已提交
2939

D
stmt  
dapan1121 已提交
2940
void runAll(TAOS *taos) {
D
dapan1121 已提交
2941
  strcpy(gCaseCtrl.caseCatalog, "Default Test");
D
dapan1121 已提交
2942
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
dapan1121 已提交
2943
  runCaseList(taos);
D
dapan 已提交
2944

2945
#if 1
D
dapan1121 已提交
2946 2947 2948 2949 2950
  strcpy(gCaseCtrl.caseCatalog, "Micro DB precision Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
  gCaseCtrl.precision = TIME_PRECISION_MICRO;
  runCaseList(taos);
  gCaseCtrl.precision = TIME_PRECISION_MILLI;
D
dapan1121 已提交
2951

D
dapan1121 已提交
2952 2953 2954 2955 2956 2957
  strcpy(gCaseCtrl.caseCatalog, "Nano DB precision Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
  gCaseCtrl.precision = TIME_PRECISION_NANO;
  runCaseList(taos);
  gCaseCtrl.precision = TIME_PRECISION_MILLI;
  
D
dapan 已提交
2958 2959 2960 2961 2962
  strcpy(gCaseCtrl.caseCatalog, "Auto Create Table Test");
  gCaseCtrl.autoCreateTbl = true;
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
  runCaseList(taos);
  gCaseCtrl.autoCreateTbl = false;
D
stmt  
dapan1121 已提交
2963

D
dapan1121 已提交
2964 2965
  strcpy(gCaseCtrl.caseCatalog, "Null Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
2966
  gCaseCtrl.bindNullNum = 1;
D
dapan1121 已提交
2967
  runCaseList(taos);
D
stmt  
dapan1121 已提交
2968
  gCaseCtrl.bindNullNum = 0;
D
stmt  
dapan1121 已提交
2969

D
dapan1121 已提交
2970 2971
  strcpy(gCaseCtrl.caseCatalog, "Bind Row Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
2972
  gCaseCtrl.bindRowNum = 1;
D
dapan1121 已提交
2973
  runCaseList(taos);
D
stmt  
dapan1121 已提交
2974
  gCaseCtrl.bindRowNum = 0;
D
stmt  
dapan1121 已提交
2975

D
dapan1121 已提交
2976 2977
  strcpy(gCaseCtrl.caseCatalog, "Row Num Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
2978
  gCaseCtrl.rowNum = 1000;
D
stmt  
dapan1121 已提交
2979
  gCaseCtrl.printRes = false;
D
dapan1121 已提交
2980
  runCaseList(taos);
D
stmt  
dapan1121 已提交
2981 2982
  gCaseCtrl.rowNum = 0;
  gCaseCtrl.printRes = true;
D
stmt  
dapan1121 已提交
2983

D
dapan1121 已提交
2984 2985
  strcpy(gCaseCtrl.caseCatalog, "Runtimes Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
2986
  gCaseCtrl.runTimes = 2;
D
dapan1121 已提交
2987
  runCaseList(taos);
D
stmt  
dapan1121 已提交
2988
  gCaseCtrl.runTimes = 0;
2989

D
dapan1121 已提交
2990 2991
  strcpy(gCaseCtrl.caseCatalog, "Check Param Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
2992
  gCaseCtrl.checkParamNum = true;
D
dapan1121 已提交
2993
  runCaseList(taos);
D
stmt  
dapan1121 已提交
2994
  gCaseCtrl.checkParamNum = false;
2995

D
dapan1121 已提交
2996 2997
  strcpy(gCaseCtrl.caseCatalog, "Bind Col Num Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
2998
  gCaseCtrl.bindColNum = 6;
D
dapan1121 已提交
2999
  runCaseList(taos);
D
stmt  
dapan1121 已提交
3000
  gCaseCtrl.bindColNum = 0;
3001

D
dapan1121 已提交
3002 3003
#endif

D
dapan1121 已提交
3004
/*
D
dapan1121 已提交
3005 3006
  strcpy(gCaseCtrl.caseCatalog, "Bind Col Type Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
3007
  gCaseCtrl.bindColTypeNum = tListLen(bindColTypeList);
D
stmt  
dapan1121 已提交
3008
  gCaseCtrl.bindColTypeList = bindColTypeList;  
D
dapan1121 已提交
3009
  runCaseList(taos);
D
dapan1121 已提交
3010
*/
D
dapan 已提交
3011

D
dapan1121 已提交
3012
  printf("All Test End\n");  
3013 3014 3015 3016
}

int main(int argc, char *argv[])
{
D
stmt  
dapan1121 已提交
3017
  TAOS     *taos = NULL;
3018

D
dapan1121 已提交
3019
  srand((unsigned int)time(NULL));
D
stmt  
dapan1121 已提交
3020
  
3021 3022 3023 3024 3025 3026
  // connect to server
  if (argc < 2) {
    printf("please input server ip \n");
    return 0;
  }

D
stmt  
dapan1121 已提交
3027
  taos = taos_connect(argv[1], "root", "taosdata", NULL, 0);
3028 3029 3030 3031 3032
  if (taos == NULL) {
    printf("failed to connect to db, reason:%s\n", taos_errstr(taos));
    exit(1);
  }   

D
stmt  
dapan1121 已提交
3033
  runAll(taos);
3034

D
dapan1121 已提交
3035 3036
  taos_close(taos);

3037 3038 3039
  return 0;
}