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

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

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

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

D
dapan1121 已提交
23 24 25 26 27
typedef enum {
  BP_BIND_TAG = 1,
  BP_BIND_COL,
} BP_BIND_TYPE;

D
dapan1121 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40
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 已提交
41
  {"nmatch",   2, false},  
D
dapan1121 已提交
42 43 44 45 46 47 48
};

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

char *bpStbPrefix = "st";
char *bpTbPrefix = "t";
D
dapan1121 已提交
49 50
int32_t bpDefaultStbId = 1;

D
dapan1121 已提交
51 52 53 54


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

#define tListLen(x) (sizeof(x) / sizeof((x)[0]))

58
typedef struct {
D
stmt  
dapan1121 已提交
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
  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 已提交
74
  TAOS_MULTI_BIND* pBind;
D
dapan1121 已提交
75
  TAOS_MULTI_BIND* pTags;
D
stmt  
dapan1121 已提交
76 77 78 79 80 81 82 83
  char*         sql;
  int32_t*      colTypes;
  int32_t       colNum;
} BindData;

int32_t gVarCharSize = 10;
int32_t gVarCharLen = 5;

D
stmt  
dapan1121 已提交
84
int32_t gExecLoopTimes = 1; // no change
D
stmt  
dapan1121 已提交
85
int32_t gFullColNum = tListLen(fullColList);
D
stmt  
dapan1121 已提交
86

D
dapan1121 已提交
87 88 89 90 91 92 93
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 已提交
94
int insertAUTOTest1(TAOS_STMT *stmt, TAOS *taos);
D
dapan1121 已提交
95 96 97 98 99 100
int querySUBTTest1(TAOS_STMT *stmt, TAOS *taos);

enum {
  TTYPE_INSERT = 1,
  TTYPE_QUERY,
};
D
stmt  
dapan1121 已提交
101 102 103 104

typedef struct {
  char     caseDesc[128];
  int32_t  colNum;
D
stmt  
dapan1121 已提交
105
  int32_t *colList;         // full table column list
D
dapan1121 已提交
106
  int32_t  testType;     
D
dapan 已提交
107
  bool     autoCreateTbl;
D
stmt  
dapan1121 已提交
108
  bool     fullCol;
D
dapan1121 已提交
109
  int32_t  (*runFn)(TAOS_STMT*, TAOS*);
D
stmt  
dapan1121 已提交
110 111 112
  int32_t  tblNum;
  int32_t  rowNum;
  int32_t  bindRowNum;
D
stmt  
dapan1121 已提交
113
  int32_t  bindColNum;      // equal colNum in full column case
D
dapan1121 已提交
114
  int32_t  bindTagNum;      // equal colNum in full column case
D
stmt  
dapan1121 已提交
115 116
  int32_t  bindNullNum;
  int32_t  runTimes;
D
dapan1121 已提交
117
  int32_t  preCaseIdx;
D
stmt  
dapan1121 已提交
118 119 120
} CaseCfg;

CaseCfg gCase[] = {
D
dapan 已提交
121 122
  {"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 已提交
123

D
dapan1121 已提交
124 125 126
  {"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 已提交
127

D
dapan1121 已提交
128 129 130
  {"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 已提交
131

D
dapan1121 已提交
132 133 134
  {"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 已提交
135

D
dapan1121 已提交
136
  // 11
D
dapan1121 已提交
137 138 139
  {"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 已提交
140

D
dapan1121 已提交
141 142 143
  {"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 已提交
144

D
dapan1121 已提交
145 146 147
  {"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 已提交
148

D
dapan1121 已提交
149 150
  {"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 已提交
151

D
dapan1121 已提交
152
  // 22
D
dapan1121 已提交
153 154 155
  {"insert:AUTO1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, true, true, insertAUTOTest1, 10, 10, 2, 0, 0, 0, 1, -1},

  {"query:SUBT-FULL", tListLen(fullColList), fullColList, TTYPE_QUERY, false, false, querySUBTTest1, 10, 10, 1, 3, 0, 0, 1, 2},
D
stmt  
dapan1121 已提交
156

D
stmt  
dapan1121 已提交
157 158 159
};

CaseCfg *gCurCase = NULL;
D
stmt  
dapan1121 已提交
160 161

typedef struct {
D
dapan1121 已提交
162
  char     caseCatalog[255];
D
stmt  
dapan1121 已提交
163 164
  int32_t  bindNullNum;
  bool     checkParamNum;
D
stmt  
dapan1121 已提交
165
  bool     printRes;
D
stmt  
dapan1121 已提交
166
  bool     printCreateTblSql;
D
dapan1121 已提交
167 168
  bool     printQuerySql;
  bool     printStmtSql;
D
dapan 已提交
169
  bool     autoCreateTbl;
D
stmt  
dapan1121 已提交
170
  int32_t  rowNum;               //row num for one table
D
stmt  
dapan1121 已提交
171
  int32_t  bindColNum;
D
dapan1121 已提交
172
  int32_t  bindTagNum;
D
stmt  
dapan1121 已提交
173
  int32_t  bindRowNum;           //row num for once bind
D
stmt  
dapan1121 已提交
174 175
  int32_t  bindColTypeNum;
  int32_t* bindColTypeList;
D
dapan1121 已提交
176 177
  int32_t  bindTagTypeNum;
  int32_t* bindTagTypeList;
D
dapan1121 已提交
178 179
  int32_t  optrIdxListNum;
  int32_t* optrIdxList;
D
stmt  
dapan1121 已提交
180
  int32_t  runTimes;
D
dapan1121 已提交
181 182 183 184
  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 已提交
185 186
} CaseCtrl;

D
dapan1121 已提交
187
#if 1
D
dapan1121 已提交
188
CaseCtrl gCaseCtrl = { // default
D
dapan1121 已提交
189 190 191 192
  .bindNullNum = 0,
  .printCreateTblSql = false,
  .printQuerySql = true,
  .printStmtSql = true,
D
dapan 已提交
193 194 195 196 197 198 199 200 201 202 203 204
  .autoCreateTbl = false,
  .rowNum = 0,
  .bindColNum = 0,
  .bindTagNum = 0,
  .bindRowNum = 0,
  .bindColTypeNum = 0,
  .bindColTypeList = NULL,
  .bindTagTypeNum = 0,
  .bindTagTypeList = NULL,
  .optrIdxListNum = 0,
  .optrIdxList = NULL,
  .checkParamNum = false,
D
dapan1121 已提交
205
  .printRes = false,
D
dapan 已提交
206 207 208 209 210 211 212 213 214
  .runTimes = 0,
  .caseIdx = -1,
  .caseNum = -1,
  .caseRunIdx = -1,
  .caseRunNum = -1,
};
#endif


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

D
dapan1121 已提交
242 243 244 245 246 247 248 249 250 251 252 253 254 255
#if 0
CaseCtrl gCaseCtrl = {  // query case with specified col&oper
  .bindNullNum = 0,
  .printCreateTblSql = false,
  .printQuerySql = true,
  .printStmtSql = true,
  .rowNum = 0,
  .bindColNum = 0,
  .bindRowNum = 0,
  .bindColTypeNum = 0,
  .bindColTypeList = NULL,
  .optrIdxListNum = 0,
  .optrIdxList = NULL,
  .checkParamNum = false,
D
dapan1121 已提交
256
  .printRes = false,
D
dapan1121 已提交
257 258 259 260 261 262
  .runTimes = 0,
  .caseRunIdx = -1,
  .optrIdxListNum = 0,
  .optrIdxList = NULL,
  .bindColTypeNum = 0,
  .bindColTypeList = NULL,
D
dapan1121 已提交
263
  .caseIdx = 23,
D
dapan1121 已提交
264 265 266
  .caseNum = 1,
  .caseRunNum = 1,
};
D
dapan1121 已提交
267 268
#endif

D
dapan 已提交
269
#if 0
D
dapan1121 已提交
270
CaseCtrl gCaseCtrl = {  // query case with specified col&oper
D
stmt  
dapan1121 已提交
271
  .bindNullNum = 0,
D
dapan1121 已提交
272
  .printCreateTblSql = true,
D
dapan1121 已提交
273 274
  .printQuerySql = true,
  .printStmtSql = true,
D
dapan 已提交
275
  .autoCreateTbl = true,
D
stmt  
dapan1121 已提交
276
  .rowNum = 0,
D
stmt  
dapan1121 已提交
277
  .bindColNum = 0,
D
dapan 已提交
278
  .bindTagNum = 0,
D
stmt  
dapan1121 已提交
279
  .bindRowNum = 0,
D
dapan1121 已提交
280 281 282 283
  .bindColTypeNum = 0,
  .bindColTypeList = NULL,
  .optrIdxListNum = 0,
  .optrIdxList = NULL,
D
fix bug  
dapan1121 已提交
284
  .checkParamNum = false,
D
stmt  
dapan1121 已提交
285 286
  .printRes = true,
  .runTimes = 0,
D
dapan1121 已提交
287
  .caseRunIdx = -1,
D
dapan1121 已提交
288 289 290 291
  //.optrIdxListNum = tListLen(optrIdxList),
  //.optrIdxList = optrIdxList,
  //.bindColTypeNum = tListLen(bindColTypeList),
  //.bindColTypeList = bindColTypeList,
D
dapan1121 已提交
292 293
  .caseIdx = 22,
  .caseNum = 1,
D
dapan1121 已提交
294
  .caseRunNum = 1,
D
stmt  
dapan1121 已提交
295
};
D
dapan1121 已提交
296 297
#endif

D
stmt  
dapan1121 已提交
298 299
int32_t taosGetTimeOfDay(struct timeval *tv) {
  return gettimeofday(tv, NULL);
300
}
D
stmt  
dapan1121 已提交
301
void *taosMemoryMalloc(uint64_t size) {
D
stmt  
dapan1121 已提交
302 303 304
  return malloc(size);
}

D
stmt  
dapan1121 已提交
305 306 307 308 309
void *taosMemoryCalloc(int32_t num, int32_t size) {
  return calloc(num, size);
}
void taosMemoryFree(const void *ptr) {
  if (ptr == NULL) return;
310

D
stmt  
dapan1121 已提交
311 312
  return free((void*)ptr);
}
313

D
stmt  
dapan1121 已提交
314 315 316 317 318 319
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 已提交
320 321 322 323 324
static int64_t taosGetTimestampUs() {
  struct timeval systemTime;
  taosGetTimeOfDay(&systemTime);
  return (int64_t)systemTime.tv_sec * 1000000L + (int64_t)systemTime.tv_usec;
}
325

D
dapan1121 已提交
326
bool colExists(TAOS_MULTI_BIND* pBind, int32_t dataType) {
D
stmt  
dapan1121 已提交
327 328 329 330 331 332 333 334 335
  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 已提交
336

D
stmt  
dapan1121 已提交
337 338 339 340
    ++i;
  }
}

D
stmt  
dapan1121 已提交
341
void generateInsertSQL(BindData *data) {
D
dapan1121 已提交
342 343 344 345 346 347
  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 已提交
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 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

  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 已提交
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
  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 已提交
470
          printf("!!!invalid col type:%d", data->pBind[c].buffer_type);
D
stmt  
dapan1121 已提交
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485
          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 已提交
486

D
dapan1121 已提交
487
  if (gCaseCtrl.printStmtSql) {
D
dapan1121 已提交
488
    printf("\tSQL: %s\n", data->sql);
D
stmt  
dapan1121 已提交
489
  }  
D
stmt  
dapan1121 已提交
490
}
D
stmt  
dapan1121 已提交
491

D
dapan1121 已提交
492
void bpAppendOperatorParam(BindData *data, int32_t *len, int32_t dataType, int32_t idx) {
D
dapan1121 已提交
493
  OperInfo *pInfo = NULL;
D
dapan1121 已提交
494 495 496

  if (gCaseCtrl.optrIdxListNum > 0) {
    pInfo = &operInfo[gCaseCtrl.optrIdxList[idx]];
D
dapan1121 已提交
497
  } else {
D
dapan1121 已提交
498 499 500 501 502
    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 已提交
503
  }
D
dapan1121 已提交
504
  
D
dapan1121 已提交
505 506 507 508 509 510 511 512 513
  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 已提交
514
      printf("!!!invalid paramNum:%d\n", pInfo->paramNum);
D
dapan1121 已提交
515 516 517 518
      exit(1);
  }
}

D
dapan1121 已提交
519
void generateQueryCondSQL(BindData *data, int32_t tblIdx) {
D
dapan1121 已提交
520 521 522 523 524 525 526 527 528 529 530 531 532 533 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
  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 ");
      }
      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 已提交
570
          printf("!!!invalid col type:%d", data->pBind[c].buffer_type);
D
dapan1121 已提交
571 572 573
          exit(1);
      }
      
D
dapan1121 已提交
574
      bpAppendOperatorParam(data, &len, data->pBind[c].buffer_type, c);
D
dapan1121 已提交
575 576 577 578
    }
  }

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

D
dapan1121 已提交
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648

void generateQueryMiscSQL(BindData *data, int32_t tblIdx) {
  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 ");
      }
      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:
          printf("!!!invalid col type:%d", data->pBind[c].buffer_type);
          exit(1);
      }
      
      bpAppendOperatorParam(data, &len, data->pBind[c].buffer_type, c);
    }
  }

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


649

D
dapan1121 已提交
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672
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 已提交
673

D
dapan1121 已提交
674
void generateColDataType(BindData *data, int32_t bindIdx, int32_t colIdx, int32_t *dataType) {
D
stmt  
dapan1121 已提交
675
  if (bindIdx < gCurCase->bindColNum) {
D
stmt  
dapan1121 已提交
676
    if (gCaseCtrl.bindColTypeNum) {
D
stmt  
dapan1121 已提交
677 678
      *dataType = gCaseCtrl.bindColTypeList[colIdx];
      return;
D
stmt  
dapan1121 已提交
679 680 681
    } else if (gCurCase->fullCol) {
      *dataType = gCurCase->colList[bindIdx];
      return;
D
stmt  
dapan1121 已提交
682 683 684 685
    } else if (0 == colIdx) {
      *dataType = TSDB_DATA_TYPE_TIMESTAMP;
      return;
    } else {
D
stmt  
dapan1121 已提交
686 687 688 689 690 691 692
      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 已提交
693

D
stmt  
dapan1121 已提交
694 695 696 697 698 699 700 701 702 703 704 705
        if (colExists(data->pBind, *dataType)) {
          continue;
        }
        
        break;
      }
    }
  } else {
    *dataType = data->pBind[bindIdx%gCurCase->bindColNum].buffer_type;
  }
}

