batchprepare.c 73.0 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 13
#define FUNCTION_TEST_IDX 1

D
stmt  
dapan1121 已提交
14 15
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 已提交
16
int32_t bindColTypeList[] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_INT};
D
dapan1121 已提交
17
int32_t optrIdxList[] = {0, 7};
D
dapan1121 已提交
18 19 20 21 22 23 24

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

D
dapan1121 已提交
25 26 27 28 29
typedef struct {
  char*   funcName;
  int32_t paramNum;
} FuncInfo;

D
dapan1121 已提交
30 31 32 33 34
typedef enum {
  BP_BIND_TAG = 1,
  BP_BIND_COL,
} BP_BIND_TYPE;

D
dapan1121 已提交
35 36 37 38 39 40 41 42 43 44 45 46 47
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 已提交
48
  {"nmatch",   2, false},  
D
dapan1121 已提交
49 50 51 52 53
};

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 已提交
54 55 56 57 58 59
FuncInfo funcInfo[] = {
  {"count", 1},
  {"sum",   1},
  {"min",   1},
};

D
dapan1121 已提交
60 61
char *bpStbPrefix = "st";
char *bpTbPrefix = "t";
D
dapan1121 已提交
62 63
int32_t bpDefaultStbId = 1;

D
dapan1121 已提交
64 65 66 67


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

#define tListLen(x) (sizeof(x) / sizeof((x)[0]))
D
dapan1121 已提交
70 71 72 73
#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 已提交
74

75
typedef struct {
D
stmt  
dapan1121 已提交
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
  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 已提交
91
  TAOS_MULTI_BIND* pBind;
D
dapan1121 已提交
92
  TAOS_MULTI_BIND* pTags;
D
stmt  
dapan1121 已提交
93 94 95 96 97 98 99 100
  char*         sql;
  int32_t*      colTypes;
  int32_t       colNum;
} BindData;

int32_t gVarCharSize = 10;
int32_t gVarCharLen = 5;

D
stmt  
dapan1121 已提交
101
int32_t gExecLoopTimes = 1; // no change
D
stmt  
dapan1121 已提交
102
int32_t gFullColNum = tListLen(fullColList);
D
stmt  
dapan1121 已提交
103

D
dapan1121 已提交
104 105 106 107 108 109 110
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 已提交
111
int insertAUTOTest1(TAOS_STMT *stmt, TAOS *taos);
D
fix bug  
dapan1121 已提交
112 113
int queryColumnTest(TAOS_STMT *stmt, TAOS *taos);
int queryMiscTest(TAOS_STMT *stmt, TAOS *taos);
D
dapan1121 已提交
114 115 116 117 118

enum {
  TTYPE_INSERT = 1,
  TTYPE_QUERY,
};
D
stmt  
dapan1121 已提交
119 120 121 122

typedef struct {
  char     caseDesc[128];
  int32_t  colNum;
D
stmt  
dapan1121 已提交
123
  int32_t *colList;         // full table column list
D
dapan1121 已提交
124
  int32_t  testType;     
D
dapan 已提交
125
  bool     autoCreateTbl;
D
stmt  
dapan1121 已提交
126
  bool     fullCol;
D
dapan1121 已提交
127
  int32_t  (*runFn)(TAOS_STMT*, TAOS*);
D
stmt  
dapan1121 已提交
128 129 130
  int32_t  tblNum;
  int32_t  rowNum;
  int32_t  bindRowNum;
D
stmt  
dapan1121 已提交
131
  int32_t  bindColNum;      // equal colNum in full column case
D
dapan1121 已提交
132
  int32_t  bindTagNum;      // equal colNum in full column case
D
stmt  
dapan1121 已提交
133 134
  int32_t  bindNullNum;
  int32_t  runTimes;
D
dapan1121 已提交
135
  int32_t  preCaseIdx;
D
stmt  
dapan1121 已提交
136 137 138
} CaseCfg;

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

D
dapan1121 已提交
142 143 144
  {"insert:MBSE1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBSETest1, 10, 10, 2, 0, 0, 0, 1, -1},
  {"insert:MBSE1-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBSETest1, 10, 10, 2, 12, 0, 0, 1, -1},
  {"insert:MBSE1-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBSETest1, 10, 10, 2, 2, 0, 0, 1, -1},
D
dapan1121 已提交
145

D
dapan1121 已提交
146 147 148
  {"insert:MBSE2-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBSETest2, 10, 10, 2, 0, 0, 0, 1, -1},
  {"insert:MBSE2-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBSETest2, 10, 10, 2, 12, 0, 0, 1, -1},
  {"insert:MBSE2-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBSETest2, 10, 10, 2, 2, 0, 0, 1, -1},
D
stmt  
dapan1121 已提交
149

D
dapan1121 已提交
150 151 152
  {"insert:MBME1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBMETest1, 10, 10, 2, 0, 0, 0, 1, -1},
  {"insert:MBME1-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest1, 10, 10, 2, 12, 0, 0, 1, -1},
  {"insert:MBME1-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest1, 10, 10, 2, 2, 0, 0, 1, -1},
D
stmt  
dapan1121 已提交
153

D
dapan1121 已提交
154
  // 11
D
dapan1121 已提交
155 156 157
  {"insert:MBME2-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBMETest2, 10, 10, 2, 0, 0, 0, 1, -1},
  {"insert:MBME2-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest2, 10, 10, 2, 12, 0, 0, 1, -1},
  {"insert:MBME2-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest2, 10, 10, 2, 2, 0, 0, 1, -1},
D
stmt  
dapan1121 已提交
158

D
dapan1121 已提交
159 160 161
  {"insert:MBME3-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBMETest3, 10, 10, 2, 0, 0, 0, 1, -1},
  {"insert:MBME3-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest3, 10, 10, 2, 12, 0, 0, 1, -1},
  {"insert:MBME3-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest3, 10, 10, 2, 2, 0, 0, 1, -1},
D
stmt  
dapan1121 已提交
162

D
dapan1121 已提交
163 164 165
  {"insert:MBME4-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBMETest4, 10, 10, 2, 0, 0, 0, 1, -1},
  {"insert:MBME4-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest4, 10, 10, 2, 12, 0, 0, 1, -1},
  {"insert:MBME4-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest4, 10, 10, 2, 2, 0, 0, 1, -1},
D
stmt  
dapan1121 已提交
166

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

D
dapan1121 已提交
170
  // 22
D
dapan1121 已提交
171 172
  {"insert:AUTO1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, true, true, insertAUTOTest1, 10, 10, 2, 0, 0, 0, 1, -1},

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

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

D
stmt  
dapan1121 已提交
179 180 181
};

CaseCfg *gCurCase = NULL;
D
stmt  
dapan1121 已提交
182 183

typedef struct {
D
dapan1121 已提交
184
  char     caseCatalog[255];
D
stmt  
dapan1121 已提交
185 186
  int32_t  bindNullNum;
  bool     checkParamNum;
D
stmt  
dapan1121 已提交
187
  bool     printRes;
D
stmt  
dapan1121 已提交
188
  bool     printCreateTblSql;
D
dapan1121 已提交
189 190
  bool     printQuerySql;
  bool     printStmtSql;
D
dapan 已提交
191
  bool     autoCreateTbl;
D
dapan1121 已提交
192
  bool     numericParam;
D
stmt  
dapan1121 已提交
193
  int32_t  rowNum;               //row num for one table
D
stmt  
dapan1121 已提交
194
  int32_t  bindColNum;
D
dapan1121 已提交
195
  int32_t  bindTagNum;
D
stmt  
dapan1121 已提交
196
  int32_t  bindRowNum;           //row num for once bind
D
stmt  
dapan1121 已提交
197 198
  int32_t  bindColTypeNum;
  int32_t* bindColTypeList;
D
dapan1121 已提交
199 200
  int32_t  bindTagTypeNum;
  int32_t* bindTagTypeList;
D
dapan1121 已提交
201 202
  int32_t  optrIdxListNum;
  int32_t* optrIdxList;
D
dapan1121 已提交
203 204
  int32_t  funcIdxListNum;
  int32_t* funcIdxList;
D
stmt  
dapan1121 已提交
205
  int32_t  runTimes;
D
dapan1121 已提交
206 207 208 209
  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 已提交
210 211
} CaseCtrl;

D
dapan1121 已提交
212
#if 1
D
dapan1121 已提交
213
CaseCtrl gCaseCtrl = { // default
D
dapan1121 已提交
214 215 216 217
  .bindNullNum = 0,
  .printCreateTblSql = false,
  .printQuerySql = true,
  .printStmtSql = true,
D
dapan 已提交
218
  .autoCreateTbl = false,
D
dapan1121 已提交
219
  .numericParam = false,
D
dapan 已提交
220 221 222 223 224 225 226 227 228 229
  .rowNum = 0,
  .bindColNum = 0,
  .bindTagNum = 0,
  .bindRowNum = 0,
  .bindColTypeNum = 0,
  .bindColTypeList = NULL,
  .bindTagTypeNum = 0,
  .bindTagTypeList = NULL,
  .optrIdxListNum = 0,
  .optrIdxList = NULL,
D
dapan1121 已提交
230 231
  .funcIdxListNum = 0,
  .funcIdxList = NULL,
D
dapan 已提交
232
  .checkParamNum = false,
D
dapan1121 已提交
233
  .printRes = false,
D
dapan 已提交
234 235 236 237 238 239 240 241 242
  .runTimes = 0,
  .caseIdx = -1,
  .caseNum = -1,
  .caseRunIdx = -1,
  .caseRunNum = -1,
};
#endif


D
dapan1121 已提交
243
#if 0
D
dapan 已提交
244
CaseCtrl gCaseCtrl = {
D
dapan 已提交
245 246 247 248 249
  .bindNullNum = 0,
  .printCreateTblSql = true,
  .printQuerySql = true,
  .printStmtSql = true,
  .autoCreateTbl = false,
D
dapan1121 已提交
250 251
  .rowNum = 0,
  .bindColNum = 0,
D
dapan1121 已提交
252
  .bindTagNum = 0,
D
dapan1121 已提交
253
  .bindRowNum = 0,
D
dapan1121 已提交
254 255
  .bindTagTypeNum = 0,
  .bindTagTypeList = NULL,
D
dapan1121 已提交
256
  .checkParamNum = false,
D
dapan 已提交
257
  .printRes = false,
D
dapan1121 已提交
258
  .runTimes = 0,
D
dapan1121 已提交
259
  .caseIdx = 1,
D
dapan1121 已提交
260
  .caseNum = 1,
D
dapan1121 已提交
261
  .caseRunIdx = -1,
D
dapan1121 已提交
262
  .caseRunNum = 1,
D
dapan1121 已提交
263 264
};
#endif
D
dapan1121 已提交
265

D
dapan1121 已提交
266
#if 0
D
dapan1121 已提交
267
CaseCtrl gCaseCtrl = {  // query case with specified col&oper
D
dapan1121 已提交
268
  .bindNullNum = 1,
D
dapan1121 已提交
269 270 271 272 273 274
  .printCreateTblSql = false,
  .printQuerySql = true,
  .printStmtSql = true,
  .rowNum = 0,
  .bindColNum = 0,
  .bindRowNum = 0,
D
dapan1121 已提交
275 276 277 278
  .optrIdxListNum = tListLen(optrIdxList),
  .optrIdxList = optrIdxList,
  .bindColTypeNum = tListLen(bindColTypeList),
  .bindColTypeList = bindColTypeList,
D
dapan1121 已提交
279
  .checkParamNum = false,
D
dapan1121 已提交
280
  .printRes = true,
D
dapan1121 已提交
281 282
  .runTimes = 0,
  .caseRunIdx = -1,
D
dapan1121 已提交
283
  .caseIdx = 23,
D
dapan1121 已提交
284 285 286
  .caseNum = 1,
  .caseRunNum = 1,
};
D
dapan1121 已提交
287 288
#endif

D
dapan 已提交
289
#if 0
D
dapan1121 已提交
290
CaseCtrl gCaseCtrl = {  // query case with specified col&oper
D
dapan1121 已提交
291
  .bindNullNum = 1,
D
dapan1121 已提交
292
  .printCreateTblSql = true,
D
dapan1121 已提交
293 294
  .printQuerySql = true,
  .printStmtSql = true,
D
dapan 已提交
295
  .autoCreateTbl = true,
D
stmt  
dapan1121 已提交
296
  .rowNum = 0,
D
stmt  
dapan1121 已提交
297
  .bindColNum = 0,
D
dapan 已提交
298
  .bindTagNum = 0,
D
stmt  
dapan1121 已提交
299
  .bindRowNum = 0,
D
dapan1121 已提交
300 301 302 303
  .bindColTypeNum = 0,
  .bindColTypeList = NULL,
  .optrIdxListNum = 0,
  .optrIdxList = NULL,
D
fix bug  
dapan1121 已提交
304
  .checkParamNum = false,
D
stmt  
dapan1121 已提交
305 306
  .printRes = true,
  .runTimes = 0,
D
dapan1121 已提交
307
  .caseRunIdx = -1,
D
dapan1121 已提交
308 309 310 311
  //.optrIdxListNum = tListLen(optrIdxList),
  //.optrIdxList = optrIdxList,
  //.bindColTypeNum = tListLen(bindColTypeList),
  //.bindColTypeList = bindColTypeList,
D
dapan1121 已提交
312
  .caseIdx = 24,
D
dapan1121 已提交
313
  .caseNum = 1,
D
dapan1121 已提交
314
  .caseRunNum = 1,
D
stmt  
dapan1121 已提交
315
};
D
dapan1121 已提交
316 317
#endif

D
stmt  
dapan1121 已提交
318 319
int32_t taosGetTimeOfDay(struct timeval *tv) {
  return gettimeofday(tv, NULL);
320
}
D
stmt  
dapan1121 已提交
321
void *taosMemoryMalloc(uint64_t size) {
D
stmt  
dapan1121 已提交
322 323 324
  return malloc(size);
}

D
stmt  
dapan1121 已提交
325 326 327 328 329
void *taosMemoryCalloc(int32_t num, int32_t size) {
  return calloc(num, size);
}
void taosMemoryFree(const void *ptr) {
  if (ptr == NULL) return;
330

D
stmt  
dapan1121 已提交
331 332
  return free((void*)ptr);
}
333

D
stmt  
dapan1121 已提交
334 335 336 337 338 339
static int64_t taosGetTimestampMs() {
  struct timeval systemTime;
  taosGetTimeOfDay(&systemTime);
  return (int64_t)systemTime.tv_sec * 1000L + (int64_t)systemTime.tv_usec/1000;
}

D
stmt  
dapan1121 已提交
340 341 342 343 344
static int64_t taosGetTimestampUs() {
  struct timeval systemTime;
  taosGetTimeOfDay(&systemTime);
  return (int64_t)systemTime.tv_sec * 1000000L + (int64_t)systemTime.tv_usec;
}
345

D
dapan1121 已提交
346
bool colExists(TAOS_MULTI_BIND* pBind, int32_t dataType) {
D
stmt  
dapan1121 已提交
347 348 349 350 351 352 353 354 355
  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 已提交
356

D
stmt  
dapan1121 已提交
357 358 359 360
    ++i;
  }
}

D
stmt  
dapan1121 已提交
361
void generateInsertSQL(BindData *data) {
D
dapan1121 已提交
362 363 364 365 366 367
  int32_t len = 0;
  if (gCurCase->tblNum > 1) {
    len = sprintf(data->sql, "insert into ? ");
  } else {
    len = sprintf(data->sql, "insert into %s0 ", bpTbPrefix);
  }
D
dapan1121 已提交
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 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

  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;
          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 已提交
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489
  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;
        default:
D
dapan1121 已提交
490
          printf("!!!invalid col type:%d", data->pBind[c].buffer_type);
D
stmt  
dapan1121 已提交
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505
          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 已提交
506

D
dapan1121 已提交
507
  if (gCaseCtrl.printStmtSql) {
D
dapan1121 已提交
508
    printf("\tSQL: %s\n", data->sql);
D
stmt  
dapan1121 已提交
509
  }  
D
stmt  
dapan1121 已提交
510
}
D
stmt  
dapan1121 已提交
511

D
dapan1121 已提交
512
void bpAppendOperatorParam(BindData *data, int32_t *len, int32_t dataType, int32_t idx) {
D
dapan1121 已提交
513
  OperInfo *pInfo = NULL;
D
dapan1121 已提交
514 515 516

  if (gCaseCtrl.optrIdxListNum > 0) {
    pInfo = &operInfo[gCaseCtrl.optrIdxList[idx]];
D
dapan1121 已提交
517
  } else {
D
dapan1121 已提交
518 519 520 521 522
    if (TSDB_DATA_TYPE_VARCHAR == dataType || TSDB_DATA_TYPE_NCHAR == dataType) {
      pInfo = &operInfo[varoperatorList[rand() % tListLen(varoperatorList)]];
    } else {
      pInfo = &operInfo[operatorList[rand() % tListLen(operatorList)]];
    }
D
dapan1121 已提交
523
  }
D
dapan1121 已提交
524
  
D
dapan1121 已提交
525 526 527 528 529 530 531 532 533
  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 已提交
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 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
      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;
    default:
      printf("!!!invalid col type:%d", type);
D
dapan1121 已提交
605 606
      exit(1);
  }
D
dapan1121 已提交
607 608

  return 0;
D
dapan1121 已提交
609 610
}

D
dapan1121 已提交
611
void generateQueryCondSQL(BindData *data, int32_t tblIdx) {
D
dapan1121 已提交
612 613 614 615 616 617
  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 已提交
618
      len += bpAppendColumnName(data, data->pBind[c].buffer_type, len);
D
dapan1121 已提交
619
      
D
dapan1121 已提交
620
      bpAppendOperatorParam(data, &len, data->pBind[c].buffer_type, c);
D
dapan1121 已提交
621 622 623 624
    }
  }

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

D
dapan1121 已提交
629 630 631 632 633 634 635 636 637 638 639 640 641
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 已提交
642

D
dapan1121 已提交
643 644 645 646 647 648 649 650 651 652 653
  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 已提交
654
    }
D
dapan1121 已提交
655 656 657 658 659 660 661 662 663
    
    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 已提交
664 665 666 667 668 669 670 671 672 673
  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 已提交
674 675 676 677 678 679 680 681
  }

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


682

D
dapan1121 已提交
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705
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 已提交
706

D
dapan1121 已提交
707
void generateColDataType(BindData *data, int32_t bindIdx, int32_t colIdx, int32_t *dataType) {
D
stmt  
dapan1121 已提交
708
  if (bindIdx < gCurCase->bindColNum) {
D
stmt  
dapan1121 已提交
709
    if (gCaseCtrl.bindColTypeNum) {
D
stmt  
dapan1121 已提交
710 711
      *dataType = gCaseCtrl.bindColTypeList[colIdx];
      return;
D
stmt  
dapan1121 已提交
712 713 714
    } else if (gCurCase->fullCol) {
      *dataType = gCurCase->colList[bindIdx];
      return;
D
dapan1121 已提交
715 716 717 718 719 720 721 722 723 724
    } 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 已提交
725 726 727 728
    } else if (0 == colIdx) {
      *dataType = TSDB_DATA_TYPE_TIMESTAMP;
      return;
    } else {
D
stmt  
dapan1121 已提交
729 730 731 732 733 734 735
      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 已提交
736

D
stmt  
dapan1121 已提交
737 738 739 740 741 742 743 744 745 746 747 748
        if (colExists(data->pBind, *dataType)) {
          continue;
        }
        
        break;
      }
    }
  } else {
    *dataType = data->pBind[bindIdx%gCurCase->bindColNum].buffer_type;
  }
}

D
dapan1121 已提交
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779
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 已提交
780
  int32_t dataType = TSDB_DATA_TYPE_TIMESTAMP;
D
dapan1121 已提交
781 782 783 784 785 786 787 788 789
  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 已提交
790 791 792 793


  switch (dataType) {  
    case TSDB_DATA_TYPE_BOOL:
D
dapan1121 已提交
794 795 796 797
      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 已提交
798 799
      break;
    case TSDB_DATA_TYPE_TINYINT:
D
dapan1121 已提交
800 801 802 803
      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 已提交
804 805
      break;
    case TSDB_DATA_TYPE_SMALLINT:
D
dapan1121 已提交
806 807 808 809
      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 已提交
810 811
      break;
    case TSDB_DATA_TYPE_INT:
D
dapan1121 已提交
812 813 814 815
      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 已提交
816 817
      break;
    case TSDB_DATA_TYPE_BIGINT:
D
dapan1121 已提交
818 819 820 821
      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 已提交
822 823
      break;
    case TSDB_DATA_TYPE_FLOAT:
D
dapan1121 已提交
824 825 826 827
      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 已提交
828 829
      break;
    case TSDB_DATA_TYPE_DOUBLE:
D
dapan1121 已提交
830 831 832 833
      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 已提交
834 835
      break;
    case TSDB_DATA_TYPE_VARCHAR:
D
dapan1121 已提交
836 837 838 839
      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 已提交
840 841
      break;
    case TSDB_DATA_TYPE_TIMESTAMP:
D
dapan1121 已提交
842 843 844 845
      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 已提交
846 847
      break;
    case TSDB_DATA_TYPE_NCHAR:
D
dapan1121 已提交
848 849 850 851
      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 已提交
852 853
      break;
    case TSDB_DATA_TYPE_UTINYINT:
D
dapan1121 已提交
854 855 856 857
      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 已提交
858 859
      break;
    case TSDB_DATA_TYPE_USMALLINT:
D
dapan1121 已提交
860 861 862 863
      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 已提交
864 865
      break;
    case TSDB_DATA_TYPE_UINT:
D
dapan1121 已提交
866 867 868 869
      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 已提交
870 871
      break;
    case TSDB_DATA_TYPE_UBIGINT:
D
dapan1121 已提交
872 873 874 875
      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 已提交
876 877
      break;
    default:
D
dapan1121 已提交
878
      printf("!!!invalid col type:%d", dataType);
D
stmt  
dapan1121 已提交
879 880 881
      exit(1);
  }

D
dapan1121 已提交
882 883
  pBase[bindIdx].buffer_type = dataType;
  pBase[bindIdx].num = gCurCase->bindRowNum;
D
stmt  
dapan1121 已提交
884

D
dapan1121 已提交
885 886 887 888
  if (bType == BP_BIND_TAG) {
    pBase[bindIdx].num = 1;
  }
  
D
stmt  
dapan1121 已提交
889 890 891 892
  return 0;
}


D
dapan1121 已提交
893
int32_t prepareInsertData(BindData *data) {
D
stmt  
dapan1121 已提交
894 895 896 897 898 899
  static int64_t tsData = 1591060628000;
  uint64_t allRowNum = gCurCase->rowNum * gCurCase->tblNum;
  
  data->colNum = 0;
  data->colTypes = taosMemoryCalloc(30, sizeof(int32_t));
  data->sql = taosMemoryCalloc(1, 1024);
D
dapan1121 已提交
900
  data->pBind = taosMemoryCalloc((allRowNum/gCurCase->bindRowNum)*gCurCase->bindColNum, sizeof(TAOS_MULTI_BIND));
D
dapan1121 已提交
901
  data->pTags = taosMemoryCalloc(gCurCase->tblNum*gCurCase->bindTagNum, sizeof(TAOS_MULTI_BIND));
D
stmt  
dapan1121 已提交
902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921
  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) {
    data->isNull = taosMemoryCalloc(allRowNum, sizeof(char));
  }
  
  for (int32_t i = 0; i < allRowNum; ++i) {
    data->tsData[i] = tsData++;
D
dapan1121 已提交
922 923 924 925 926 927 928 929 930 931 932
    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 已提交
933 934 935 936 937 938 939 940 941
    memset(data->binaryData + gVarCharSize * i, 'a'+i%26, gVarCharLen);
    if (gCurCase->bindNullNum) {
      data->isNull[i] = i % 2;
    }
    data->binaryLen[i] = gVarCharLen;
  }

  for (int b = 0; b < (allRowNum/gCurCase->bindRowNum); b++) {
    for (int c = 0; c < gCurCase->bindColNum; ++c) {
D
dapan1121 已提交
942 943 944 945 946 947 948
      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 已提交
949 950 951
    }
  }

D
dapan1121 已提交
952

D
stmt  
dapan1121 已提交
953
  generateInsertSQL(data);
D
stmt  
dapan1121 已提交
954 955 956 957
  
  return 0;
}

D
dapan1121 已提交
958
int32_t prepareQueryCondData(BindData *data, int32_t tblIdx) {
D
dapan1121 已提交
959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005
  static int64_t tsData = 1591060628000;
  uint64_t bindNum = gCurCase->rowNum / gCurCase->bindRowNum;
  
  data->colNum = 0;
  data->colTypes = taosMemoryCalloc(30, sizeof(int32_t));
  data->sql = taosMemoryCalloc(1, 1024);
  data->pBind = taosMemoryCalloc(bindNum*gCurCase->bindColNum, sizeof(TAOS_MULTI_BIND));
  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) {
    data->isNull = taosMemoryCalloc(bindNum, sizeof(char));
  }
  
  for (int32_t i = 0; i < bindNum; ++i) {
    data->tsData[i] = tsData + tblIdx*gCurCase->rowNum + rand()%gCurCase->rowNum;
    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) {
      data->isNull[i] = i % 2;
    }
    data->binaryLen[i] = gVarCharLen;
  }

  for (int b = 0; b < bindNum; b++) {
    for (int c = 0; c < gCurCase->bindColNum; ++c) {
D
dapan1121 已提交
1006
      prepareColData(BP_BIND_COL, data, b*gCurCase->bindColNum+c, b*gCurCase->bindRowNum, c);
D
dapan1121 已提交
1007 1008 1009
    }
  }

D
fix bug  
dapan1121 已提交
1010
  generateQueryCondSQL(data, tblIdx);
D
dapan1121 已提交
1011 1012 1013 1014 1015
  
  return 0;
}


D
dapan1121 已提交
1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061
int32_t prepareQueryMiscData(BindData *data, int32_t tblIdx) {
  static int64_t tsData = 1591060628000;
  uint64_t bindNum = gCurCase->rowNum / gCurCase->bindRowNum;
  
  data->colNum = 0;
  data->colTypes = taosMemoryCalloc(30, sizeof(int32_t));
  data->sql = taosMemoryCalloc(1, 1024);
  data->pBind = taosMemoryCalloc(bindNum*gCurCase->bindColNum, sizeof(TAOS_MULTI_BIND));
  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) {
    data->isNull = taosMemoryCalloc(bindNum, sizeof(char));
  }
  
  for (int32_t i = 0; i < bindNum; ++i) {
    data->tsData[i] = tsData + tblIdx*gCurCase->rowNum + rand()%gCurCase->rowNum;
    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) {
      data->isNull[i] = i % 2;
    }
    data->binaryLen[i] = gVarCharLen;
  }

D
dapan1121 已提交
1062 1063
  if (tblIdx == FUNCTION_TEST_IDX) {
    gCaseCtrl.numericParam = true;
D
dapan1121 已提交
1064 1065
  } else {
    gCaseCtrl.numericParam = false;
D
dapan1121 已提交
1066 1067
  }
  
D
dapan1121 已提交
1068 1069
  for (int b = 0; b < bindNum; b++) {
    for (int c = 0; c < gCurCase->bindColNum; ++c) {
D
dapan1121 已提交
1070
      prepareColData(BP_BIND_COL, data, b*gCurCase->bindColNum+c, b*gCurCase->bindRowNum, c);
D
dapan1121 已提交
1071 1072 1073
    }
  }

D
dapan1121 已提交
1074 1075
  gCaseCtrl.numericParam = false;

D
dapan1121 已提交
1076
  generateQueryMiscSQL(data, tblIdx);
D
dapan1121 已提交
1077

D
dapan1121 已提交
1078 1079 1080
  return 0;
}

D
dapan1121 已提交
1081 1082


D
stmt  
dapan1121 已提交
1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099
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 已提交
1100
  taosMemoryFree(data->pTags);
D
stmt  
dapan1121 已提交
1101
  taosMemoryFree(data->colTypes);
D
dapan1121 已提交
1102
  taosMemoryFree(data->sql);
D
stmt  
dapan1121 已提交
1103 1104
}

D
dapan1121 已提交
1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116
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 已提交
1117
      printf("\t[%s]\n", temp);
D
dapan1121 已提交
1118 1119 1120 1121 1122 1123 1124 1125
    }
  }
}

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 已提交
1126
    printf("!!!failed to query table, reason:%s\n", taos_errstr(result));
D
dapan1121 已提交
1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198
    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:
      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 已提交
1199
      printf("!!!invalid data type:%d\n", type);
D
dapan1121 已提交
1200 1201 1202 1203 1204
      exit(1);
  }
}