D
dapan1121 已提交
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736
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 已提交
737
  int32_t dataType = TSDB_DATA_TYPE_TIMESTAMP;
D
dapan1121 已提交
738 739 740 741 742 743 744 745 746
  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 已提交
747 748 749 750


  switch (dataType) {  
    case TSDB_DATA_TYPE_BOOL:
D
dapan1121 已提交
751 752 753 754
      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 已提交
755 756
      break;
    case TSDB_DATA_TYPE_TINYINT:
D
dapan1121 已提交
757 758 759 760
      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 已提交
761 762
      break;
    case TSDB_DATA_TYPE_SMALLINT:
D
dapan1121 已提交
763 764 765 766
      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 已提交
767 768
      break;
    case TSDB_DATA_TYPE_INT:
D
dapan1121 已提交
769 770 771 772
      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 已提交
773 774
      break;
    case TSDB_DATA_TYPE_BIGINT:
D
dapan1121 已提交
775 776 777 778
      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 已提交
779 780
      break;
    case TSDB_DATA_TYPE_FLOAT:
D
dapan1121 已提交
781 782 783 784
      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 已提交
785 786
      break;
    case TSDB_DATA_TYPE_DOUBLE:
D
dapan1121 已提交
787 788 789 790
      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 已提交
791 792
      break;
    case TSDB_DATA_TYPE_VARCHAR:
D
dapan1121 已提交
793 794 795 796
      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 已提交
797 798
      break;
    case TSDB_DATA_TYPE_TIMESTAMP:
D
dapan1121 已提交
799 800 801 802
      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 已提交
803 804
      break;
    case TSDB_DATA_TYPE_NCHAR:
D
dapan1121 已提交
805 806 807 808
      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 已提交
809 810
      break;
    case TSDB_DATA_TYPE_UTINYINT:
D
dapan1121 已提交
811 812 813 814
      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 已提交
815 816
      break;
    case TSDB_DATA_TYPE_USMALLINT:
D
dapan1121 已提交
817 818 819 820
      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 已提交
821 822
      break;
    case TSDB_DATA_TYPE_UINT:
D
dapan1121 已提交
823 824 825 826
      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 已提交
827 828
      break;
    case TSDB_DATA_TYPE_UBIGINT:
D
dapan1121 已提交
829 830 831 832
      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 已提交
833 834
      break;
    default:
D
dapan1121 已提交
835
      printf("!!!invalid col type:%d", dataType);
D
stmt  
dapan1121 已提交
836 837 838
      exit(1);
  }

D
dapan1121 已提交
839 840
  pBase[bindIdx].buffer_type = dataType;
  pBase[bindIdx].num = gCurCase->bindRowNum;
D
stmt  
dapan1121 已提交
841

D
dapan1121 已提交
842 843 844 845
  if (bType == BP_BIND_TAG) {
    pBase[bindIdx].num = 1;
  }
  
D
stmt  
dapan1121 已提交
846 847 848 849
  return 0;
}


D
dapan1121 已提交
850
int32_t prepareInsertData(BindData *data) {
D
stmt  
dapan1121 已提交
851 852 853 854 855 856
  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 已提交
857
  data->pBind = taosMemoryCalloc((allRowNum/gCurCase->bindRowNum)*gCurCase->bindColNum, sizeof(TAOS_MULTI_BIND));
D
dapan1121 已提交
858
  data->pTags = taosMemoryCalloc(gCurCase->tblNum*gCurCase->bindTagNum, sizeof(TAOS_MULTI_BIND));
D
stmt  
dapan1121 已提交
859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878
  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 已提交
879 880 881 882 883 884 885 886 887 888 889
    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 已提交
890 891 892 893 894 895 896 897 898
    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 已提交
899 900 901 902 903 904 905
      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 已提交
906 907 908
    }
  }

D
dapan1121 已提交
909

D
stmt  
dapan1121 已提交
910
  generateInsertSQL(data);
D
stmt  
dapan1121 已提交
911 912 913 914
  
  return 0;
}

D
dapan1121 已提交
915
int32_t prepareQueryCondData(BindData *data, int32_t tblIdx) {
D
dapan1121 已提交
916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962
  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 已提交
963
      prepareColData(BP_BIND_COL, data, b*gCurCase->bindColNum+c, b*gCurCase->bindRowNum, c);
D
dapan1121 已提交
964 965 966
    }
  }

D
fix bug  
dapan1121 已提交
967
  generateQueryCondSQL(data, tblIdx);
D
dapan1121 已提交
968 969 970 971 972
  
  return 0;
}


D
dapan1121 已提交
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 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020
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;
  }

  for (int b = 0; b < bindNum; b++) {
    for (int c = 0; c < gCurCase->bindColNum; ++c) {
D
dapan1121 已提交
1021
      prepareColData(BP_BIND_COL, data, b*gCurCase->bindColNum+c, b*gCurCase->bindRowNum, c);
D
dapan1121 已提交
1022 1023 1024 1025 1026 1027 1028 1029
    }
  }

  generateQueryMiscSQL(data, tblIdx);
  
  return 0;
}

D
dapan1121 已提交
1030 1031


D
stmt  
dapan1121 已提交
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048
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
stmt  
dapan1121 已提交
1049 1050 1051
  taosMemoryFree(data->colTypes);
}

D
dapan1121 已提交
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063
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 已提交
1064
      printf("\t[%s]\n", temp);
D
dapan1121 已提交
1065 1066 1067 1068 1069 1070 1071 1072
    }
  }
}

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 已提交
1073
    printf("!!!failed to query table, reason:%s\n", taos_errstr(result));
D
dapan1121 已提交
1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145
    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 已提交
1146
      printf("!!!invalid data type:%d\n", type);
D
dapan1121 已提交
1147 1148 1149 1150 1151
      exit(1);
  }
}


D
dapan1121 已提交
1152
int32_t bpBindParam(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind) {
D
stmt  
dapan1121 已提交
1153 1154 1155 1156 1157
  static int32_t n = 0;
  
  if (gCurCase->bindRowNum > 1) {
    if (0 == (n++%2)) {
      if (taos_stmt_bind_param_batch(stmt, bind)) {
D
dapan1121 已提交
1158
        printf("!!!taos_stmt_bind_param_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1159 1160 1161 1162 1163
        exit(1);
      }
    } else {
      for (int32_t i = 0; i < gCurCase->bindColNum; ++i) {
        if (taos_stmt_bind_single_param_batch(stmt, bind++, i)) {
D
dapan1121 已提交
1164
          printf("!!!taos_stmt_bind_single_param_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1165 1166 1167 1168 1169
          exit(1);
        }
      }
    }
  } else {
D
dapan1121 已提交
1170 1171
    if (0 == (n++%2)) {
      if (taos_stmt_bind_param_batch(stmt, bind)) {
D
dapan1121 已提交
1172
        printf("!!!taos_stmt_bind_param_batch error:%s\n", taos_stmt_errstr(stmt));
D
dapan1121 已提交
1173 1174 1175 1176
        exit(1);
      }
    } else {
      if (taos_stmt_bind_param(stmt, bind)) {
D
dapan1121 已提交
1177
        printf("!!!taos_stmt_bind_param error:%s\n", taos_stmt_errstr(stmt));
D
dapan1121 已提交
1178 1179
        exit(1);
      }
D
stmt  
dapan1121 已提交
1180 1181 1182 1183 1184 1185
    }
  }

  return 0;
}

D
dapan1121 已提交
1186
void bpCheckIsInsert(TAOS_STMT *stmt, int32_t insert) {
D
stmt  
dapan1121 已提交
1187 1188
  int32_t isInsert = 0;
  if (taos_stmt_is_insert(stmt, &isInsert)) {
D
dapan1121 已提交
1189
    printf("!!!taos_stmt_is_insert error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1190 1191 1192
    exit(1);
  }

D
dapan1121 已提交
1193
  if (insert != isInsert) {
D
dapan1121 已提交
1194
    printf("!!!is insert failed\n");
D
stmt  
dapan1121 已提交
1195 1196 1197 1198 1199 1200 1201
    exit(1);
  }
}

void bpCheckParamNum(TAOS_STMT *stmt) {
  int32_t num = 0;
  if (taos_stmt_num_params(stmt, &num)) {
D
dapan1121 已提交
1202
    printf("!!!taos_stmt_num_params error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1203 1204 1205 1206
    exit(1);
  }

  if (gCurCase->bindColNum != num) {
D
dapan1121 已提交
1207
    printf("!!!is insert failed\n");
D
stmt  
dapan1121 已提交
1208 1209 1210 1211 1212 1213 1214 1215
    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 已提交
1216
    printf("!!!affected rows %d mis-match with insert num %d\n", rows, insertNum);
D
stmt  
dapan1121 已提交
1217 1218
    exit(1);
  }
D
stmt  
dapan1121 已提交
1219 1220
}

D
dapan1121 已提交
1221 1222 1223
void bpCheckAffectedRowsOnce(TAOS_STMT *stmt, int32_t expectedNum) {
  int32_t rows = taos_stmt_affected_rows_once(stmt);
  if (expectedNum != rows) {
D
dapan1121 已提交
1224
    printf("!!!affected rows %d mis-match with expected num %d\n", rows, expectedNum);
D
dapan1121 已提交
1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258
    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 已提交
1259
    printf("\tQuery SQL: %s\n", sql);
D
dapan1121 已提交
1260 1261 1262 1263
  }

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

D
dapan1121 已提交
1268
  printf("***sql res num match stmt res num %d\n", stmtResNum);
D
dapan1121 已提交
1269
}
D
stmt  
dapan1121 已提交
1270

D
dapan 已提交
1271 1272 1273 1274 1275 1276 1277 1278 1279
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 已提交
1280
/* prepare [settbname [bind add]] exec */
D
dapan1121 已提交
1281
int insertMBSETest1(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1282
  BindData data = {0};
D
dapan1121 已提交
1283
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1284 1285

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

D
dapan1121 已提交
1291
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1292

D
stmt  
dapan1121 已提交
1293 1294 1295 1296 1297
  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 已提交
1298
      code = bpSetTableNameTags(&data, t, buf, stmt);
D
stmt  
dapan1121 已提交
1299
      if (code != 0){
D
dapan1121 已提交
1300
        printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1301 1302 1303
        exit(1);
      }  
    }
D
stmt  
dapan1121 已提交
1304 1305 1306 1307

    if (gCaseCtrl.checkParamNum) {
      bpCheckParamNum(stmt);
    }
D
stmt  
dapan1121 已提交
1308 1309
    
    for (int32_t b = 0; b <bindTimes; ++b) {
D
stmt  
dapan1121 已提交
1310
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
1311 1312 1313 1314
        exit(1);
      }
      
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1315
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1316 1317 1318 1319 1320 1321
        exit(1);
      }
    }
  }

  if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1322
    printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1323 1324 1325
    exit(1);
  }

D
dapan1121 已提交
1326
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1327 1328 1329 1330
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);

D
stmt  
dapan1121 已提交
1331 1332 1333 1334
  return 0;
}


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

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

D
dapan1121 已提交
1346
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1347

D
stmt  
dapan1121 已提交
1348 1349 1350 1351 1352 1353 1354
  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 已提交
1355
        code = bpSetTableNameTags(&data, t, buf, stmt);
D
stmt  
dapan1121 已提交
1356
        if (code != 0){
D
dapan1121 已提交
1357
          printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1358 1359 1360 1361
          exit(1);
        }  
      }
    
D
stmt  
dapan1121 已提交
1362
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
1363 1364
        exit(1);
      }
D
stmt  
dapan1121 已提交
1365 1366 1367 1368 1369

      if (gCaseCtrl.checkParamNum) {
        bpCheckParamNum(stmt);
      }
    
D
stmt  
dapan1121 已提交
1370
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1371
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1372 1373 1374 1375 1376 1377
        exit(1);
      }
    }
  }

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

D
dapan1121 已提交
1382
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1383 1384 1385 1386
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);

D
stmt  
dapan1121 已提交
1387 1388 1389 1390
  return 0;
}

/* prepare [settbname [bind add] exec] */
D
dapan1121 已提交
1391
int insertMBMETest1(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1392
  BindData data = {0};
D
dapan1121 已提交
1393
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1394 1395 1396
  
  int code = taos_stmt_prepare(stmt, data.sql, 0);
  if (code != 0){
D
dapan1121 已提交
1397
    printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1398 1399
    exit(1);
  }
D
stmt  
dapan1121 已提交
1400

D
dapan1121 已提交
1401
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1402

D
stmt  
dapan1121 已提交
1403 1404 1405 1406 1407
  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 已提交
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
        exit(1);
      }  
    }
D
stmt  
dapan1121 已提交
1414 1415 1416 1417

    if (gCaseCtrl.checkParamNum) {
      bpCheckParamNum(stmt);
    }
D
stmt  
dapan1121 已提交
1418 1419
    
    for (int32_t b = 0; b <bindTimes; ++b) {
D
stmt  
dapan1121 已提交
1420
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
1421 1422 1423 1424
        exit(1);
      }
      
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1425
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1426 1427 1428
        exit(1);
      }
    }
D
stmt  
dapan1121 已提交
1429

D
stmt  
dapan1121 已提交
1430
    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
      exit(1);
    }
D
stmt  
dapan1121 已提交
1434 1435
  }

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

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

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

D
stmt  
dapan1121 已提交
1444
/* prepare [settbname [bind add exec]] */
D
dapan1121 已提交
1445
int insertMBMETest2(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1446
  BindData data = {0};
D
dapan1121 已提交
1447
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1448 1449 1450

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

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

D
stmt  
dapan1121 已提交
1457 1458 1459 1460 1461
  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 已提交
1462
      code = bpSetTableNameTags(&data, t, buf, stmt);
D
stmt  
dapan1121 已提交
1463
      if (code != 0){
D
dapan1121 已提交
1464
        printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1465 1466 1467 1468 1469
        exit(1);
      }  
    }
    
    for (int32_t b = 0; b <bindTimes; ++b) {
D
stmt  
dapan1121 已提交
1470
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
1471 1472
        exit(1);
      }
D
stmt  
dapan1121 已提交
1473 1474 1475 1476 1477

      if (gCaseCtrl.checkParamNum) {
        bpCheckParamNum(stmt);
      }
    
D
stmt  
dapan1121 已提交
1478
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1479
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1480 1481 1482 1483
        exit(1);
      }

      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 1487 1488 1489
        exit(1);
      }
    }
  }

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

  destroyData(&data);
D
stmt  
dapan1121 已提交
1494 1495 1496 1497

  return 0;
}

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

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

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

D
stmt  
dapan1121 已提交
1511 1512 1513 1514 1515
  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 已提交
1516
      code = bpSetTableNameTags(&data, t, buf, stmt);
D
stmt  
dapan1121 已提交
1517
      if (code != 0){
D
dapan1121 已提交
1518
        printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1519 1520 1521
        exit(1);
      }  
    }
D
stmt  
dapan1121 已提交
1522 1523 1524 1525

    if (gCaseCtrl.checkParamNum) {
      bpCheckParamNum(stmt);
    }
D
stmt  
dapan1121 已提交
1526 1527 1528 1529 1530
    
    for (int32_t b = 0; b <bindTimes; ++b) {
      if (gCurCase->tblNum > 1) {
        char buf[32];
        sprintf(buf, "t%d", t);
D
dapan 已提交
1531
        code = bpSetTableNameTags(&data, t, buf, stmt);
D
stmt  
dapan1121 已提交
1532
        if (code != 0){
D
dapan1121 已提交
1533
          printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1534 1535 1536 1537
          exit(1);
        }  
      }
      
D
stmt  
dapan1121 已提交
1538
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
1539 1540 1541 1542
        exit(1);
      }
      
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1543
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1544 1545 1546 1547
        exit(1);
      }

      if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1548
        printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1549 1550 1551 1552 1553
        exit(1);
      }
    }
  }

D
dapan1121 已提交
1554
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1555 1556 1557
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);
D
stmt  
dapan1121 已提交
1558 1559 1560 1561 1562 1563

  return 0;
}


/* prepare [settbname bind add exec]   */
D
dapan1121 已提交
1564
int insertMBMETest4(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1565
  BindData data = {0};
D
dapan1121 已提交
1566
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1567 1568 1569

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

D
dapan1121 已提交
1574
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1575

D
stmt  
dapan1121 已提交
1576 1577 1578 1579 1580 1581 1582
  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 已提交
1583
        code = bpSetTableNameTags(&data, t, buf, stmt);
D
stmt  
dapan1121 已提交
1584
        if (code != 0){
D
dapan1121 已提交
1585
          printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1586 1587 1588 1589
          exit(1);
        }  
      }
    
D
stmt  
dapan1121 已提交
1590
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
1591 1592
        exit(1);
      }
D
stmt  
dapan1121 已提交
1593 1594 1595 1596 1597

      if (gCaseCtrl.checkParamNum) {
        bpCheckParamNum(stmt);
      }
    
D
stmt  
dapan1121 已提交
1598
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1599
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1600 1601 1602 1603
        exit(1);
      }

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

D
dapan1121 已提交
1610
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1611 1612 1613 1614 1615 1616 1617 1618
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);

  return 0;
}

/* [prepare [settbname [bind add] exec]]   */
D
dapan1121 已提交
1619
int insertMPMETest1(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1620 1621 1622 1623
  int32_t loop = 0;
  
  while (gCurCase->bindColNum >= 2) {
    BindData data = {0};
D
dapan1121 已提交
1624
    prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1625 1626 1627

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

D
dapan1121 已提交
1632
    bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1633 1634 1635 1636 1637 1638

    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 已提交
1639
        code = bpSetTableNameTags(&data, t, buf, stmt);
D
stmt  
dapan1121 已提交
1640
        if (code != 0){
D
dapan1121 已提交
1641
          printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655
          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 已提交
1656
          printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1657 1658 1659 1660 1661
          exit(1);
        }
      }

      if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1662
        printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1663 1664 1665 1666
        exit(1);
      }
    }

D
dapan1121 已提交
1667
    bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1668 1669 1670 1671

    destroyData(&data);

    gCurCase->bindColNum -= 2;
D
stmt  
dapan1121 已提交
1672
    gCurCase->fullCol = false;
D
stmt  
dapan1121 已提交
1673 1674 1675 1676 1677 1678 1679
    loop++;
  }

  bpCheckAffectedRows(stmt, loop);

  gExecLoopTimes = loop;
  
D
stmt  
dapan1121 已提交
1680 1681 1682
  return 0;
}

D
dapan 已提交
1683

D
dapan1121 已提交
1684 1685 1686 1687
/* [prepare [settbnametag [bind add] exec]]   */
int insertAUTOTest1(TAOS_STMT *stmt, TAOS *taos) {
  int32_t loop = 0;
  
D
dapan 已提交
1688
  while (gCurCase->bindTagNum > 0 && gCurCase->bindColNum > 0) {
D
dapan1121 已提交
1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750
    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 已提交
1751
/* select * from table */
D
dapan1121 已提交
1752 1753 1754 1755 1756
int querySUBTTest1(TAOS_STMT *stmt, TAOS *taos) {
  BindData data = {0};

  for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
    memset(&data, 0, sizeof(data));
D
dapan1121 已提交
1757
    prepareQueryCondData(&data, t);
D
dapan1121 已提交
1758 1759 1760

    int code = taos_stmt_prepare(stmt, data.sql, 0);
    if (code != 0){
D
dapan1121 已提交
1761
      printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
D
dapan1121 已提交
1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776
      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);
      }
      
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1777
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
dapan1121 已提交
1778 1779 1780 1781
        exit(1);
      }

      if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1782
        printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
dapan1121 已提交
1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796
        exit(1);
      }

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

    destroyData(&data);
  }

  return 0;
}