D
dapan1121 已提交
1205
int32_t bpBindParam(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind) {
D
stmt  
dapan1121 已提交
1206 1207 1208 1209 1210
  static int32_t n = 0;
  
  if (gCurCase->bindRowNum > 1) {
    if (0 == (n++%2)) {
      if (taos_stmt_bind_param_batch(stmt, bind)) {
D
dapan1121 已提交
1211
        printf("!!!taos_stmt_bind_param_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1212 1213 1214 1215 1216
        exit(1);
      }
    } else {
      for (int32_t i = 0; i < gCurCase->bindColNum; ++i) {
        if (taos_stmt_bind_single_param_batch(stmt, bind++, i)) {
D
dapan1121 已提交
1217
          printf("!!!taos_stmt_bind_single_param_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1218 1219 1220 1221 1222
          exit(1);
        }
      }
    }
  } else {
D
dapan1121 已提交
1223 1224
    if (0 == (n++%2)) {
      if (taos_stmt_bind_param_batch(stmt, bind)) {
D
dapan1121 已提交
1225
        printf("!!!taos_stmt_bind_param_batch error:%s\n", taos_stmt_errstr(stmt));
D
dapan1121 已提交
1226 1227 1228 1229
        exit(1);
      }
    } else {
      if (taos_stmt_bind_param(stmt, bind)) {
D
dapan1121 已提交
1230
        printf("!!!taos_stmt_bind_param error:%s\n", taos_stmt_errstr(stmt));
D
dapan1121 已提交
1231 1232
        exit(1);
      }
D
stmt  
dapan1121 已提交
1233 1234 1235 1236 1237 1238
    }
  }

  return 0;
}

D
dapan1121 已提交
1239
void bpCheckIsInsert(TAOS_STMT *stmt, int32_t insert) {
D
stmt  
dapan1121 已提交
1240 1241
  int32_t isInsert = 0;
  if (taos_stmt_is_insert(stmt, &isInsert)) {
D
dapan1121 已提交
1242
    printf("!!!taos_stmt_is_insert error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1243 1244 1245
    exit(1);
  }

D
dapan1121 已提交
1246
  if (insert != isInsert) {
D
dapan1121 已提交
1247
    printf("!!!is insert failed\n");
D
stmt  
dapan1121 已提交
1248 1249 1250 1251 1252 1253 1254
    exit(1);
  }
}

void bpCheckParamNum(TAOS_STMT *stmt) {
  int32_t num = 0;
  if (taos_stmt_num_params(stmt, &num)) {
D
dapan1121 已提交
1255
    printf("!!!taos_stmt_num_params error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1256 1257 1258 1259
    exit(1);
  }

  if (gCurCase->bindColNum != num) {
D
dapan1121 已提交
1260
    printf("!!!is insert failed\n");
D
stmt  
dapan1121 已提交
1261 1262 1263 1264 1265 1266 1267 1268
    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;
  if (insertNum != rows) {
D
dapan1121 已提交
1269
    printf("!!!affected rows %d mis-match with insert num %d\n", rows, insertNum);
D
stmt  
dapan1121 已提交
1270 1271
    exit(1);
  }
D
stmt  
dapan1121 已提交
1272 1273
}

D
dapan1121 已提交
1274 1275 1276
void bpCheckAffectedRowsOnce(TAOS_STMT *stmt, int32_t expectedNum) {
  int32_t rows = taos_stmt_affected_rows_once(stmt);
  if (expectedNum != rows) {
D
dapan1121 已提交
1277
    printf("!!!affected rows %d mis-match with expected num %d\n", rows, expectedNum);
D
dapan1121 已提交
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311
    exit(1);
  }
}

void bpCheckQueryResult(TAOS_STMT *stmt, TAOS *taos, char *stmtSql, TAOS_MULTI_BIND* bind) {
  TAOS_RES* res = taos_stmt_use_result(stmt);
  int32_t sqlResNum = 0;
  int32_t stmtResNum = 0;
  bpFetchRows(res, gCaseCtrl.printRes, &stmtResNum);

  char sql[1024];
  int32_t len = 0;
  char* p = stmtSql;
  char* s = NULL;

  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);
    len += (int64_t)s - (int64_t)p;
    
    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 已提交
1312
    printf("\tQuery SQL: %s\n", sql);
D
dapan1121 已提交
1313 1314 1315 1316
  }

  bpExecQuery(taos, sql, gCaseCtrl.printRes, &sqlResNum);
  if (sqlResNum != stmtResNum) {
D
dapan1121 已提交
1317
    printf("!!!sql res num %d mis-match stmt res num %d\n", sqlResNum, stmtResNum);
D
dapan1121 已提交
1318 1319 1320
    exit(1);
  }

D
dapan1121 已提交
1321
  printf("***sql res num match stmt res num %d\n", stmtResNum);
D
dapan1121 已提交
1322
}
D
stmt  
dapan1121 已提交
1323

D
dapan 已提交
1324 1325 1326 1327 1328 1329 1330 1331 1332
int32_t bpSetTableNameTags(BindData *data, int32_t tblIdx, char *tblName, TAOS_STMT *stmt) {
  if (gCurCase->bindTagNum > 0) {
    return taos_stmt_set_tbname_tags(stmt, tblName, data->pTags + tblIdx * gCurCase->bindTagNum);  
  } else {
    return taos_stmt_set_tbname(stmt, tblName);
  }
}


D
stmt  
dapan1121 已提交
1333
/* prepare [settbname [bind add]] exec */
D
dapan1121 已提交
1334
int insertMBSETest1(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1335
  BindData data = {0};
D
dapan1121 已提交
1336
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1337 1338

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

D
dapan1121 已提交
1344
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1345

D
stmt  
dapan1121 已提交
1346 1347 1348 1349 1350
  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 已提交
1351
      code = bpSetTableNameTags(&data, t, buf, stmt);
D
stmt  
dapan1121 已提交
1352
      if (code != 0){
D
dapan1121 已提交
1353
        printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1354 1355 1356
        exit(1);
      }  
    }
D
stmt  
dapan1121 已提交
1357 1358 1359 1360

    if (gCaseCtrl.checkParamNum) {
      bpCheckParamNum(stmt);
    }
D
stmt  
dapan1121 已提交
1361 1362
    
    for (int32_t b = 0; b <bindTimes; ++b) {
D
stmt  
dapan1121 已提交
1363
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
1364 1365 1366 1367
        exit(1);
      }
      
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1368
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1369 1370 1371 1372 1373 1374
        exit(1);
      }
    }
  }

  if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1375
    printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1376 1377 1378
    exit(1);
  }

D
dapan1121 已提交
1379
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1380 1381 1382 1383
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);

D
stmt  
dapan1121 已提交
1384 1385 1386 1387
  return 0;
}


D
stmt  
dapan1121 已提交
1388
/* prepare [settbname bind add] exec  */
D
dapan1121 已提交
1389
int insertMBSETest2(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1390
  BindData data = {0};
D
dapan1121 已提交
1391
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1392 1393 1394

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

D
dapan1121 已提交
1399
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1400

D
stmt  
dapan1121 已提交
1401 1402 1403 1404 1405 1406 1407
  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 已提交
1408
        code = bpSetTableNameTags(&data, t, buf, stmt);
D
stmt  
dapan1121 已提交
1409
        if (code != 0){
D
dapan1121 已提交
1410
          printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1411 1412 1413 1414
          exit(1);
        }  
      }
    
D
stmt  
dapan1121 已提交
1415
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
1416 1417
        exit(1);
      }
D
stmt  
dapan1121 已提交
1418 1419 1420 1421 1422

      if (gCaseCtrl.checkParamNum) {
        bpCheckParamNum(stmt);
      }
    
D
stmt  
dapan1121 已提交
1423
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1424
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1425 1426 1427 1428 1429 1430
        exit(1);
      }
    }
  }

  if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1431
    printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1432 1433 1434
    exit(1);
  }