D
dapan1121 已提交
1797 1798 1799 1800 1801 1802
/* value in query sql */
int querySUBTTest2(TAOS_STMT *stmt, TAOS *taos) {
  BindData data = {0};

  for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
    memset(&data, 0, sizeof(data));
D
dapan1121 已提交
1803
    prepareQueryMiscData(&data, t);
D
dapan1121 已提交
1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864

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

      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
stmt  
dapan1121 已提交
1865

D
stmt  
dapan1121 已提交
1866
#if 0
1867 1868

//1 tables 10 records
D
stmt  
dapan1121 已提交
1869
int stmt_funcb_autoctb1(TAOS_STMT *stmt) {
1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881
  struct {
      int64_t *ts;
      int8_t b[10];
      int8_t v1[10];
      int16_t v2[10];
      int32_t v4[10];
      int64_t v8[10];
      float f4[10];
      double f8[10];
      char bin[10][40];
  } v = {0};

wafwerar's avatar
wafwerar 已提交
1882
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
1883
  
wafwerar's avatar
wafwerar 已提交
1884
  int *lb = taosMemoryMalloc(10 * sizeof(int));
1885

wafwerar's avatar
wafwerar 已提交
1886
  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
D
dapan1121 已提交
1887
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10);
1888

D
stmt  
dapan1121 已提交
1889
  unsigned long long starttime = taosGetTimestampUs();
1890

D
stmt  
dapan1121 已提交
1891
  char *sql = "insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)";
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
  int code = taos_stmt_prepare(stmt, sql, 0);
  if (code != 0){
    printf("failed to execute taos_stmt_prepare. code:0x%x\n", code);
    exit(1);
  }

  int id = 0;
  for (int zz = 0; zz < 1; zz++) {
    char buf[32];
    sprintf(buf, "m%d", zz);
    code = taos_stmt_set_tbname_tags(stmt, buf, tags);
    if (code != 0){
      printf("failed to execute taos_stmt_set_tbname_tags. code:0x%x\n", code);
    }  

    taos_stmt_bind_param_batch(stmt, params + id * 10);
    taos_stmt_add_batch(stmt);
  }

  if (taos_stmt_execute(stmt) != 0) {
    printf("failed to execute insert statement.\n");
    exit(1);
  }

  ++id;

D
stmt  
dapan1121 已提交
1918
  unsigned long long endtime = taosGetTimestampUs();
1919 1920
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10));

wafwerar's avatar
wafwerar 已提交
1921 1922 1923 1924 1925 1926
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
  taosMemoryFree(tags);
1927 1928 1929 1930 1931 1932 1933 1934

  return 0;
}




//1 tables 10 records
D
stmt  
dapan1121 已提交
1935
int stmt_funcb_autoctb2(TAOS_STMT *stmt) {
1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947
  struct {
      int64_t *ts;
      int8_t b[10];
      int8_t v1[10];
      int16_t v2[10];
      int32_t v4[10];
      int64_t v8[10];
      float f4[10];
      double f8[10];
      char bin[10][40];
  } v = {0};

wafwerar's avatar
wafwerar 已提交
1948
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
1949
  
wafwerar's avatar
wafwerar 已提交
1950
  int *lb = taosMemoryMalloc(10 * sizeof(int));
1951

wafwerar's avatar
wafwerar 已提交
1952
  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
D
dapan1121 已提交
1953
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10);
1954 1955 1956 1957

//  int one_null = 1;
  int one_not_null = 0;
  
wafwerar's avatar
wafwerar 已提交
1958 1959
  char* is_null = taosMemoryMalloc(sizeof(char) * 10);
  char* no_null = taosMemoryMalloc(sizeof(char) * 10);
1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027

  for (int i = 0; i < 10; ++i) {
    lb[i] = 40;
    no_null[i] = 0;
    is_null[i] = (i % 10 == 2) ? 1 : 0;
    v.b[i] = (int8_t)(i % 2);
    v.v1[i] = (int8_t)((i+1) % 2);
    v.v2[i] = (int16_t)i;
    v.v4[i] = (int32_t)(i+1);
    v.v8[i] = (int64_t)(i+2);
    v.f4[i] = (float)(i+3);
    v.f8[i] = (double)(i+4);
    memset(v.bin[i], '0'+i%10, 40);
  }
  
  for (int i = 0; i < 10; i+=10) {
    params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
    params[i+0].buffer_length = sizeof(int64_t);
    params[i+0].buffer = &v.ts[10*i/10];
    params[i+0].length = NULL;
    params[i+0].is_null = no_null;
    params[i+0].num = 10;
    
    params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
    params[i+1].buffer_length = sizeof(int8_t);
    params[i+1].buffer = v.b;
    params[i+1].length = NULL;
    params[i+1].is_null = is_null;
    params[i+1].num = 10;

    params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
    params[i+2].buffer_length = sizeof(int8_t);
    params[i+2].buffer = v.v1;
    params[i+2].length = NULL;
    params[i+2].is_null = is_null;
    params[i+2].num = 10;

    params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    params[i+3].buffer_length = sizeof(int16_t);
    params[i+3].buffer = v.v2;
    params[i+3].length = NULL;
    params[i+3].is_null = is_null;
    params[i+3].num = 10;

    params[i+4].buffer_type = TSDB_DATA_TYPE_INT;
    params[i+4].buffer_length = sizeof(int32_t);
    params[i+4].buffer = v.v4;
    params[i+4].length = NULL;
    params[i+4].is_null = is_null;
    params[i+4].num = 10;

    params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT;
    params[i+5].buffer_length = sizeof(int64_t);
    params[i+5].buffer = v.v8;
    params[i+5].length = NULL;
    params[i+5].is_null = is_null;
    params[i+5].num = 10;

    params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT;
    params[i+6].buffer_length = sizeof(float);
    params[i+6].buffer = v.f4;
    params[i+6].length = NULL;
    params[i+6].is_null = is_null;
    params[i+6].num = 10;

    params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE;
    params[i+7].buffer_length = sizeof(double);
    params[i+7].buffer = v.f8;
D
stmt  
dapan1121 已提交
2028 2029 2030
    params[i+7].length = NULL;
    params[i+7].is_null = is_null;
    params[i+7].num = 10;
2031

D
stmt  
dapan1121 已提交
2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045
    params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+8].buffer_length = 40;
    params[i+8].buffer = v.bin;
    params[i+8].length = lb;
    params[i+8].is_null = is_null;
    params[i+8].num = 10;

    params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+9].buffer_length = 40;
    params[i+9].buffer = v.bin;
    params[i+9].length = lb;
    params[i+9].is_null = is_null;
    params[i+9].num = 10;
    
2046 2047 2048 2049 2050 2051 2052 2053 2054
  }

  int64_t tts = 1591060628000;
  for (int i = 0; i < 10; ++i) {
    v.ts[i] = tts + i;
  }


  for (int i = 0; i < 1; ++i) {
D
stmt  
dapan1121 已提交
2055 2056
    tags[i+0].buffer_type = TSDB_DATA_TYPE_INT;
    tags[i+0].buffer = v.v4;
2057 2058 2059
    tags[i+0].is_null = &one_not_null;
    tags[i+0].length = NULL;

D
stmt  
dapan1121 已提交
2060 2061
    tags[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
    tags[i+1].buffer = v.b;
2062 2063 2064
    tags[i+1].is_null = &one_not_null;
    tags[i+1].length = NULL;

D
stmt  
dapan1121 已提交
2065 2066
    tags[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
    tags[i+2].buffer = v.v1;
2067 2068 2069
    tags[i+2].is_null = &one_not_null;
    tags[i+2].length = NULL;

D
stmt  
dapan1121 已提交
2070 2071
    tags[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    tags[i+3].buffer = v.v2;
2072
    tags[i+3].is_null = &one_not_null;
D
stmt  
dapan1121 已提交
2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098
    tags[i+3].length = NULL;

    tags[i+4].buffer_type = TSDB_DATA_TYPE_BIGINT;
    tags[i+4].buffer = v.v8;
    tags[i+4].is_null = &one_not_null;
    tags[i+4].length = NULL;

    tags[i+5].buffer_type = TSDB_DATA_TYPE_FLOAT;
    tags[i+5].buffer = v.f4;
    tags[i+5].is_null = &one_not_null;
    tags[i+5].length = NULL;

    tags[i+6].buffer_type = TSDB_DATA_TYPE_DOUBLE;
    tags[i+6].buffer = v.f8;
    tags[i+6].is_null = &one_not_null;
    tags[i+6].length = NULL;

    tags[i+7].buffer_type = TSDB_DATA_TYPE_BINARY;
    tags[i+7].buffer = v.bin;
    tags[i+7].is_null = &one_not_null;
    tags[i+7].length = (uintptr_t *)lb;

    tags[i+8].buffer_type = TSDB_DATA_TYPE_NCHAR;
    tags[i+8].buffer = v.bin;
    tags[i+8].is_null = &one_not_null;
    tags[i+8].length = (uintptr_t *)lb;
2099 2100 2101
  }


D
stmt  
dapan1121 已提交
2102
  unsigned long long starttime = taosGetTimestampUs();
2103

D
stmt  
dapan1121 已提交
2104
  char *sql = "insert into ? using stb1 tags(1,true,2,3,4,5.0,6.0,'a','b') values(?,?,?,?,?,?,?,?,?,?)";
2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119
  int code = taos_stmt_prepare(stmt, sql, 0);
  if (code != 0){
    printf("failed to execute taos_stmt_prepare. code:0x%x\n", code);
    exit(1);
  }

  int id = 0;
  for (int zz = 0; zz < 1; zz++) {
    char buf[32];
    sprintf(buf, "m%d", zz);
    code = taos_stmt_set_tbname_tags(stmt, buf, tags);
    if (code != 0){
      printf("failed to execute taos_stmt_set_tbname_tags. code:0x%x\n", code);
    }  

D
stmt  
dapan1121 已提交
2120
    taos_stmt_bind_param_batch(stmt, params + id * 10);
2121 2122 2123 2124 2125 2126 2127 2128 2129 2130
    taos_stmt_add_batch(stmt);
  }

  if (taos_stmt_execute(stmt) != 0) {
    printf("failed to execute insert statement.\n");
    exit(1);
  }

  ++id;

D
stmt  
dapan1121 已提交
2131
  unsigned long long endtime = taosGetTimestampUs();
2132 2133
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10));

wafwerar's avatar
wafwerar 已提交
2134 2135 2136 2137 2138 2139
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
  taosMemoryFree(tags);
2140 2141 2142 2143 2144 2145 2146 2147 2148

  return 0;
}





//1 tables 10 records
D
stmt  
dapan1121 已提交
2149
int stmt_funcb_autoctb3(TAOS_STMT *stmt) {
2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161
  struct {
      int64_t *ts;
      int8_t b[10];
      int8_t v1[10];
      int16_t v2[10];
      int32_t v4[10];
      int64_t v8[10];
      float f4[10];
      double f8[10];
      char bin[10][40];
  } v = {0};

wafwerar's avatar
wafwerar 已提交
2162
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
2163
  
wafwerar's avatar
wafwerar 已提交
2164
  int *lb = taosMemoryMalloc(10 * sizeof(int));
2165

wafwerar's avatar
wafwerar 已提交
2166
  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
D
dapan1121 已提交
2167
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10);
2168 2169 2170 2171

//  int one_null = 1;
  int one_not_null = 0;
  