D
dapan1121 已提交
1435
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1436 1437 1438 1439
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);

D
stmt  
dapan1121 已提交
1440 1441 1442 1443
  return 0;
}

/* prepare [settbname [bind add] exec] */
D
dapan1121 已提交
1444
int insertMBMETest1(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1445
  BindData data = {0};
D
dapan1121 已提交
1446
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1447 1448 1449
  
  int code = taos_stmt_prepare(stmt, data.sql, 0);
  if (code != 0){
D
dapan1121 已提交
1450
    printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1451 1452
    exit(1);
  }
D
stmt  
dapan1121 已提交
1453

D
dapan1121 已提交
1454
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1455

D
stmt  
dapan1121 已提交
1456 1457 1458 1459 1460
  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 已提交
1461
      code = bpSetTableNameTags(&data, t, buf, stmt);
D
stmt  
dapan1121 已提交
1462
      if (code != 0){
D
dapan1121 已提交
1463
        printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1464 1465 1466
        exit(1);
      }  
    }
D
stmt  
dapan1121 已提交
1467 1468 1469 1470

    if (gCaseCtrl.checkParamNum) {
      bpCheckParamNum(stmt);
    }
D
stmt  
dapan1121 已提交
1471 1472
    
    for (int32_t b = 0; b <bindTimes; ++b) {
D
stmt  
dapan1121 已提交
1473
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
1474 1475 1476 1477
        exit(1);
      }
      
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1478
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1479 1480 1481
        exit(1);
      }
    }
D
stmt  
dapan1121 已提交
1482

D
stmt  
dapan1121 已提交
1483
    if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1484
      printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1485 1486
      exit(1);
    }
D
stmt  
dapan1121 已提交
1487 1488
  }

D
dapan1121 已提交
1489
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1490 1491 1492
  bpCheckAffectedRows(stmt, 1);

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

D
stmt  
dapan1121 已提交
1494 1495 1496
  return 0;
}

D
stmt  
dapan1121 已提交
1497
/* prepare [settbname [bind add exec]] */
D
dapan1121 已提交
1498
int insertMBMETest2(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1499
  BindData data = {0};
D
dapan1121 已提交
1500
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1501 1502 1503

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

D
dapan1121 已提交
1508
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1509

D
stmt  
dapan1121 已提交
1510 1511 1512 1513 1514
  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 已提交
1515
      code = bpSetTableNameTags(&data, t, buf, stmt);
D
stmt  
dapan1121 已提交
1516
      if (code != 0){
D
dapan1121 已提交
1517
        printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1518 1519 1520 1521 1522
        exit(1);
      }  
    }
    
    for (int32_t b = 0; b <bindTimes; ++b) {
D
stmt  
dapan1121 已提交
1523
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
1524 1525
        exit(1);
      }
D
stmt  
dapan1121 已提交
1526 1527 1528 1529 1530

      if (gCaseCtrl.checkParamNum) {
        bpCheckParamNum(stmt);
      }
    
D
stmt  
dapan1121 已提交
1531
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1532
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1533 1534 1535 1536
        exit(1);
      }

      if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1537
        printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1538 1539 1540 1541 1542
        exit(1);
      }
    }
  }

D
dapan1121 已提交
1543
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1544 1545 1546
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);
D
stmt  
dapan1121 已提交
1547 1548 1549 1550

  return 0;
}

D
stmt  
dapan1121 已提交
1551
/* prepare [settbname [settbname bind add exec]] */
D
dapan1121 已提交
1552
int insertMBMETest3(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1553
  BindData data = {0};
D
dapan1121 已提交
1554
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1555 1556 1557

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

D
dapan1121 已提交
1562
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1563

D
stmt  
dapan1121 已提交
1564 1565 1566 1567 1568
  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 已提交
1569
      code = bpSetTableNameTags(&data, t, buf, stmt);
D
stmt  
dapan1121 已提交
1570
      if (code != 0){
D
dapan1121 已提交
1571
        printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1572 1573 1574
        exit(1);
      }  
    }
D
stmt  
dapan1121 已提交
1575 1576 1577 1578

    if (gCaseCtrl.checkParamNum) {
      bpCheckParamNum(stmt);
    }
D
stmt  
dapan1121 已提交
1579 1580 1581 1582 1583
    
    for (int32_t b = 0; b <bindTimes; ++b) {
      if (gCurCase->tblNum > 1) {
        char buf[32];
        sprintf(buf, "t%d", t);
D
dapan 已提交
1584
        code = bpSetTableNameTags(&data, t, buf, stmt);
D
stmt  
dapan1121 已提交
1585
        if (code != 0){
D
dapan1121 已提交
1586
          printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1587 1588 1589 1590
          exit(1);
        }  
      }
      
D
stmt  
dapan1121 已提交
1591
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
1592 1593 1594 1595
        exit(1);
      }
      
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1596
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1597 1598 1599 1600
        exit(1);
      }

      if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1601
        printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1602 1603 1604 1605 1606
        exit(1);
      }
    }
  }

D
dapan1121 已提交
1607
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1608 1609 1610
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);
D
stmt  
dapan1121 已提交
1611 1612 1613 1614 1615 1616

  return 0;
}


/* prepare [settbname bind add exec]   */
D
dapan1121 已提交
1617
int insertMBMETest4(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1618
  BindData data = {0};
D
dapan1121 已提交
1619
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1620 1621 1622

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

D
dapan1121 已提交
1627
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1628

D
stmt  
dapan1121 已提交
1629 1630 1631 1632 1633 1634 1635
  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 已提交
1636
        code = bpSetTableNameTags(&data, t, buf, stmt);
D
stmt  
dapan1121 已提交
1637
        if (code != 0){
D
dapan1121 已提交
1638
          printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1639 1640 1641 1642
          exit(1);
        }  
      }
    
D
stmt  
dapan1121 已提交
1643
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
1644 1645
        exit(1);
      }
D
stmt  
dapan1121 已提交
1646 1647 1648 1649 1650

      if (gCaseCtrl.checkParamNum) {
        bpCheckParamNum(stmt);
      }
    
D
stmt  
dapan1121 已提交
1651
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1652
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1653 1654 1655 1656
        exit(1);
      }

      if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1657
        printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1658 1659 1660 1661 1662
        exit(1);
      }
    }
  }

D
dapan1121 已提交
1663
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1664 1665 1666 1667 1668 1669 1670 1671
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);

  return 0;
}

/* [prepare [settbname [bind add] exec]]   */
D
dapan1121 已提交
1672
int insertMPMETest1(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1673 1674 1675 1676
  int32_t loop = 0;
  
  while (gCurCase->bindColNum >= 2) {
    BindData data = {0};
D
dapan1121 已提交
1677
    prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1678 1679 1680

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

D
dapan1121 已提交
1685
    bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1686 1687 1688 1689 1690 1691

    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 已提交
1692
        code = bpSetTableNameTags(&data, t, buf, stmt);
D
stmt  
dapan1121 已提交
1693
        if (code != 0){
D
dapan1121 已提交
1694
          printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708
          exit(1);
        }  
      }

      if (gCaseCtrl.checkParamNum) {
        bpCheckParamNum(stmt);
      }
      
      for (int32_t b = 0; b <bindTimes; ++b) {
        if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
          exit(1);
        }
        
        if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1709
          printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1710 1711 1712 1713 1714
          exit(1);
        }
      }

      if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1715
        printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1716 1717 1718 1719
        exit(1);
      }
    }

D
dapan1121 已提交
1720
    bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1721 1722 1723 1724

    destroyData(&data);

    gCurCase->bindColNum -= 2;
D
stmt  
dapan1121 已提交
1725
    gCurCase->fullCol = false;
D
stmt  
dapan1121 已提交
1726 1727 1728 1729 1730 1731 1732
    loop++;
  }

  bpCheckAffectedRows(stmt, loop);

  gExecLoopTimes = loop;
  
D
stmt  
dapan1121 已提交
1733 1734 1735
  return 0;
}

D
dapan 已提交
1736

D
dapan1121 已提交
1737 1738 1739 1740
/* [prepare [settbnametag [bind add] exec]]   */
int insertAUTOTest1(TAOS_STMT *stmt, TAOS *taos) {
  int32_t loop = 0;
  
D
dapan 已提交
1741
  while (gCurCase->bindTagNum > 0 && gCurCase->bindColNum > 0) {
D
dapan1121 已提交
1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803
    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);
        code = taos_stmt_set_tbname_tags(stmt, buf, data.pTags + t * gCurCase->bindTagNum);
        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) {
        if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
          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 已提交
1804
/* select * from table */
D
fix bug  
dapan1121 已提交
1805
int queryColumnTest(TAOS_STMT *stmt, TAOS *taos) {
D
dapan1121 已提交
1806 1807 1808 1809
  BindData data = {0};

  for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
    memset(&data, 0, sizeof(data));
D
dapan1121 已提交
1810
    prepareQueryCondData(&data, t);
D
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
dapan1121 已提交
1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827
      exit(1);
    }

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

      if (gCaseCtrl.checkParamNum) {
        bpCheckParamNum(stmt);
      }
      
      if (bpBindParam(stmt, data.pBind + n * gCurCase->bindColNum)) {
        exit(1);
      }
D
dapan1121 已提交
1828 1829 1830 1831 1832 1833

      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 已提交
1834 1835 1836
      }

      if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1837
        printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
dapan1121 已提交
1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851
        exit(1);
      }

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

    destroyData(&data);
  }

  return 0;
}

D
dapan1121 已提交
1852
/* value in query sql */
D
fix bug  
dapan1121 已提交
1853
int queryMiscTest(TAOS_STMT *stmt, TAOS *taos) {
D
dapan1121 已提交
1854 1855 1856 1857
  BindData data = {0};

  for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
    memset(&data, 0, sizeof(data));
D
dapan1121 已提交
1858
    prepareQueryMiscData(&data, t);
D
dapan1121 已提交
1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875

    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);
      }
      
      if (bpBindParam(stmt, data.pBind + n * gCurCase->bindColNum)) {
        exit(1);
      }
D
dapan1121 已提交
1876 1877 1878 1879 1880 1881

      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 已提交
1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921
      }

      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;
}


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 已提交
1922 1923 1924 1925
void prepareCheckResultImpl(TAOS     * taos, char *tname, bool printr, int expected, bool silent) {
  char sql[255] = "SELECT * FROM ";
  int32_t rows = 0;
  
1926
  strcat(sql, tname);
D
dapan1121 已提交
1927
  bpExecQuery(taos, sql, printr, &rows);
1928 1929
  
  if (rows == expected) {
D
dapan1121 已提交
1930
    if (!silent) {
D
dapan1121 已提交
1931
      printf("***%d rows are fetched as expected from %s\n", rows, tname);
D
dapan1121 已提交
1932
    }
1933
  } else {
D
dapan1121 已提交
1934
    printf("!!!expect rows %d mis-match rows %d fetched from %s\n", expected, rows, tname);
D
dapan1121 已提交
1935
    exit(1);
1936 1937 1938 1939
  }
}


D
dapan1121 已提交
1940
void prepareCheckResult(TAOS     *taos, bool silent) {
D
stmt  
dapan1121 已提交
1941 1942 1943
  char buf[32];
  for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
    if (gCurCase->tblNum > 1) {
D
dapan1121 已提交
1944
      sprintf(buf, "%s%d", bpTbPrefix, t);
D
stmt  
dapan1121 已提交
1945
    } else {
D
dapan1121 已提交
1946
      sprintf(buf, "%s%d", bpTbPrefix, 0);
D
stmt  
dapan1121 已提交
1947 1948
    }

D
dapan1121 已提交
1949
    prepareCheckResultImpl(taos, buf, gCaseCtrl.printRes, gCurCase->rowNum * gExecLoopTimes, silent);
D
stmt  
dapan1121 已提交
1950
  }
D
stmt  
dapan1121 已提交
1951 1952

  gExecLoopTimes = 1;
D
stmt  
dapan1121 已提交
1953 1954 1955
}