wafwerar's avatar
wafwerar 已提交
2172 2173
  char* is_null = taosMemoryMalloc(sizeof(char) * 10);
  char* no_null = taosMemoryMalloc(sizeof(char) * 10);
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 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290

  for (int i = 0; i < 10; ++i) {
    lb[i] = 40;
    no_null[i] = 0;
    is_null[i] = (i % 10 == 2) ? 1 : 0;
    v.b[i] = (int8_t)(i % 2);
    v.v1[i] = (int8_t)((i+1) % 2);
    v.v2[i] = (int16_t)i;
    v.v4[i] = (int32_t)(i+1);
    v.v8[i] = (int64_t)(i+2);
    v.f4[i] = (float)(i+3);
    v.f8[i] = (double)(i+4);
    memset(v.bin[i], '0'+i%10, 40);
  }
  
  for (int i = 0; i < 10; i+=10) {
    params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
    params[i+0].buffer_length = sizeof(int64_t);
    params[i+0].buffer = &v.ts[10*i/10];
    params[i+0].length = NULL;
    params[i+0].is_null = no_null;
    params[i+0].num = 10;
    
    params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
    params[i+1].buffer_length = sizeof(int8_t);
    params[i+1].buffer = v.b;
    params[i+1].length = NULL;
    params[i+1].is_null = is_null;
    params[i+1].num = 10;

    params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
    params[i+2].buffer_length = sizeof(int8_t);
    params[i+2].buffer = v.v1;
    params[i+2].length = NULL;
    params[i+2].is_null = is_null;
    params[i+2].num = 10;

    params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    params[i+3].buffer_length = sizeof(int16_t);
    params[i+3].buffer = v.v2;
    params[i+3].length = NULL;
    params[i+3].is_null = is_null;
    params[i+3].num = 10;

    params[i+4].buffer_type = TSDB_DATA_TYPE_INT;
    params[i+4].buffer_length = sizeof(int32_t);
    params[i+4].buffer = v.v4;
    params[i+4].length = NULL;
    params[i+4].is_null = is_null;
    params[i+4].num = 10;

    params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT;
    params[i+5].buffer_length = sizeof(int64_t);
    params[i+5].buffer = v.v8;
    params[i+5].length = NULL;
    params[i+5].is_null = is_null;
    params[i+5].num = 10;

    params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT;
    params[i+6].buffer_length = sizeof(float);
    params[i+6].buffer = v.f4;
    params[i+6].length = NULL;
    params[i+6].is_null = is_null;
    params[i+6].num = 10;

    params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE;
    params[i+7].buffer_length = sizeof(double);
    params[i+7].buffer = v.f8;
    params[i+7].length = NULL;
    params[i+7].is_null = is_null;
    params[i+7].num = 10;

    params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+8].buffer_length = 40;
    params[i+8].buffer = v.bin;
    params[i+8].length = lb;
    params[i+8].is_null = is_null;
    params[i+8].num = 10;

    params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+9].buffer_length = 40;
    params[i+9].buffer = v.bin;
    params[i+9].length = lb;
    params[i+9].is_null = is_null;
    params[i+9].num = 10;
    
  }

  int64_t tts = 1591060628000;
  for (int i = 0; i < 10; ++i) {
    v.ts[i] = tts + i;
  }


  for (int i = 0; i < 1; ++i) {
    tags[i+0].buffer_type = TSDB_DATA_TYPE_BOOL;
    tags[i+0].buffer = v.b;
    tags[i+0].is_null = &one_not_null;
    tags[i+0].length = NULL;

    tags[i+1].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    tags[i+1].buffer = v.v2;
    tags[i+1].is_null = &one_not_null;
    tags[i+1].length = NULL;

    tags[i+2].buffer_type = TSDB_DATA_TYPE_FLOAT;
    tags[i+2].buffer = v.f4;
    tags[i+2].is_null = &one_not_null;
    tags[i+2].length = NULL;

    tags[i+3].buffer_type = TSDB_DATA_TYPE_BINARY;
    tags[i+3].buffer = v.bin;
    tags[i+3].is_null = &one_not_null;
    tags[i+3].length = (uintptr_t *)lb;
  }


D
stmt  
dapan1121 已提交
2291
  unsigned long long starttime = taosGetTimestampUs();
2292

D
stmt  
dapan1121 已提交
2293
  char *sql = "insert into ? using stb1 tags(1,?,2,?,4,?,6.0,?,'b') values(?,?,?,?,?,?,?,?,?,?)";
2294 2295
  int code = taos_stmt_prepare(stmt, sql, 0);
  if (code != 0){
D
stmt  
dapan1121 已提交
2296 2297
    printf("failed to execute taos_stmt_prepare. code:0x%x\n", code);
    exit(1);
2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319
  }

  int id = 0;
  for (int zz = 0; zz < 1; zz++) {
    char buf[32];
    sprintf(buf, "m%d", zz);
    code = taos_stmt_set_tbname_tags(stmt, buf, tags);
    if (code != 0){
      printf("failed to execute taos_stmt_set_tbname_tags. code:0x%x\n", code);
    }  

    taos_stmt_bind_param_batch(stmt, params + id * 10);
    taos_stmt_add_batch(stmt);
  }

  if (taos_stmt_execute(stmt) != 0) {
    printf("failed to execute insert statement.\n");
    exit(1);
  }

  ++id;

D
stmt  
dapan1121 已提交
2320
  unsigned long long endtime = taosGetTimestampUs();
2321 2322
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10));

wafwerar's avatar
wafwerar 已提交
2323 2324 2325 2326 2327 2328
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
  taosMemoryFree(tags);
2329 2330 2331 2332 2333 2334 2335 2336

  return 0;
}





D
stmt  
dapan1121 已提交
2337 2338


2339
//1 tables 10 records
D
stmt  
dapan1121 已提交
2340
int stmt_funcb_autoctb4(TAOS_STMT *stmt) {
2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352
  struct {
      int64_t *ts;
      int8_t b[10];
      int8_t v1[10];
      int16_t v2[10];
      int32_t v4[10];
      int64_t v8[10];
      float f4[10];
      double f8[10];
      char bin[10][40];
  } v = {0};

wafwerar's avatar
wafwerar 已提交
2353
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
2354
  
wafwerar's avatar
wafwerar 已提交
2355
  int *lb = taosMemoryMalloc(10 * sizeof(int));
2356

wafwerar's avatar
wafwerar 已提交
2357
  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
D
dapan1121 已提交
2358
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*5);
2359 2360 2361 2362

//  int one_null = 1;
  int one_not_null = 0;
  
wafwerar's avatar
wafwerar 已提交
2363 2364
  char* is_null = taosMemoryMalloc(sizeof(char) * 10);
  char* no_null = taosMemoryMalloc(sizeof(char) * 10);
2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379

  for (int i = 0; i < 10; ++i) {
    lb[i] = 40;
    no_null[i] = 0;
    is_null[i] = (i % 10 == 2) ? 1 : 0;
    v.b[i] = (int8_t)(i % 2);
    v.v1[i] = (int8_t)((i+1) % 2);
    v.v2[i] = (int16_t)i;
    v.v4[i] = (int32_t)(i+1);
    v.v8[i] = (int64_t)(i+2);
    v.f4[i] = (float)(i+3);
    v.f8[i] = (double)(i+4);
    memset(v.bin[i], '0'+i%10, 40);
  }
  
D
stmt  
dapan1121 已提交
2380
  for (int i = 0; i < 5; i+=5) {
2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394
    params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
    params[i+0].buffer_length = sizeof(int64_t);
    params[i+0].buffer = &v.ts[10*i/10];
    params[i+0].length = NULL;
    params[i+0].is_null = no_null;
    params[i+0].num = 10;
    
    params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
    params[i+1].buffer_length = sizeof(int8_t);
    params[i+1].buffer = v.b;
    params[i+1].length = NULL;
    params[i+1].is_null = is_null;
    params[i+1].num = 10;

D
stmt  
dapan1121 已提交
2395 2396 2397
    params[i+2].buffer_type = TSDB_DATA_TYPE_INT;
    params[i+2].buffer_length = sizeof(int32_t);
    params[i+2].buffer = v.v4;
2398 2399 2400 2401
    params[i+2].length = NULL;
    params[i+2].is_null = is_null;
    params[i+2].num = 10;

D
stmt  
dapan1121 已提交
2402 2403 2404
    params[i+3].buffer_type = TSDB_DATA_TYPE_BIGINT;
    params[i+3].buffer_length = sizeof(int64_t);
    params[i+3].buffer = v.v8;
2405 2406 2407 2408
    params[i+3].length = NULL;
    params[i+3].is_null = is_null;
    params[i+3].num = 10;

D
stmt  
dapan1121 已提交
2409 2410 2411
    params[i+4].buffer_type = TSDB_DATA_TYPE_DOUBLE;
    params[i+4].buffer_length = sizeof(double);
    params[i+4].buffer = v.f8;
2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423
    params[i+4].length = NULL;
    params[i+4].is_null = is_null;
    params[i+4].num = 10;
  }

  int64_t tts = 1591060628000;
  for (int i = 0; i < 10; ++i) {
    v.ts[i] = tts + i;
  }


  for (int i = 0; i < 1; ++i) {
D
stmt  
dapan1121 已提交
2424 2425
    tags[i+0].buffer_type = TSDB_DATA_TYPE_BOOL;
    tags[i+0].buffer = v.b;
2426 2427 2428
    tags[i+0].is_null = &one_not_null;
    tags[i+0].length = NULL;

D
stmt  
dapan1121 已提交
2429 2430
    tags[i+1].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    tags[i+1].buffer = v.v2;
2431 2432 2433
    tags[i+1].is_null = &one_not_null;
    tags[i+1].length = NULL;

D
stmt  
dapan1121 已提交
2434 2435
    tags[i+2].buffer_type = TSDB_DATA_TYPE_FLOAT;
    tags[i+2].buffer = v.f4;
2436 2437 2438
    tags[i+2].is_null = &one_not_null;
    tags[i+2].length = NULL;

D
stmt  
dapan1121 已提交
2439 2440
    tags[i+3].buffer_type = TSDB_DATA_TYPE_BINARY;
    tags[i+3].buffer = v.bin;
2441
    tags[i+3].is_null = &one_not_null;
D
stmt  
dapan1121 已提交
2442
    tags[i+3].length = (uintptr_t *)lb;
2443 2444 2445
  }


D
stmt  
dapan1121 已提交
2446
  unsigned long long starttime = taosGetTimestampUs();
2447

D
stmt  
dapan1121 已提交
2448
  char *sql = "insert into ? using stb1 tags(1,?,2,?,4,?,6.0,?,'b') (ts,b,v4,v8,f8) values(?,?,?,?,?)";
2449 2450 2451 2452 2453 2454 2455 2456 2457 2458
  int code = taos_stmt_prepare(stmt, sql, 0);
  if (code != 0){
    printf("failed to execute taos_stmt_prepare. code:0x%x\n", code);
    exit(1);
  }

  int id = 0;
  for (int zz = 0; zz < 1; zz++) {
    char buf[32];
    sprintf(buf, "m%d", zz);
D
stmt  
dapan1121 已提交
2459
    code = taos_stmt_set_tbname_tags(stmt, buf, tags);
2460
    if (code != 0){
D
stmt  
dapan1121 已提交
2461
      printf("failed to execute taos_stmt_set_tbname_tags. code:0x%x\n", code);
2462 2463
    }  

D
stmt  
dapan1121 已提交
2464
    taos_stmt_bind_param_batch(stmt, params + id * 5);
2465 2466 2467 2468 2469 2470 2471 2472 2473 2474
    taos_stmt_add_batch(stmt);
  }

  if (taos_stmt_execute(stmt) != 0) {
    printf("failed to execute insert statement.\n");
    exit(1);
  }

  ++id;

D
stmt  
dapan1121 已提交
2475
  unsigned long long endtime = taosGetTimestampUs();
2476 2477
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10));

wafwerar's avatar
wafwerar 已提交
2478 2479 2480 2481 2482 2483
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
  taosMemoryFree(tags);
2484 2485 2486 2487 2488 2489 2490 2491 2492

  return 0;
}





//1 tables 10 records
D
stmt  
dapan1121 已提交
2493
int stmt_funcb_autoctb_e1(TAOS_STMT *stmt) {
2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505
  struct {
      int64_t *ts;
      int8_t b[10];
      int8_t v1[10];
      int16_t v2[10];
      int32_t v4[10];
      int64_t v8[10];
      float f4[10];
      double f8[10];
      char bin[10][40];
  } v = {0};

wafwerar's avatar
wafwerar 已提交
2506
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
2507
  
wafwerar's avatar
wafwerar 已提交
2508
  int *lb = taosMemoryMalloc(10 * sizeof(int));
2509

wafwerar's avatar
wafwerar 已提交
2510
  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
D
dapan1121 已提交
2511
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10);
2512 2513 2514 2515

//  int one_null = 1;
  int one_not_null = 0;
  
wafwerar's avatar
wafwerar 已提交
2516 2517
  char* is_null = taosMemoryMalloc(sizeof(char) * 10);
  char* no_null = taosMemoryMalloc(sizeof(char) * 10);
2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612

  for (int i = 0; i < 10; ++i) {
    lb[i] = 40;
    no_null[i] = 0;
    is_null[i] = (i % 10 == 2) ? 1 : 0;
    v.b[i] = (int8_t)(i % 2);
    v.v1[i] = (int8_t)((i+1) % 2);
    v.v2[i] = (int16_t)i;
    v.v4[i] = (int32_t)(i+1);
    v.v8[i] = (int64_t)(i+2);
    v.f4[i] = (float)(i+3);
    v.f8[i] = (double)(i+4);
    memset(v.bin[i], '0'+i%10, 40);
  }
  
  for (int i = 0; i < 10; i+=10) {
    params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
    params[i+0].buffer_length = sizeof(int64_t);
    params[i+0].buffer = &v.ts[10*i/10];
    params[i+0].length = NULL;
    params[i+0].is_null = no_null;
    params[i+0].num = 10;
    
    params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
    params[i+1].buffer_length = sizeof(int8_t);
    params[i+1].buffer = v.b;
    params[i+1].length = NULL;
    params[i+1].is_null = is_null;
    params[i+1].num = 10;

    params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
    params[i+2].buffer_length = sizeof(int8_t);
    params[i+2].buffer = v.v1;
    params[i+2].length = NULL;
    params[i+2].is_null = is_null;
    params[i+2].num = 10;

    params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    params[i+3].buffer_length = sizeof(int16_t);
    params[i+3].buffer = v.v2;
    params[i+3].length = NULL;
    params[i+3].is_null = is_null;
    params[i+3].num = 10;

    params[i+4].buffer_type = TSDB_DATA_TYPE_INT;
    params[i+4].buffer_length = sizeof(int32_t);
    params[i+4].buffer = v.v4;
    params[i+4].length = NULL;
    params[i+4].is_null = is_null;
    params[i+4].num = 10;

    params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT;
    params[i+5].buffer_length = sizeof(int64_t);
    params[i+5].buffer = v.v8;
    params[i+5].length = NULL;
    params[i+5].is_null = is_null;
    params[i+5].num = 10;

    params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT;
    params[i+6].buffer_length = sizeof(float);
    params[i+6].buffer = v.f4;
    params[i+6].length = NULL;
    params[i+6].is_null = is_null;
    params[i+6].num = 10;

    params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE;
    params[i+7].buffer_length = sizeof(double);
    params[i+7].buffer = v.f8;
    params[i+7].length = NULL;
    params[i+7].is_null = is_null;
    params[i+7].num = 10;

    params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+8].buffer_length = 40;
    params[i+8].buffer = v.bin;
    params[i+8].length = lb;
    params[i+8].is_null = is_null;
    params[i+8].num = 10;

    params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY;
    params[i+9].buffer_length = 40;
    params[i+9].buffer = v.bin;
    params[i+9].length = lb;
    params[i+9].is_null = is_null;
    params[i+9].num = 10;
    
  }

  int64_t tts = 1591060628000;
  for (int i = 0; i < 10; ++i) {
    v.ts[i] = tts + i;
  }


  for (int i = 0; i < 1; ++i) {
D
stmt  
dapan1121 已提交
2613 2614
    tags[i+0].buffer_type = TSDB_DATA_TYPE_BOOL;
    tags[i+0].buffer = v.b;
2615 2616 2617
    tags[i+0].is_null = &one_not_null;
    tags[i+0].length = NULL;

D
stmt  
dapan1121 已提交
2618 2619
    tags[i+1].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    tags[i+1].buffer = v.v2;
2620 2621 2622
    tags[i+1].is_null = &one_not_null;
    tags[i+1].length = NULL;

D
stmt  
dapan1121 已提交
2623 2624
    tags[i+2].buffer_type = TSDB_DATA_TYPE_FLOAT;
    tags[i+2].buffer = v.f4;
2625 2626 2627
    tags[i+2].is_null = &one_not_null;
    tags[i+2].length = NULL;

D
stmt  
dapan1121 已提交
2628 2629
    tags[i+3].buffer_type = TSDB_DATA_TYPE_BINARY;
    tags[i+3].buffer = v.bin;
2630
    tags[i+3].is_null = &one_not_null;
D
stmt  
dapan1121 已提交
2631
    tags[i+3].length = (uintptr_t *)lb;
2632 2633 2634
  }


D
stmt  
dapan1121 已提交
2635
  unsigned long long starttime = taosGetTimestampUs();
2636

D
stmt  
dapan1121 已提交
2637
  char *sql = "insert into ? using stb1 (id1,id2,id3,id4,id5,id6,id7,id8,id9) tags(1,?,2,?,4,?,6.0,?,'b') values(?,?,?,?,?,?,?,?,?,?)";
2638 2639
  int code = taos_stmt_prepare(stmt, sql, 0);
  if (code != 0){
D
stmt  
dapan1121 已提交
2640
    printf("failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
2641 2642 2643 2644 2645 2646 2647
    return -1;
  }

  int id = 0;
  for (int zz = 0; zz < 1; zz++) {
    char buf[32];
    sprintf(buf, "m%d", zz);
D
stmt  
dapan1121 已提交
2648
    code = taos_stmt_set_tbname_tags(stmt, buf, tags);
2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663
    if (code != 0){
      printf("failed to execute taos_stmt_set_tbname_tags. code:0x%x\n", code);
    }  

    taos_stmt_bind_param_batch(stmt, params + id * 10);
    taos_stmt_add_batch(stmt);
  }

  if (taos_stmt_execute(stmt) != 0) {
    printf("failed to execute insert statement.\n");
    exit(1);
  }

  ++id;

D
stmt  
dapan1121 已提交
2664
  unsigned long long endtime = taosGetTimestampUs();
2665 2666
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10));

wafwerar's avatar
wafwerar 已提交
2667 2668 2669 2670 2671 2672
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
  taosMemoryFree(tags);
2673 2674 2675 2676 2677 2678 2679

  return 0;
}




D
stmt  
dapan1121 已提交
2680

2681
//1 tables 10 records
D
stmt  
dapan1121 已提交
2682
int stmt_funcb_autoctb_e2(TAOS_STMT *stmt) {
2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694
  struct {
      int64_t *ts;
      int8_t b[10];
      int8_t v1[10];
      int16_t v2[10];
      int32_t v4[10];
      int64_t v8[10];
      float f4[10];
      double f8[10];
      char bin[10][40];
  } v = {0};

wafwerar's avatar
wafwerar 已提交
2695
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
2696
  
wafwerar's avatar
wafwerar 已提交
2697
  int *lb = taosMemoryMalloc(10 * sizeof(int));
2698

wafwerar's avatar
wafwerar 已提交
2699
  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
D
dapan1121 已提交
2700
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10);
2701

D
dapan1121 已提交
2702
  unsigned long long starttime = taosGetTimestampUs();
2703

D
dapan1121 已提交
2704 2705 2706 2707 2708
  char *sql = "insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)";
  int code = taos_stmt_prepare(stmt, sql, 0);
  if (code != 0){
    printf("failed to execute taos_stmt_prepare. code:0x%x\n", code);
    exit(1);
2709 2710 2711 2712 2713 2714
  }

  int id = 0;
  for (int zz = 0; zz < 1; zz++) {
    char buf[32];
    sprintf(buf, "m%d", zz);
D
stmt  
dapan1121 已提交
2715
    code = taos_stmt_set_tbname_tags(stmt, buf, NULL);
2716
    if (code != 0){
D
stmt  
dapan1121 已提交
2717 2718
      printf("failed to execute taos_stmt_set_tbname_tags. code:%s\n", taos_stmt_errstr(stmt));
      return -1;
2719 2720
    }  

D
stmt  
dapan1121 已提交
2721
    taos_stmt_bind_param_batch(stmt, params + id * 10);
2722 2723 2724 2725 2726 2727 2728 2729 2730 2731
    taos_stmt_add_batch(stmt);
  }

  if (taos_stmt_execute(stmt) != 0) {
    printf("failed to execute insert statement.\n");
    exit(1);
  }

  ++id;

D
stmt  
dapan1121 已提交
2732
  unsigned long long endtime = taosGetTimestampUs();
2733 2734
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10));

wafwerar's avatar
wafwerar 已提交
2735 2736 2737 2738 2739 2740
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
  taosMemoryFree(tags);
2741 2742 2743 2744 2745 2746 2747 2748 2749

  return 0;
}






D
stmt  
dapan1121 已提交
2750

2751
//1 tables 10 records
D
stmt  
dapan1121 已提交
2752
int stmt_funcb_autoctb_e3(TAOS_STMT *stmt) {
2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764
  struct {
      int64_t *ts;
      int8_t b[10];
      int8_t v1[10];
      int16_t v2[10];
      int32_t v4[10];
      int64_t v8[10];
      float f4[10];
      double f8[10];
      char bin[10][40];
  } v = {0};

wafwerar's avatar
wafwerar 已提交
2765
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
2766
  
wafwerar's avatar
wafwerar 已提交
2767
  int *lb = taosMemoryMalloc(10 * sizeof(int));
2768

D
dapan1121 已提交
2769 2770
  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10);
2771 2772


D
dapan1121 已提交
2773 2774 2775 2776 2777 2778 2779 2780
  unsigned long long starttime = taosGetTimestampUs();

  char *sql = "insert into ? using stb1 (id1,id2,id3,id4,id5,id6,id7,id8,id9) tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)";
  int code = taos_stmt_prepare(stmt, sql, 0);
  if (code != 0){
    printf("failed to execute taos_stmt_prepare. code:%s\n", taos_stmt_errstr(stmt));
    return -1;
    //exit(1);
2781 2782
  }

D
dapan1121 已提交
2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794
  int id = 0;
  for (int zz = 0; zz < 1; zz++) {
    char buf[32];
    sprintf(buf, "m%d", zz);
    code = taos_stmt_set_tbname_tags(stmt, buf, NULL);
    if (code != 0){
      printf("failed to execute taos_stmt_set_tbname_tags. code:0x%x\n", code);
      return -1;
    }  

    taos_stmt_bind_param_batch(stmt, params + id * 10);
    taos_stmt_add_batch(stmt);
2795 2796
  }

D
dapan1121 已提交
2797 2798 2799 2800
  if (taos_stmt_execute(stmt) != 0) {
    printf("failed to execute insert statement.\n");
    exit(1);
  }
2801

D
dapan1121 已提交
2802
  ++id;
2803

D
dapan1121 已提交
2804 2805
  unsigned long long endtime = taosGetTimestampUs();
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10));
2806

D
dapan1121 已提交
2807 2808 2809 2810 2811 2812
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
  taosMemoryFree(tags);
2813

D
dapan1121 已提交
2814 2815
  return 0;
}
2816 2817 2818 2819