1956 1957 1958 1959 1960 1961 1962

//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 已提交
1963
    sql[i] = taosMemoryCalloc(1, 1048576);
1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978
  }

  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 已提交
1979
  int64_t starttime = taosGetTimestampUs();
1980 1981 1982 1983
  for (int i = 0; i < 3000; ++i) {
      result = taos_query(taos, sql[i]);
      int code = taos_errno(result);
      if (code != 0) {
D
dapan1121 已提交
1984
        printf("%d failed to query table, reason:%s\n", taos_errstr(result));
1985 1986 1987 1988 1989 1990
        taos_free_result(result);
        exit(1);
    }

    taos_free_result(result);
  }
D
stmt  
dapan1121 已提交
1991
  int64_t endtime = taosGetTimestampUs();
1992 1993 1994
  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 已提交
1995
    taosMemoryFree(sql[i]);
1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006
  }

  return 0;
}





//one table 60 records one time
int sql_perf_s1(TAOS     *taos) {
D
stmt  
dapan1121 已提交
2007
  char **sql = calloc(1, sizeof(char*) * 360000);
2008 2009 2010
  TAOS_RES *result;

  for (int i = 0; i < 360000; i++) {
wafwerar's avatar
wafwerar 已提交
2011
    sql[i] = taosMemoryCalloc(1, 9000);
2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031
  }

  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 已提交
2032
  unsigned long long starttime = taosGetTimestampUs();
2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043
  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 已提交
2044
  unsigned long long endtime = taosGetTimestampUs();
2045 2046 2047
  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 已提交
2048
    taosMemoryFree(sql[i]);
2049 2050
  }

wafwerar's avatar
wafwerar 已提交
2051
  taosMemoryFree(sql);
2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062

  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 已提交
2063
    sql[i] = taosMemoryCalloc(1, 1048576);
2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078
  }

  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 已提交
2079
  unsigned long long starttime = taosGetTimestampUs();
2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090
  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 已提交
2091
  unsigned long long endtime = taosGetTimestampUs();
2092 2093 2094
  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 已提交
2095
    taosMemoryFree(sql[i]);
2096 2097 2098 2099 2100
  }

  return 0;
}

D
stmt  
dapan1121 已提交
2101 2102
void generateCreateTableSQL(char *buf, int32_t tblIdx, int32_t colNum, int32_t *colList, bool stable) {
  int32_t blen = 0;
D
dapan1121 已提交
2103
  blen = sprintf(buf, "create table %s%d ", (stable ? bpStbPrefix : bpTbPrefix), tblIdx);
D
stmt  
dapan1121 已提交
2104 2105 2106 2107

  blen += sprintf(buf + blen, " (");
  
  for (int c = 0; c < colNum; ++c) {
D
stmt  
dapan1121 已提交
2108 2109 2110 2111
    if (c > 0) {
      blen += sprintf(buf + blen, ",");
    }
  
D
stmt  
dapan1121 已提交
2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137
    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:
D
stmt  
dapan1121 已提交
2138
        blen += sprintf(buf + blen, "ts timestamp");
D
stmt  
dapan1121 已提交
2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161
        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;
      default:
        printf("invalid col type:%d", colList[c]);
        exit(1);
    }      
  }

  blen += sprintf(buf + blen, ")");
D
stmt  
dapan1121 已提交
2162

D
dapan1121 已提交
2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220
  if (stable) {
    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, "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;
        default:
          printf("invalid col type:%d", colList[c]);
          exit(1);
      }      
    }

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

D
stmt  
dapan1121 已提交
2221
  if (gCaseCtrl.printCreateTblSql) {
D
dapan1121 已提交
2222
    printf("\tCreate Table SQL:%s\n", buf);
D
stmt  
dapan1121 已提交
2223
  }
D
stmt  
dapan1121 已提交
2224
}
2225

D
dapan1121 已提交
2226
void prepare(TAOS     *taos, int32_t colNum, int32_t *colList, int prepareStb) {
2227 2228 2229 2230 2231 2232 2233 2234 2235
  TAOS_RES *result;
  int      code;

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

  result = taos_query(taos, "create database demo keep 36500");
  code = taos_errno(result);
  if (code != 0) {
D
dapan1121 已提交
2236
    printf("!!!failed to create database, reason:%s\n", taos_errstr(result));
2237 2238 2239 2240 2241 2242 2243 2244
    taos_free_result(result);
    exit(1);
  }
  taos_free_result(result);

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

D
dapan1121 已提交
2245
  if (!prepareStb) {
2246
    // create table
D
stmt  
dapan1121 已提交
2247
    for (int i = 0 ; i < 10; i++) {
2248
      char buf[1024];
D
stmt  
dapan1121 已提交
2249
      generateCreateTableSQL(buf, i, colNum, colList, false);
2250 2251 2252
      result = taos_query(taos, buf);
      code = taos_errno(result);
      if (code != 0) {
D
dapan1121 已提交
2253
        printf("!!!failed to create table, reason:%s\n", taos_errstr(result));
2254 2255 2256 2257 2258 2259 2260
        taos_free_result(result);
        exit(1);
      }
      taos_free_result(result);
    }
  } else {
    char buf[1024];
D
dapan1121 已提交
2261
    generateCreateTableSQL(buf, bpDefaultStbId, colNum, colList, true);
2262 2263 2264 2265
    
    result = taos_query(taos, buf);
    code = taos_errno(result);
    if (code != 0) {
D
dapan1121 已提交
2266
      printf("!!!failed to create table, reason:%s\n", taos_errstr(result));
2267 2268 2269 2270 2271 2272 2273 2274
      taos_free_result(result);
      exit(1);
    }
    taos_free_result(result);
  }

}

D
dapan1121 已提交
2275
int32_t runCase(TAOS *taos, int32_t caseIdx, int32_t caseRunIdx, bool silent) {
D
stmt  
dapan1121 已提交
2276
  TAOS_STMT *stmt = NULL;
D
dapan1121 已提交
2277 2278
  int64_t beginUs, endUs, totalUs;  
  CaseCfg cfg = gCase[caseIdx];
D
dapan1121 已提交
2279
  CaseCfg cfgBk;
D
dapan1121 已提交
2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293
  gCurCase = &cfg;
  
  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 已提交
2294
    
D
stmt  
dapan1121 已提交
2295
    gCurCase = &cfg;
D
dapan1121 已提交
2296 2297 2298 2299 2300 2301 2302 2303 2304
  }
  
  if (gCaseCtrl.runTimes) {
    gCurCase->runTimes = gCaseCtrl.runTimes;
  }
  
  if (gCaseCtrl.rowNum) {
    gCurCase->rowNum = gCaseCtrl.rowNum;
  }
D
dapan 已提交
2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315

  if (gCaseCtrl.autoCreateTbl) {
    if (gCurCase->testType == TTYPE_INSERT && gCurCase->tblNum > 1) {
      gCurCase->autoCreateTbl = true;
      if (gCurCase->bindTagNum <= 0) {
        gCurCase->bindTagNum = gCurCase->colNum;
      }
    } else {
      return 1;
    }
  }
D
dapan1121 已提交
2316 2317 2318
  
  if (gCurCase->fullCol) {
    gCurCase->bindColNum = gCurCase->colNum;
D
dapan 已提交
2319 2320 2321
    if (gCurCase->autoCreateTbl) {
      gCurCase->bindTagNum = gCurCase->colNum;
    }
D
dapan1121 已提交
2322 2323 2324 2325 2326 2327 2328
  }
  
  gCurCase->bindNullNum = gCaseCtrl.bindNullNum;
  if (gCaseCtrl.bindColNum) {
    gCurCase->bindColNum = gCaseCtrl.bindColNum;
    gCurCase->fullCol = false;
  }
D
dapan1121 已提交
2329 2330 2331 2332
  if (gCaseCtrl.bindTagNum) {
    gCurCase->bindTagNum = gCaseCtrl.bindTagNum;
    gCurCase->fullCol = false;
  }
D
dapan1121 已提交
2333 2334 2335 2336 2337 2338 2339
  if (gCaseCtrl.bindRowNum) {
    gCurCase->bindRowNum = gCaseCtrl.bindRowNum;
  }
  if (gCaseCtrl.bindColTypeNum) {
    gCurCase->bindColNum = gCaseCtrl.bindColTypeNum;
    gCurCase->fullCol = false;
  }