D
dapan1121 已提交
2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832
//1 tables 10 records
int stmt_funcb_autoctb_e4(TAOS_STMT *stmt) {
  struct {
      int64_t *ts;
      int8_t b[10];
      int8_t v1[10];
      int16_t v2[10];
      int32_t v4[10];
      int64_t v8[10];
      float f4[10];
      double f8[10];
      char bin[10][40];
  } v = {0};
2833

D
dapan1121 已提交
2834 2835 2836
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
  
  int *lb = taosMemoryMalloc(10 * sizeof(int));
2837

D
dapan1121 已提交
2838 2839
  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10);
D
stmt  
dapan1121 已提交
2840

D
stmt  
dapan1121 已提交
2841
  unsigned long long starttime = taosGetTimestampUs();
2842

D
stmt  
dapan1121 已提交
2843
  char *sql = "insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)";
2844 2845
  int code = taos_stmt_prepare(stmt, sql, 0);
  if (code != 0){
D
stmt  
dapan1121 已提交
2846 2847
    printf("failed to execute taos_stmt_prepare. code:%s\n", taos_stmt_errstr(stmt));
    exit(1);
2848 2849 2850
  }

  int id = 0;
D
stmt  
dapan1121 已提交
2851 2852 2853 2854 2855 2856 2857 2858
  for (int zz = 0; zz < 1; zz++) {
    char buf[32];
    sprintf(buf, "m%d", zz);
    code = taos_stmt_set_tbname_tags(stmt, buf, tags);
    if (code != 0){
      printf("failed to execute taos_stmt_set_tbname_tags. error:%s\n", taos_stmt_errstr(stmt));
      exit(1);
    }  
2859

D
stmt  
dapan1121 已提交
2860 2861 2862 2863
    code = taos_stmt_bind_param_batch(stmt, params + id * 10);
    if (code != 0) {
      printf("failed to execute taos_stmt_bind_param_batch. error:%s\n", taos_stmt_errstr(stmt));
      exit(1);
2864
    }
D
stmt  
dapan1121 已提交
2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877
    
    code = taos_stmt_bind_param_batch(stmt, params + id * 10);
    if (code != 0) {
      printf("failed to execute taos_stmt_bind_param_batch. error:%s\n", taos_stmt_errstr(stmt));
      return -1;
    }
    
    taos_stmt_add_batch(stmt);
  }

  if (taos_stmt_execute(stmt) != 0) {
    printf("failed to execute insert statement.\n");
    exit(1);
2878 2879
  }

D
stmt  
dapan1121 已提交
2880 2881
  ++id;

D
stmt  
dapan1121 已提交
2882
  unsigned long long endtime = taosGetTimestampUs();
D
stmt  
dapan1121 已提交
2883
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10));
2884

wafwerar's avatar
wafwerar 已提交
2885 2886 2887 2888 2889
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
D
stmt  
dapan1121 已提交
2890
  taosMemoryFree(tags);
2891 2892 2893 2894 2895

  return 0;
}


D
stmt  
dapan1121 已提交
2896 2897 2898 2899 2900 2901




//1 tables 10 records
int stmt_funcb_autoctb_e5(TAOS_STMT *stmt) {
2902 2903
  struct {
      int64_t *ts;
D
stmt  
dapan1121 已提交
2904 2905 2906 2907 2908 2909 2910 2911
      int8_t b[10];
      int8_t v1[10];
      int16_t v2[10];
      int32_t v4[10];
      int64_t v8[10];
      float f4[10];
      double f8[10];
      char bin[10][40];
2912 2913
  } v = {0};

D
stmt  
dapan1121 已提交
2914
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
2915
  
D
stmt  
dapan1121 已提交
2916 2917 2918
  int *lb = taosMemoryMalloc(10 * sizeof(int));

  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
D
dapan1121 已提交
2919
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10);
D
stmt  
dapan1121 已提交
2920

D
stmt  
dapan1121 已提交
2921
  unsigned long long starttime = taosGetTimestampUs();
2922

D
stmt  
dapan1121 已提交
2923 2924
  char *sql = "insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)";
  int code = taos_stmt_prepare(NULL, sql, 0);
2925
  if (code != 0){
D
stmt  
dapan1121 已提交
2926 2927
    printf("failed to execute taos_stmt_prepare. code:%s\n", taos_stmt_errstr(NULL));
    return -1;
2928 2929 2930
  }

  int id = 0;
D
stmt  
dapan1121 已提交
2931 2932 2933 2934 2935 2936 2937 2938
  for (int zz = 0; zz < 1; zz++) {
    char buf[32];
    sprintf(buf, "m%d", zz);
    code = taos_stmt_set_tbname_tags(stmt, buf, tags);
    if (code != 0){
      printf("failed to execute taos_stmt_set_tbname_tags. error:%s\n", taos_stmt_errstr(stmt));
      exit(1);
    }  
2939

D
stmt  
dapan1121 已提交
2940 2941 2942
    code = taos_stmt_bind_param_batch(stmt, params + id * 10);
    if (code != 0) {
      printf("failed to execute taos_stmt_bind_param_batch. error:%s\n", taos_stmt_errstr(stmt));
2943 2944
      exit(1);
    }
D
stmt  
dapan1121 已提交
2945 2946 2947 2948 2949 2950 2951 2952 2953
    
    code = taos_stmt_bind_param_batch(stmt, params + id * 10);
    if (code != 0) {
      printf("failed to execute taos_stmt_bind_param_batch. error:%s\n", taos_stmt_errstr(stmt));
      return -1;
    }
    
    taos_stmt_add_batch(stmt);
  }
2954

D
stmt  
dapan1121 已提交
2955 2956 2957
  if (taos_stmt_execute(stmt) != 0) {
    printf("failed to execute insert statement.\n");
    exit(1);
2958 2959
  }

D
stmt  
dapan1121 已提交
2960 2961
  ++id;

D
stmt  
dapan1121 已提交
2962
  unsigned long long endtime = taosGetTimestampUs();
D
stmt  
dapan1121 已提交
2963
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10));
2964

wafwerar's avatar
wafwerar 已提交
2965 2966 2967 2968 2969
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
D
stmt  
dapan1121 已提交
2970
  taosMemoryFree(tags);
2971 2972 2973 2974

  return 0;
}

D
stmt  
dapan1121 已提交
2975
#endif
2976 2977


D
dapan1121 已提交
2978 2979 2980 2981
void prepareCheckResultImpl(TAOS     * taos, char *tname, bool printr, int expected, bool silent) {
  char sql[255] = "SELECT * FROM ";
  int32_t rows = 0;
  
2982
  strcat(sql, tname);
D
dapan1121 已提交
2983
  bpExecQuery(taos, sql, printr, &rows);
2984 2985
  
  if (rows == expected) {
D
dapan1121 已提交
2986
    if (!silent) {
D
dapan1121 已提交
2987
      printf("***%d rows are fetched as expected from %s\n", rows, tname);
D
dapan1121 已提交
2988
    }
2989
  } else {
D
dapan1121 已提交
2990
    printf("!!!expect rows %d mis-match rows %d fetched from %s\n", expected, rows, tname);
D
dapan1121 已提交
2991
    exit(1);
2992 2993 2994 2995
  }
}


D
dapan1121 已提交
2996
void prepareCheckResult(TAOS     *taos, bool silent) {
D
stmt  
dapan1121 已提交
2997 2998 2999
  char buf[32];
  for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
    if (gCurCase->tblNum > 1) {
D
dapan1121 已提交
3000
      sprintf(buf, "%s%d", bpTbPrefix, t);
D
stmt  
dapan1121 已提交
3001
    } else {
D
dapan1121 已提交
3002
      sprintf(buf, "%s%d", bpTbPrefix, 0);
D
stmt  
dapan1121 已提交
3003 3004
    }

D
dapan1121 已提交
3005
    prepareCheckResultImpl(taos, buf, gCaseCtrl.printRes, gCurCase->rowNum * gExecLoopTimes, silent);
D
stmt  
dapan1121 已提交
3006
  }
D
stmt  
dapan1121 已提交
3007 3008

  gExecLoopTimes = 1;
D
stmt  
dapan1121 已提交
3009 3010 3011
}


3012 3013 3014 3015 3016 3017 3018

//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 已提交
3019
    sql[i] = taosMemoryCalloc(1, 1048576);
3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034
  }

  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 已提交
3035
  int64_t starttime = taosGetTimestampUs();
3036 3037 3038 3039
  for (int i = 0; i < 3000; ++i) {
      result = taos_query(taos, sql[i]);
      int code = taos_errno(result);
      if (code != 0) {
D
dapan1121 已提交
3040
        printf("%d failed to query table, reason:%s\n", taos_errstr(result));
3041 3042 3043 3044 3045 3046
        taos_free_result(result);
        exit(1);
    }

    taos_free_result(result);
  }
D
stmt  
dapan1121 已提交
3047
  int64_t endtime = taosGetTimestampUs();
3048 3049 3050
  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 已提交
3051
    taosMemoryFree(sql[i]);
3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062
  }

  return 0;
}





//one table 60 records one time
int sql_perf_s1(TAOS     *taos) {
D
stmt  
dapan1121 已提交
3063
  char **sql = calloc(1, sizeof(char*) * 360000);
3064 3065 3066
  TAOS_RES *result;

  for (int i = 0; i < 360000; i++) {
wafwerar's avatar
wafwerar 已提交
3067
    sql[i] = taosMemoryCalloc(1, 9000);
3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087
  }

  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 已提交
3088
  unsigned long long starttime = taosGetTimestampUs();
3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099
  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 已提交
3100
  unsigned long long endtime = taosGetTimestampUs();
3101 3102 3103
  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 已提交
3104
    taosMemoryFree(sql[i]);
3105 3106
  }

wafwerar's avatar
wafwerar 已提交
3107
  taosMemoryFree(sql);
3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118

  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 已提交
3119
    sql[i] = taosMemoryCalloc(1, 1048576);
3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134
  }

  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 已提交
3135
  unsigned long long starttime = taosGetTimestampUs();
3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146
  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 已提交
3147
  unsigned long long endtime = taosGetTimestampUs();
3148 3149 3150
  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 已提交
3151
    taosMemoryFree(sql[i]);
3152 3153 3154 3155 3156
  }

  return 0;
}

D
stmt  
dapan1121 已提交
3157 3158
void generateCreateTableSQL(char *buf, int32_t tblIdx, int32_t colNum, int32_t *colList, bool stable) {
  int32_t blen = 0;
D
dapan1121 已提交
3159
  blen = sprintf(buf, "create table %s%d ", (stable ? bpStbPrefix : bpTbPrefix), tblIdx);
D
stmt  
dapan1121 已提交
3160 3161 3162 3163

  blen += sprintf(buf + blen, " (");
  
  for (int c = 0; c < colNum; ++c) {
D
stmt  
dapan1121 已提交
3164 3165 3166 3167
    if (c > 0) {
      blen += sprintf(buf + blen, ",");
    }
  
D
stmt  
dapan1121 已提交
3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193
    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 已提交
3194
        blen += sprintf(buf + blen, "ts timestamp");
D
stmt  
dapan1121 已提交
3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217
        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 已提交
3218

D
dapan1121 已提交
3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276
  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 已提交
3277
  if (gCaseCtrl.printCreateTblSql) {
D
dapan1121 已提交
3278
    printf("\tCreate Table SQL:%s\n", buf);
D
stmt  
dapan1121 已提交
3279
  }
D
stmt  
dapan1121 已提交
3280
}
3281

D
dapan1121 已提交
3282
void prepare(TAOS     *taos, int32_t colNum, int32_t *colList, int prepareStb) {
3283 3284 3285 3286 3287 3288 3289 3290 3291
  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 已提交
3292
    printf("!!!failed to create database, reason:%s\n", taos_errstr(result));
3293 3294 3295 3296 3297 3298 3299 3300
    taos_free_result(result);
    exit(1);
  }
  taos_free_result(result);

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

D
dapan1121 已提交
3301
  if (!prepareStb) {
3302
    // create table
D
stmt  
dapan1121 已提交
3303
    for (int i = 0 ; i < 10; i++) {
3304
      char buf[1024];
D
stmt  
dapan1121 已提交
3305
      generateCreateTableSQL(buf, i, colNum, colList, false);
3306 3307 3308
      result = taos_query(taos, buf);
      code = taos_errno(result);
      if (code != 0) {
D
dapan1121 已提交
3309
        printf("!!!failed to create table, reason:%s\n", taos_errstr(result));
3310 3311 3312 3313 3314 3315 3316
        taos_free_result(result);
        exit(1);
      }
      taos_free_result(result);
    }
  } else {
    char buf[1024];
D
dapan1121 已提交
3317
    generateCreateTableSQL(buf, bpDefaultStbId, colNum, colList, true);
3318 3319 3320 3321
    
    result = taos_query(taos, buf);
    code = taos_errno(result);
    if (code != 0) {
D
dapan1121 已提交
3322
      printf("!!!failed to create table, reason:%s\n", taos_errstr(result));
3323 3324 3325 3326 3327 3328 3329 3330
      taos_free_result(result);
      exit(1);
    }
    taos_free_result(result);
  }

}

D
dapan1121 已提交
3331
int32_t runCase(TAOS *taos, int32_t caseIdx, int32_t caseRunIdx, bool silent) {
D
stmt  
dapan1121 已提交
3332
  TAOS_STMT *stmt = NULL;
D
dapan1121 已提交
3333 3334
  int64_t beginUs, endUs, totalUs;  
  CaseCfg cfg = gCase[caseIdx];
D
dapan1121 已提交
3335
  CaseCfg cfgBk;
D
dapan1121 已提交
3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349
  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 已提交
3350
    
D
stmt  
dapan1121 已提交
3351
    gCurCase = &cfg;
D
dapan1121 已提交
3352 3353 3354 3355 3356 3357 3358 3359 3360
  }
  
  if (gCaseCtrl.runTimes) {
    gCurCase->runTimes = gCaseCtrl.runTimes;
  }
  
  if (gCaseCtrl.rowNum) {
    gCurCase->rowNum = gCaseCtrl.rowNum;
  }
D
dapan 已提交
3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371

  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 已提交
3372 3373 3374
  
  if (gCurCase->fullCol) {
    gCurCase->bindColNum = gCurCase->colNum;
D
dapan 已提交
3375 3376 3377
    if (gCurCase->autoCreateTbl) {
      gCurCase->bindTagNum = gCurCase->colNum;
    }
D
dapan1121 已提交
3378 3379 3380 3381 3382 3383 3384
  }
  
  gCurCase->bindNullNum = gCaseCtrl.bindNullNum;
  if (gCaseCtrl.bindColNum) {
    gCurCase->bindColNum = gCaseCtrl.bindColNum;
    gCurCase->fullCol = false;
  }
D
dapan1121 已提交
3385 3386 3387 3388
  if (gCaseCtrl.bindTagNum) {
    gCurCase->bindTagNum = gCaseCtrl.bindTagNum;
    gCurCase->fullCol = false;
  }
D
dapan1121 已提交
3389 3390 3391 3392 3393 3394 3395
  if (gCaseCtrl.bindRowNum) {
    gCurCase->bindRowNum = gCaseCtrl.bindRowNum;
  }
  if (gCaseCtrl.bindColTypeNum) {
    gCurCase->bindColNum = gCaseCtrl.bindColTypeNum;
    gCurCase->fullCol = false;
  }
D
dapan1121 已提交
3396 3397 3398 3399
  if (gCaseCtrl.bindTagTypeNum) {
    gCurCase->bindTagNum = gCaseCtrl.bindTagTypeNum;
    gCurCase->fullCol = false;
  }
D
stmt  
dapan1121 已提交
3400

D
dapan1121 已提交
3401 3402 3403 3404 3405
  if (!silent) {
    printf("* Case %d - [%s]%s Begin *\n", caseRunIdx, gCaseCtrl.caseCatalog, gCurCase->caseDesc);
  }
  
  totalUs = 0;
D
dapan1121 已提交
3406
  cfgBk = cfg;
D
dapan1121 已提交
3407 3408
  for (int32_t n = 0; n < gCurCase->runTimes; ++n) {
    if (gCurCase->preCaseIdx < 0) {
D
dapan 已提交
3409
      prepare(taos, gCurCase->colNum, gCurCase->colList, gCurCase->autoCreateTbl);
D
stmt  
dapan1121 已提交
3410 3411
    }
    
D
dapan1121 已提交
3412 3413 3414 3415
    beginUs = taosGetTimestampUs();
   
    stmt = taos_stmt_init(taos);
    if (NULL == stmt) {
D
dapan1121 已提交
3416
      printf("!!!taos_stmt_init failed, error:%s\n", taos_stmt_errstr(stmt));
D
dapan1121 已提交
3417
      exit(1);
D
stmt  
dapan1121 已提交
3418
    }
D
dapan1121 已提交
3419 3420 3421 3422 3423 3424 3425
  
    (*gCurCase->runFn)(stmt, taos);
  
    taos_stmt_close(stmt);
  
    endUs = taosGetTimestampUs();
    totalUs += (endUs - beginUs);
D
dapan1121 已提交
3426

D
dapan1121 已提交
3427
    prepareCheckResult(taos, silent);
D
dapan1121 已提交
3428 3429

    cfg = cfgBk;
D
dapan1121 已提交
3430
  }
D
dapan1121 已提交
3431

D
dapan1121 已提交
3432 3433 3434 3435 3436 3437
  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 已提交
3438

D
dapan1121 已提交
3439 3440 3441 3442 3443
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;
3444

D
dapan1121 已提交
3445 3446 3447 3448
  for (int32_t i = caseIdx; i < sizeof(gCase)/sizeof(gCase[0]); ++i) {
    if (gCaseCtrl.caseNum > 0 && caseNum >= gCaseCtrl.caseNum) {
      break;
    }
3449

D
dapan1121 已提交
3450 3451 3452
    if (gCaseCtrl.caseRunNum > 0 && caseRunNum >= gCaseCtrl.caseRunNum) {
      break;
    }
D
dapan1121 已提交
3453

D
dapan1121 已提交
3454 3455 3456 3457
    if (gCaseCtrl.caseRunIdx >= 0 && caseRunIdx < gCaseCtrl.caseRunIdx) {
      caseRunIdx++;
      continue;
    }
D
dapan1121 已提交
3458

D
dapan1121 已提交
3459 3460
    if (runCase(taos, i, caseRunIdx, false)) {
      continue;
3461
    }
D
stmt  
dapan1121 已提交
3462

D
dapan1121 已提交
3463 3464
    caseRunIdx++;
    caseNum++;
D
dapan1121 已提交
3465
    caseRunNum++;
D
stmt  
dapan1121 已提交
3466
  }
3467

D
stmt  
dapan1121 已提交
3468 3469
  return NULL;
}
D
stmt  
dapan1121 已提交
3470

D
stmt  
dapan1121 已提交
3471
void runAll(TAOS *taos) {
D
dapan1121 已提交
3472 3473
#if 1

D
dapan1121 已提交
3474 3475
  strcpy(gCaseCtrl.caseCatalog, "Normal Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
dapan1121 已提交
3476
  runCaseList(taos);
D
dapan 已提交
3477

D
dapan1121 已提交
3478

D
dapan 已提交
3479 3480 3481 3482 3483
  strcpy(gCaseCtrl.caseCatalog, "Auto Create Table Test");
  gCaseCtrl.autoCreateTbl = true;
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
  runCaseList(taos);
  gCaseCtrl.autoCreateTbl = false;
D
dapan1121 已提交
3484
  
D
dapan 已提交
3485
#endif
D
stmt  
dapan1121 已提交
3486

D
dapan 已提交
3487
/*
D
dapan1121 已提交
3488 3489
  strcpy(gCaseCtrl.caseCatalog, "Null Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
3490
  gCaseCtrl.bindNullNum = 1;
D
dapan1121 已提交
3491
  runCaseList(taos);
D
stmt  
dapan1121 已提交
3492
  gCaseCtrl.bindNullNum = 0;
D
stmt  
dapan1121 已提交
3493

D
dapan1121 已提交
3494 3495
  strcpy(gCaseCtrl.caseCatalog, "Bind Row Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
3496
  gCaseCtrl.bindRowNum = 1;
D
dapan1121 已提交
3497
  runCaseList(taos);
D
stmt  
dapan1121 已提交
3498
  gCaseCtrl.bindRowNum = 0;
D
stmt  
dapan1121 已提交
3499

D
dapan1121 已提交
3500 3501
  strcpy(gCaseCtrl.caseCatalog, "Row Num Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
3502
  gCaseCtrl.rowNum = 1000;
D
stmt  
dapan1121 已提交
3503
  gCaseCtrl.printRes = false;
D
dapan1121 已提交
3504
  runCaseList(taos);
D
stmt  
dapan1121 已提交
3505 3506
  gCaseCtrl.rowNum = 0;
  gCaseCtrl.printRes = true;
D
dapan1121 已提交
3507
*/
D
stmt  
dapan1121 已提交
3508

D
dapan1121 已提交
3509 3510
  strcpy(gCaseCtrl.caseCatalog, "Runtimes Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
3511
  gCaseCtrl.runTimes = 2;
D
dapan1121 已提交
3512
  runCaseList(taos);
D
stmt  
dapan1121 已提交
3513
  gCaseCtrl.runTimes = 0;
3514

D
dapan1121 已提交
3515
#if 1
D
dapan1121 已提交
3516 3517
  strcpy(gCaseCtrl.caseCatalog, "Check Param Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
3518
  gCaseCtrl.checkParamNum = true;
D
dapan1121 已提交
3519
  runCaseList(taos);
D
stmt  
dapan1121 已提交
3520
  gCaseCtrl.checkParamNum = false;
D
dapan1121 已提交
3521
#endif
3522

D
dapan1121 已提交
3523
/*
D
dapan1121 已提交
3524 3525
  strcpy(gCaseCtrl.caseCatalog, "Bind Col Num Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
3526
  gCaseCtrl.bindColNum = 6;
D
dapan1121 已提交
3527
  runCaseList(taos);
D
stmt  
dapan1121 已提交
3528
  gCaseCtrl.bindColNum = 0;
3529

D
dapan1121 已提交
3530 3531
  strcpy(gCaseCtrl.caseCatalog, "Bind Col Type Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
3532
  gCaseCtrl.bindColTypeNum = tListLen(bindColTypeList);
D
stmt  
dapan1121 已提交
3533
  gCaseCtrl.bindColTypeList = bindColTypeList;  
D
dapan1121 已提交
3534
  runCaseList(taos);
D
dapan 已提交
3535 3536
*/

D
dapan1121 已提交
3537
  printf("All Test End\n");  
3538 3539 3540 3541
}

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

D
stmt  
dapan1121 已提交
3544 3545
  srand(time(NULL));
  
3546 3547 3548 3549 3550 3551
  // connect to server
  if (argc < 2) {
    printf("please input server ip \n");
    return 0;
  }

D
stmt  
dapan1121 已提交
3552
  taos = taos_connect(argv[1], "root", "taosdata", NULL, 0);
3553 3554 3555 3556 3557
  if (taos == NULL) {
    printf("failed to connect to db, reason:%s\n", taos_errstr(taos));
    exit(1);
  }   

D
stmt  
dapan1121 已提交
3558
  runAll(taos);
3559 3560 3561 3562

  return 0;
}