D
dapan1121 已提交
2340 2341 2342 2343
  if (gCaseCtrl.bindTagTypeNum) {
    gCurCase->bindTagNum = gCaseCtrl.bindTagTypeNum;
    gCurCase->fullCol = false;
  }
D
stmt  
dapan1121 已提交
2344

D
dapan1121 已提交
2345 2346 2347 2348 2349
  if (!silent) {
    printf("* Case %d - [%s]%s Begin *\n", caseRunIdx, gCaseCtrl.caseCatalog, gCurCase->caseDesc);
  }
  
  totalUs = 0;
D
dapan1121 已提交
2350
  cfgBk = cfg;
D
dapan1121 已提交
2351 2352
  for (int32_t n = 0; n < gCurCase->runTimes; ++n) {
    if (gCurCase->preCaseIdx < 0) {
D
dapan 已提交
2353
      prepare(taos, gCurCase->colNum, gCurCase->colList, gCurCase->autoCreateTbl);
D
stmt  
dapan1121 已提交
2354 2355
    }
    
D
dapan1121 已提交
2356 2357 2358 2359
    beginUs = taosGetTimestampUs();
   
    stmt = taos_stmt_init(taos);
    if (NULL == stmt) {
D
dapan1121 已提交
2360
      printf("!!!taos_stmt_init failed, error:%s\n", taos_stmt_errstr(stmt));
D
dapan1121 已提交
2361
      exit(1);
D
stmt  
dapan1121 已提交
2362
    }
D
dapan1121 已提交
2363 2364 2365 2366 2367 2368 2369
  
    (*gCurCase->runFn)(stmt, taos);
  
    taos_stmt_close(stmt);
  
    endUs = taosGetTimestampUs();
    totalUs += (endUs - beginUs);
D
dapan1121 已提交
2370

D
dapan1121 已提交
2371
    prepareCheckResult(taos, silent);
D
dapan1121 已提交
2372 2373

    cfg = cfgBk;
D
dapan1121 已提交
2374
  }
D
dapan1121 已提交
2375

D
dapan1121 已提交
2376 2377 2378 2379 2380 2381
  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 已提交
2382

D
dapan1121 已提交
2383 2384 2385 2386 2387
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;
2388

D
dapan1121 已提交
2389 2390 2391 2392
  for (int32_t i = caseIdx; i < sizeof(gCase)/sizeof(gCase[0]); ++i) {
    if (gCaseCtrl.caseNum > 0 && caseNum >= gCaseCtrl.caseNum) {
      break;
    }
2393

D
dapan1121 已提交
2394 2395 2396
    if (gCaseCtrl.caseRunNum > 0 && caseRunNum >= gCaseCtrl.caseRunNum) {
      break;
    }
D
dapan1121 已提交
2397

D
dapan1121 已提交
2398 2399 2400 2401
    if (gCaseCtrl.caseRunIdx >= 0 && caseRunIdx < gCaseCtrl.caseRunIdx) {
      caseRunIdx++;
      continue;
    }
D
dapan1121 已提交
2402

D
dapan1121 已提交
2403 2404
    if (runCase(taos, i, caseRunIdx, false)) {
      continue;
2405
    }
D
stmt  
dapan1121 已提交
2406

D
dapan1121 已提交
2407 2408
    caseRunIdx++;
    caseNum++;
D
dapan1121 已提交
2409
    caseRunNum++;
D
stmt  
dapan1121 已提交
2410
  }
2411

D
stmt  
dapan1121 已提交
2412 2413
  return NULL;
}
D
stmt  
dapan1121 已提交
2414

D
stmt  
dapan1121 已提交
2415
void runAll(TAOS *taos) {
D
dapan1121 已提交
2416 2417
#if 1

D
dapan1121 已提交
2418 2419
  strcpy(gCaseCtrl.caseCatalog, "Normal Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
dapan1121 已提交
2420
  runCaseList(taos);
D
dapan 已提交
2421

D
dapan1121 已提交
2422

D
dapan 已提交
2423 2424 2425 2426 2427
  strcpy(gCaseCtrl.caseCatalog, "Auto Create Table Test");
  gCaseCtrl.autoCreateTbl = true;
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
  runCaseList(taos);
  gCaseCtrl.autoCreateTbl = false;
D
dapan1121 已提交
2428
  
D
dapan 已提交
2429
#endif
D
stmt  
dapan1121 已提交
2430

D
dapan 已提交
2431
/*
D
dapan1121 已提交
2432 2433
  strcpy(gCaseCtrl.caseCatalog, "Null Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
2434
  gCaseCtrl.bindNullNum = 1;
D
dapan1121 已提交
2435
  runCaseList(taos);
D
stmt  
dapan1121 已提交
2436
  gCaseCtrl.bindNullNum = 0;
D
stmt  
dapan1121 已提交
2437

D
dapan1121 已提交
2438 2439
  strcpy(gCaseCtrl.caseCatalog, "Bind Row Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
2440
  gCaseCtrl.bindRowNum = 1;
D
dapan1121 已提交
2441
  runCaseList(taos);
D
stmt  
dapan1121 已提交
2442
  gCaseCtrl.bindRowNum = 0;
D
stmt  
dapan1121 已提交
2443

D
dapan1121 已提交
2444 2445
  strcpy(gCaseCtrl.caseCatalog, "Row Num Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
2446
  gCaseCtrl.rowNum = 1000;
D
stmt  
dapan1121 已提交
2447
  gCaseCtrl.printRes = false;
D
dapan1121 已提交
2448
  runCaseList(taos);
D
stmt  
dapan1121 已提交
2449 2450
  gCaseCtrl.rowNum = 0;
  gCaseCtrl.printRes = true;
D
dapan1121 已提交
2451
*/
D
stmt  
dapan1121 已提交
2452

D
dapan1121 已提交
2453 2454
  strcpy(gCaseCtrl.caseCatalog, "Runtimes Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
2455
  gCaseCtrl.runTimes = 2;
D
dapan1121 已提交
2456
  runCaseList(taos);
D
stmt  
dapan1121 已提交
2457
  gCaseCtrl.runTimes = 0;
2458

D
dapan1121 已提交
2459
#if 1
D
dapan1121 已提交
2460 2461
  strcpy(gCaseCtrl.caseCatalog, "Check Param Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
2462
  gCaseCtrl.checkParamNum = true;
D
dapan1121 已提交
2463
  runCaseList(taos);
D
stmt  
dapan1121 已提交
2464
  gCaseCtrl.checkParamNum = false;
D
dapan1121 已提交
2465
#endif
2466

D
dapan1121 已提交
2467
/*
D
dapan1121 已提交
2468 2469
  strcpy(gCaseCtrl.caseCatalog, "Bind Col Num Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
2470
  gCaseCtrl.bindColNum = 6;
D
dapan1121 已提交
2471
  runCaseList(taos);
D
stmt  
dapan1121 已提交
2472
  gCaseCtrl.bindColNum = 0;
2473

D
dapan1121 已提交
2474 2475
  strcpy(gCaseCtrl.caseCatalog, "Bind Col Type Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
2476
  gCaseCtrl.bindColTypeNum = tListLen(bindColTypeList);
D
stmt  
dapan1121 已提交
2477
  gCaseCtrl.bindColTypeList = bindColTypeList;  
D
dapan1121 已提交
2478
  runCaseList(taos);
D
dapan 已提交
2479 2480
*/

D
dapan1121 已提交
2481
  printf("All Test End\n");  
2482 2483 2484 2485
}

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

D
stmt  
dapan1121 已提交
2488 2489
  srand(time(NULL));
  
2490 2491 2492 2493 2494 2495
  // connect to server
  if (argc < 2) {
    printf("please input server ip \n");
    return 0;
  }

D
stmt  
dapan1121 已提交
2496
  taos = taos_connect(argv[1], "root", "taosdata", NULL, 0);
2497 2498 2499 2500 2501
  if (taos == NULL) {
    printf("failed to connect to db, reason:%s\n", taos_errstr(taos));
    exit(1);
  }   

D
stmt  
dapan1121 已提交
2502
  runAll(taos);
2503 2504 2505 2506

  return 0;
}