batchprepare.c 88.6 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_SMALLINT, TSDB_DATA_TYPE_DOUBLE};
int32_t optrIdxList[] = {0, 1, 2};
D
dapan1121 已提交
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

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

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

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


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

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

51
typedef struct {
D
stmt  
dapan1121 已提交
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
  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 已提交
67
  TAOS_MULTI_BIND* pBind;
D
stmt  
dapan1121 已提交
68 69 70 71 72 73 74 75
  char*         sql;
  int32_t*      colTypes;
  int32_t       colNum;
} BindData;

int32_t gVarCharSize = 10;
int32_t gVarCharLen = 5;

D
stmt  
dapan1121 已提交
76
int32_t gExecLoopTimes = 1; // no change
D
stmt  
dapan1121 已提交
77
int32_t gFullColNum = tListLen(fullColList);
D
stmt  
dapan1121 已提交
78

D
dapan1121 已提交
79 80 81 82 83 84 85 86 87 88 89 90 91
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);
int querySUBTTest1(TAOS_STMT *stmt, TAOS *taos);

enum {
  TTYPE_INSERT = 1,
  TTYPE_QUERY,
};
D
stmt  
dapan1121 已提交
92 93 94 95

typedef struct {
  char     caseDesc[128];
  int32_t  colNum;
D
stmt  
dapan1121 已提交
96
  int32_t *colList;         // full table column list
D
dapan1121 已提交
97 98
  int32_t  testType;     
  bool     prepareStb;
D
stmt  
dapan1121 已提交
99
  bool     fullCol;
D
dapan1121 已提交
100
  int32_t  (*runFn)(TAOS_STMT*, TAOS*);
D
stmt  
dapan1121 已提交
101 102 103
  int32_t  tblNum;
  int32_t  rowNum;
  int32_t  bindRowNum;
D
stmt  
dapan1121 已提交
104
  int32_t  bindColNum;      // equal colNum in full column case
D
stmt  
dapan1121 已提交
105 106
  int32_t  bindNullNum;
  int32_t  runTimes;
D
dapan1121 已提交
107
  int32_t  preCaseIdx;
D
stmt  
dapan1121 已提交
108 109 110
} CaseCfg;

CaseCfg gCase[] = {
D
dapan1121 已提交
111 112 113 114 115 116 117 118 119 120
  {"insert:MBSE1-FULL", tListLen(shortColList), shortColList, TTYPE_INSERT, false, true, insertMBSETest1,  1, 10, 10, 0, 0, 1, -1},
  {"insert:MBSE1-FULL", tListLen(shortColList), shortColList, TTYPE_INSERT, false, true, insertMBSETest1, 10, 100, 10, 0, 0, 1, -1},

  {"insert:MBSE1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBSETest1, 10, 10, 2, 0, 0, 1, -1},
  {"insert:MBSE1-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBSETest1, 10, 10, 2, 12, 0, 1, -1},
  {"insert:MBSE1-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBSETest1, 10, 10, 2, 2, 0, 1, -1},

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

D
dapan1121 已提交
122 123 124
  {"insert:MBME1-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBMETest1, 10, 10, 2, 0, 0, 1, -1},
  {"insert:MBME1-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest1, 10, 10, 2, 12, 0, 1, -1},
  {"insert:MBME1-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest1, 10, 10, 2, 2, 0, 1, -1},
D
stmt  
dapan1121 已提交
125

D
dapan1121 已提交
126 127 128 129
  // 11
  {"insert:MBME2-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBMETest2, 10, 10, 2, 0, 0, 1, -1},
  {"insert:MBME2-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest2, 10, 10, 2, 12, 0, 1, -1},
  {"insert:MBME2-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest2, 10, 10, 2, 2, 0, 1, -1},
D
stmt  
dapan1121 已提交
130

D
dapan1121 已提交
131 132 133
  {"insert:MBME3-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBMETest3, 10, 10, 2, 0, 0, 1, -1},
  {"insert:MBME3-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest3, 10, 10, 2, 12, 0, 1, -1},
  {"insert:MBME3-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest3, 10, 10, 2, 2, 0, 1, -1},
D
stmt  
dapan1121 已提交
134

D
dapan1121 已提交
135 136 137
  {"insert:MBME4-FULL", tListLen(fullColList), fullColList, TTYPE_INSERT, false, true, insertMBMETest4, 10, 10, 2, 0, 0, 1, -1},
  {"insert:MBME4-C012", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest4, 10, 10, 2, 12, 0, 1, -1},
  {"insert:MBME4-C002", tListLen(fullColList), fullColList, TTYPE_INSERT, false, false, insertMBMETest4, 10, 10, 2, 2, 0, 1, -1},
D
stmt  
dapan1121 已提交
138

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

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

D
stmt  
dapan1121 已提交
145 146 147
};

CaseCfg *gCurCase = NULL;
D
stmt  
dapan1121 已提交
148 149

typedef struct {
D
dapan1121 已提交
150
  char     caseCatalog[255];
D
stmt  
dapan1121 已提交
151
  int32_t  bindNullNum;
D
dapan1121 已提交
152
  bool     prepareStb;
D
stmt  
dapan1121 已提交
153
  bool     checkParamNum;
D
stmt  
dapan1121 已提交
154
  bool     printRes;
D
stmt  
dapan1121 已提交
155
  bool     printCreateTblSql;
D
dapan1121 已提交
156 157
  bool     printQuerySql;
  bool     printStmtSql;
D
stmt  
dapan1121 已提交
158
  int32_t  rowNum;               //row num for one table
D
stmt  
dapan1121 已提交
159
  int32_t  bindColNum;
D
stmt  
dapan1121 已提交
160
  int32_t  bindRowNum;           //row num for once bind
D
stmt  
dapan1121 已提交
161 162
  int32_t  bindColTypeNum;
  int32_t* bindColTypeList;
D
dapan1121 已提交
163 164
  int32_t  optrIdxListNum;
  int32_t* optrIdxList;
D
stmt  
dapan1121 已提交
165
  int32_t  runTimes;
D
dapan1121 已提交
166 167 168 169
  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 已提交
170 171
} CaseCtrl;

D
dapan1121 已提交
172 173
#if 0
CaseCtrl gCaseCtrl = { // default
D
dapan1121 已提交
174 175 176 177 178 179 180 181
  .bindNullNum = 0,
  .prepareStb = false,
  .printCreateTblSql = false,
  .printQuerySql = true,
  .printStmtSql = true,
  .rowNum = 0,
  .bindColNum = 0,
  .bindRowNum = 0,
D
dapan1121 已提交
182 183 184 185
  .bindColTypeNum = 0,
  .bindColTypeList = NULL,
  .optrIdxListNum = 0,
  .optrIdxList = NULL,
D
dapan1121 已提交
186 187 188
  .checkParamNum = false,
  .printRes = true,
  .runTimes = 0,
D
dapan1121 已提交
189 190
  .caseIdx = -1,
  .caseNum = -1,
D
dapan1121 已提交
191
  .caseRunIdx = -1,
D
dapan1121 已提交
192 193 194
  .caseRunNum = -1,
};
#endif
D
dapan1121 已提交
195

D
dapan1121 已提交
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
#if 0
CaseCtrl gCaseCtrl = {  // query case with specified col&oper
  .bindNullNum = 0,
  .prepareStb = false,
  .printCreateTblSql = false,
  .printQuerySql = true,
  .printStmtSql = true,
  .rowNum = 0,
  .bindColNum = 0,
  .bindRowNum = 0,
  .bindColTypeNum = 0,
  .bindColTypeList = NULL,
  .optrIdxListNum = 0,
  .optrIdxList = NULL,
  .checkParamNum = false,
  .printRes = true,
  .runTimes = 0,
  .caseRunIdx = -1,
  .optrIdxListNum = 0,
  .optrIdxList = NULL,
  .bindColTypeNum = 0,
  .bindColTypeList = NULL,
D
dapan1121 已提交
218
  .caseIdx = 22,
D
dapan1121 已提交
219 220 221
  .caseNum = 1,
  .caseRunNum = 1,
};
D
dapan1121 已提交
222 223 224 225
#endif

#if 1
CaseCtrl gCaseCtrl = {  // query case with specified col&oper
D
stmt  
dapan1121 已提交
226
  .bindNullNum = 0,
D
dapan1121 已提交
227
  .prepareStb = false,
D
stmt  
dapan1121 已提交
228
  .printCreateTblSql = false,
D
dapan1121 已提交
229 230
  .printQuerySql = true,
  .printStmtSql = true,
D
stmt  
dapan1121 已提交
231
  .rowNum = 0,
D
stmt  
dapan1121 已提交
232 233
  .bindColNum = 0,
  .bindRowNum = 0,
D
dapan1121 已提交
234 235 236 237 238
  .bindColTypeNum = 0,
  .bindColTypeList = NULL,
  .optrIdxListNum = 0,
  .optrIdxList = NULL,
  .checkParamNum = true,
D
stmt  
dapan1121 已提交
239 240
  .printRes = true,
  .runTimes = 0,
D
dapan1121 已提交
241
  .caseRunIdx = -1,
D
dapan1121 已提交
242 243 244 245 246 247
  .optrIdxListNum = tListLen(optrIdxList),
  .optrIdxList = optrIdxList,
  .bindColTypeNum = tListLen(bindColTypeList),
  .bindColTypeList = bindColTypeList,
  .caseIdx = 22,
  .caseNum = 1,
D
dapan1121 已提交
248
  .caseRunNum = 1,
D
stmt  
dapan1121 已提交
249
};
D
dapan1121 已提交
250 251
#endif

D
stmt  
dapan1121 已提交
252 253
int32_t taosGetTimeOfDay(struct timeval *tv) {
  return gettimeofday(tv, NULL);
254
}
D
stmt  
dapan1121 已提交
255
void *taosMemoryMalloc(uint64_t size) {
D
stmt  
dapan1121 已提交
256 257 258
  return malloc(size);
}

D
stmt  
dapan1121 已提交
259 260 261 262 263
void *taosMemoryCalloc(int32_t num, int32_t size) {
  return calloc(num, size);
}
void taosMemoryFree(const void *ptr) {
  if (ptr == NULL) return;
264

D
stmt  
dapan1121 已提交
265 266
  return free((void*)ptr);
}
267

D
stmt  
dapan1121 已提交
268 269 270 271 272 273
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 已提交
274 275 276 277 278
static int64_t taosGetTimestampUs() {
  struct timeval systemTime;
  taosGetTimeOfDay(&systemTime);
  return (int64_t)systemTime.tv_sec * 1000000L + (int64_t)systemTime.tv_usec;
}
279

D
dapan1121 已提交
280
bool colExists(TAOS_MULTI_BIND* pBind, int32_t dataType) {
D
stmt  
dapan1121 已提交
281 282 283 284 285 286 287 288 289
  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 已提交
290

D
stmt  
dapan1121 已提交
291 292 293 294
    ++i;
  }
}

D
stmt  
dapan1121 已提交
295
void generateInsertSQL(BindData *data) {
D
dapan1121 已提交
296 297 298 299 300 301
  int32_t len = 0;
  if (gCurCase->tblNum > 1) {
    len = sprintf(data->sql, "insert into ? ");
  } else {
    len = sprintf(data->sql, "insert into %s0 ", bpTbPrefix);
  }
D
stmt  
dapan1121 已提交
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
  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 已提交
352
          printf("!!!invalid col type:%d", data->pBind[c].buffer_type);
D
stmt  
dapan1121 已提交
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
          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 已提交
368

D
dapan1121 已提交
369
  if (gCaseCtrl.printStmtSql) {
D
dapan1121 已提交
370
    printf("\tSQL: %s\n", data->sql);
D
stmt  
dapan1121 已提交
371
  }  
D
stmt  
dapan1121 已提交
372
}
D
stmt  
dapan1121 已提交
373

D
dapan1121 已提交
374
void bpAppendOperatorParam(BindData *data, int32_t *len, int32_t dataType, int32_t idx) {
D
dapan1121 已提交
375
  OperInfo *pInfo = NULL;
D
dapan1121 已提交
376 377 378

  if (gCaseCtrl.optrIdxListNum > 0) {
    pInfo = &operInfo[gCaseCtrl.optrIdxList[idx]];
D
dapan1121 已提交
379
  } else {
D
dapan1121 已提交
380 381 382 383 384
    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 已提交
385
  }
D
dapan1121 已提交
386
  
D
dapan1121 已提交
387 388 389 390 391 392 393 394 395
  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 已提交
396
      printf("!!!invalid paramNum:%d\n", pInfo->paramNum);
D
dapan1121 已提交
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
      exit(1);
  }
}

void generateQuerySQL(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:
D
dapan1121 已提交
452
          printf("!!!invalid col type:%d", data->pBind[c].buffer_type);
D
dapan1121 已提交
453 454 455
          exit(1);
      }
      
D
dapan1121 已提交
456
      bpAppendOperatorParam(data, &len, data->pBind[c].buffer_type, c);
D
dapan1121 已提交
457 458 459 460
    }
  }

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

D
dapan1121 已提交
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
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 已提交
488

D
stmt  
dapan1121 已提交
489 490
void generateDataType(BindData *data, int32_t bindIdx, int32_t colIdx, int32_t *dataType) {
  if (bindIdx < gCurCase->bindColNum) {
D
stmt  
dapan1121 已提交
491
    if (gCaseCtrl.bindColTypeNum) {
D
stmt  
dapan1121 已提交
492 493
      *dataType = gCaseCtrl.bindColTypeList[colIdx];
      return;
D
stmt  
dapan1121 已提交
494 495 496
    } else if (gCurCase->fullCol) {
      *dataType = gCurCase->colList[bindIdx];
      return;
D
stmt  
dapan1121 已提交
497 498 499 500
    } else if (0 == colIdx) {
      *dataType = TSDB_DATA_TYPE_TIMESTAMP;
      return;
    } else {
D
stmt  
dapan1121 已提交
501 502 503 504 505 506 507
      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 已提交
508

D
stmt  
dapan1121 已提交
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530
        if (colExists(data->pBind, *dataType)) {
          continue;
        }
        
        break;
      }
    }
  } else {
    *dataType = data->pBind[bindIdx%gCurCase->bindColNum].buffer_type;
  }
}

int32_t prepareColData(BindData *data, int32_t bindIdx, int32_t rowIdx, int32_t colIdx) {
  int32_t dataType = TSDB_DATA_TYPE_TIMESTAMP;

  generateDataType(data, bindIdx, colIdx, &dataType);

  switch (dataType) {  
    case TSDB_DATA_TYPE_BOOL:
      data->pBind[bindIdx].buffer_length = sizeof(bool);
      data->pBind[bindIdx].buffer = data->boolData + rowIdx;
      data->pBind[bindIdx].length = NULL;
D
stmt  
dapan1121 已提交
531
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
532 533 534 535 536
      break;
    case TSDB_DATA_TYPE_TINYINT:
      data->pBind[bindIdx].buffer_length = sizeof(int8_t);
      data->pBind[bindIdx].buffer = data->tinyData + rowIdx;
      data->pBind[bindIdx].length = NULL;
D
stmt  
dapan1121 已提交
537
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
538 539 540 541 542
      break;
    case TSDB_DATA_TYPE_SMALLINT:
      data->pBind[bindIdx].buffer_length = sizeof(int16_t);
      data->pBind[bindIdx].buffer = data->smallData + rowIdx;
      data->pBind[bindIdx].length = NULL;
D
stmt  
dapan1121 已提交
543
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
544 545 546 547 548
      break;
    case TSDB_DATA_TYPE_INT:
      data->pBind[bindIdx].buffer_length = sizeof(int32_t);
      data->pBind[bindIdx].buffer = data->intData + rowIdx;
      data->pBind[bindIdx].length = NULL;
D
stmt  
dapan1121 已提交
549
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
550 551 552 553 554
      break;
    case TSDB_DATA_TYPE_BIGINT:
      data->pBind[bindIdx].buffer_length = sizeof(int64_t);
      data->pBind[bindIdx].buffer = data->bigData + rowIdx;
      data->pBind[bindIdx].length = NULL;
D
stmt  
dapan1121 已提交
555
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
556 557 558 559 560
      break;
    case TSDB_DATA_TYPE_FLOAT:
      data->pBind[bindIdx].buffer_length = sizeof(float);
      data->pBind[bindIdx].buffer = data->floatData + rowIdx;
      data->pBind[bindIdx].length = NULL;
D
stmt  
dapan1121 已提交
561
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
562 563 564 565 566
      break;
    case TSDB_DATA_TYPE_DOUBLE:
      data->pBind[bindIdx].buffer_length = sizeof(double);
      data->pBind[bindIdx].buffer = data->doubleData + rowIdx;
      data->pBind[bindIdx].length = NULL;
D
stmt  
dapan1121 已提交
567
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
568 569 570
      break;
    case TSDB_DATA_TYPE_VARCHAR:
      data->pBind[bindIdx].buffer_length = gVarCharSize;
D
stmt  
dapan1121 已提交
571
      data->pBind[bindIdx].buffer = data->binaryData + rowIdx * gVarCharSize;
D
stmt  
dapan1121 已提交
572
      data->pBind[bindIdx].length = data->binaryLen;
D
stmt  
dapan1121 已提交
573
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
574 575 576 577 578 579 580 581 582
      break;
    case TSDB_DATA_TYPE_TIMESTAMP:
      data->pBind[bindIdx].buffer_length = sizeof(int64_t);
      data->pBind[bindIdx].buffer = data->tsData + rowIdx;
      data->pBind[bindIdx].length = NULL;
      data->pBind[bindIdx].is_null = NULL;
      break;
    case TSDB_DATA_TYPE_NCHAR:
      data->pBind[bindIdx].buffer_length = gVarCharSize;
D
stmt  
dapan1121 已提交
583
      data->pBind[bindIdx].buffer = data->binaryData + rowIdx * gVarCharSize;
D
stmt  
dapan1121 已提交
584
      data->pBind[bindIdx].length = data->binaryLen;
D
stmt  
dapan1121 已提交
585
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
586 587 588 589 590
      break;
    case TSDB_DATA_TYPE_UTINYINT:
      data->pBind[bindIdx].buffer_length = sizeof(uint8_t);
      data->pBind[bindIdx].buffer = data->utinyData + rowIdx;
      data->pBind[bindIdx].length = NULL;
D
stmt  
dapan1121 已提交
591
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
592 593 594 595 596
      break;
    case TSDB_DATA_TYPE_USMALLINT:
      data->pBind[bindIdx].buffer_length = sizeof(uint16_t);
      data->pBind[bindIdx].buffer = data->usmallData + rowIdx;
      data->pBind[bindIdx].length = NULL;
D
stmt  
dapan1121 已提交
597
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
598 599 600 601 602
      break;
    case TSDB_DATA_TYPE_UINT:
      data->pBind[bindIdx].buffer_length = sizeof(uint32_t);
      data->pBind[bindIdx].buffer = data->uintData + rowIdx;
      data->pBind[bindIdx].length = NULL;
D
stmt  
dapan1121 已提交
603
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
604 605 606 607 608
      break;
    case TSDB_DATA_TYPE_UBIGINT:
      data->pBind[bindIdx].buffer_length = sizeof(uint64_t);
      data->pBind[bindIdx].buffer = data->ubigData + rowIdx;
      data->pBind[bindIdx].length = NULL;
D
stmt  
dapan1121 已提交
609
      data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL;
D
stmt  
dapan1121 已提交
610 611
      break;
    default:
D
dapan1121 已提交
612
      printf("!!!invalid col type:%d", dataType);
D
stmt  
dapan1121 已提交
613 614 615 616 617 618 619 620 621 622
      exit(1);
  }

  data->pBind[bindIdx].buffer_type = dataType;
  data->pBind[bindIdx].num = gCurCase->bindRowNum;

  return 0;
}


D
dapan1121 已提交
623
int32_t prepareInsertData(BindData *data) {
D
stmt  
dapan1121 已提交
624 625 626 627 628 629
  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 已提交
630
  data->pBind = taosMemoryCalloc((allRowNum/gCurCase->bindRowNum)*gCurCase->bindColNum, sizeof(TAOS_MULTI_BIND));
D
stmt  
dapan1121 已提交
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650
  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 已提交
651 652 653 654 655 656 657 658 659 660 661
    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 已提交
662 663 664 665 666 667 668 669 670 671 672 673 674
    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) {
      prepareColData(data, b*gCurCase->bindColNum+c, b*gCurCase->bindRowNum, c);
    }
  }

D
stmt  
dapan1121 已提交
675
  generateInsertSQL(data);
D
stmt  
dapan1121 已提交
676 677 678 679
  
  return 0;
}

D
dapan1121 已提交
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 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 737
int32_t prepareQueryData(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) {
      prepareColData(data, b*gCurCase->bindColNum+c, b*gCurCase->bindRowNum, c);
    }
  }

  generateQuerySQL(data, tblIdx);
  
  return 0;
}


D
dapan1121 已提交
738 739


D
stmt  
dapan1121 已提交
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
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 已提交
757 758 759
  taosMemoryFree(data->colTypes);
}

D
dapan1121 已提交
760 761 762 763 764 765 766 767 768 769 770 771
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 已提交
772
      printf("\t[%s]\n", temp);
D
dapan1121 已提交
773 774 775 776 777 778 779 780
    }
  }
}

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 已提交
781
    printf("!!!failed to query table, reason:%s\n", taos_errstr(result));
D
dapan1121 已提交
782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853
    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 已提交
854
      printf("!!!invalid data type:%d\n", type);
D
dapan1121 已提交
855 856 857 858 859
      exit(1);
  }
}


D
dapan1121 已提交
860
int32_t bpBindParam(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind) {
D
stmt  
dapan1121 已提交
861 862 863 864 865
  static int32_t n = 0;
  
  if (gCurCase->bindRowNum > 1) {
    if (0 == (n++%2)) {
      if (taos_stmt_bind_param_batch(stmt, bind)) {
D
dapan1121 已提交
866
        printf("!!!taos_stmt_bind_param_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
867 868 869 870 871
        exit(1);
      }
    } else {
      for (int32_t i = 0; i < gCurCase->bindColNum; ++i) {
        if (taos_stmt_bind_single_param_batch(stmt, bind++, i)) {
D
dapan1121 已提交
872
          printf("!!!taos_stmt_bind_single_param_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
873 874 875 876 877
          exit(1);
        }
      }
    }
  } else {
D
dapan1121 已提交
878 879
    if (0 == (n++%2)) {
      if (taos_stmt_bind_param_batch(stmt, bind)) {
D
dapan1121 已提交
880
        printf("!!!taos_stmt_bind_param_batch error:%s\n", taos_stmt_errstr(stmt));
D
dapan1121 已提交
881 882 883 884
        exit(1);
      }
    } else {
      if (taos_stmt_bind_param(stmt, bind)) {
D
dapan1121 已提交
885
        printf("!!!taos_stmt_bind_param error:%s\n", taos_stmt_errstr(stmt));
D
dapan1121 已提交
886 887
        exit(1);
      }
D
stmt  
dapan1121 已提交
888 889 890 891 892 893
    }
  }

  return 0;
}

D
dapan1121 已提交
894
void bpCheckIsInsert(TAOS_STMT *stmt, int32_t insert) {
D
stmt  
dapan1121 已提交
895 896
  int32_t isInsert = 0;
  if (taos_stmt_is_insert(stmt, &isInsert)) {
D
dapan1121 已提交
897
    printf("!!!taos_stmt_is_insert error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
898 899 900
    exit(1);
  }

D
dapan1121 已提交
901
  if (insert != isInsert) {
D
dapan1121 已提交
902
    printf("!!!is insert failed\n");
D
stmt  
dapan1121 已提交
903 904 905 906 907 908 909
    exit(1);
  }
}

void bpCheckParamNum(TAOS_STMT *stmt) {
  int32_t num = 0;
  if (taos_stmt_num_params(stmt, &num)) {
D
dapan1121 已提交
910
    printf("!!!taos_stmt_num_params error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
911 912 913 914
    exit(1);
  }

  if (gCurCase->bindColNum != num) {
D
dapan1121 已提交
915
    printf("!!!is insert failed\n");
D
stmt  
dapan1121 已提交
916 917 918 919 920 921 922 923
    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 已提交
924
    printf("!!!affected rows %d mis-match with insert num %d\n", rows, insertNum);
D
stmt  
dapan1121 已提交
925 926
    exit(1);
  }
D
stmt  
dapan1121 已提交
927 928
}

D
dapan1121 已提交
929 930 931
void bpCheckAffectedRowsOnce(TAOS_STMT *stmt, int32_t expectedNum) {
  int32_t rows = taos_stmt_affected_rows_once(stmt);
  if (expectedNum != rows) {
D
dapan1121 已提交
932
    printf("!!!affected rows %d mis-match with expected num %d\n", rows, expectedNum);
D
dapan1121 已提交
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 963 964 965 966
    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 已提交
967
    printf("\tQuery SQL: %s\n", sql);
D
dapan1121 已提交
968 969 970 971
  }

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

D
dapan1121 已提交
976
  printf("***sql res num match stmt res num %d\n", stmtResNum);
D
dapan1121 已提交
977
}
D
stmt  
dapan1121 已提交
978

D
stmt  
dapan1121 已提交
979
/* prepare [settbname [bind add]] exec */
D
dapan1121 已提交
980
int insertMBSETest1(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
981
  BindData data = {0};
D
dapan1121 已提交
982
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
983 984

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

D
dapan1121 已提交
990
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
991

D
stmt  
dapan1121 已提交
992 993 994 995 996 997 998
  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(stmt, buf);
      if (code != 0){
D
dapan1121 已提交
999
        printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1000 1001 1002
        exit(1);
      }  
    }
D
stmt  
dapan1121 已提交
1003 1004 1005 1006

    if (gCaseCtrl.checkParamNum) {
      bpCheckParamNum(stmt);
    }
D
stmt  
dapan1121 已提交
1007 1008
    
    for (int32_t b = 0; b <bindTimes; ++b) {
D
stmt  
dapan1121 已提交
1009
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
1010 1011 1012 1013
        exit(1);
      }
      
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1014
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1015 1016 1017 1018 1019 1020
        exit(1);
      }
    }
  }

  if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1021
    printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1022 1023 1024
    exit(1);
  }

D
dapan1121 已提交
1025
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1026 1027 1028 1029
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);

D
stmt  
dapan1121 已提交
1030 1031 1032 1033
  return 0;
}


D
stmt  
dapan1121 已提交
1034
/* prepare [settbname bind add] exec  */
D
dapan1121 已提交
1035
int insertMBSETest2(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1036
  BindData data = {0};
D
dapan1121 已提交
1037
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1038 1039 1040

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

D
dapan1121 已提交
1045
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1046

D
stmt  
dapan1121 已提交
1047 1048 1049 1050 1051 1052 1053 1054 1055
  int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum;

  for (int32_t b = 0; b <bindTimes; ++b) {
    for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
      if (gCurCase->tblNum > 1) {
        char buf[32];
        sprintf(buf, "t%d", t);
        code = taos_stmt_set_tbname(stmt, buf);
        if (code != 0){
D
dapan1121 已提交
1056
          printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1057 1058 1059 1060
          exit(1);
        }  
      }
    
D
stmt  
dapan1121 已提交
1061
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
1062 1063
        exit(1);
      }
D
stmt  
dapan1121 已提交
1064 1065 1066 1067 1068

      if (gCaseCtrl.checkParamNum) {
        bpCheckParamNum(stmt);
      }
    
D
stmt  
dapan1121 已提交
1069
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1070
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1071 1072 1073 1074 1075 1076
        exit(1);
      }
    }
  }

  if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1077
    printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1078 1079 1080
    exit(1);
  }

D
dapan1121 已提交
1081
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1082 1083 1084 1085
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);

D
stmt  
dapan1121 已提交
1086 1087 1088 1089
  return 0;
}

/* prepare [settbname [bind add] exec] */
D
dapan1121 已提交
1090
int insertMBMETest1(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1091
  BindData data = {0};
D
dapan1121 已提交
1092
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1093 1094 1095
  
  int code = taos_stmt_prepare(stmt, data.sql, 0);
  if (code != 0){
D
dapan1121 已提交
1096
    printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1097 1098
    exit(1);
  }
D
stmt  
dapan1121 已提交
1099

D
dapan1121 已提交
1100
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1101

D
stmt  
dapan1121 已提交
1102 1103 1104 1105 1106 1107 1108
  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(stmt, buf);
      if (code != 0){
D
dapan1121 已提交
1109
        printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1110 1111 1112
        exit(1);
      }  
    }
D
stmt  
dapan1121 已提交
1113 1114 1115 1116

    if (gCaseCtrl.checkParamNum) {
      bpCheckParamNum(stmt);
    }
D
stmt  
dapan1121 已提交
1117 1118
    
    for (int32_t b = 0; b <bindTimes; ++b) {
D
stmt  
dapan1121 已提交
1119
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
1120 1121 1122 1123
        exit(1);
      }
      
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1124
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1125 1126 1127
        exit(1);
      }
    }
D
stmt  
dapan1121 已提交
1128

D
stmt  
dapan1121 已提交
1129
    if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1130
      printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1131 1132
      exit(1);
    }
D
stmt  
dapan1121 已提交
1133 1134
  }

D
dapan1121 已提交
1135
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1136 1137 1138
  bpCheckAffectedRows(stmt, 1);

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

D
stmt  
dapan1121 已提交
1140 1141 1142
  return 0;
}

D
stmt  
dapan1121 已提交
1143
/* prepare [settbname [bind add exec]] */
D
dapan1121 已提交
1144
int insertMBMETest2(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1145
  BindData data = {0};
D
dapan1121 已提交
1146
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1147 1148 1149

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

D
dapan1121 已提交
1154
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1155

D
stmt  
dapan1121 已提交
1156 1157 1158 1159 1160 1161 1162
  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(stmt, buf);
      if (code != 0){
D
dapan1121 已提交
1163
        printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1164 1165 1166 1167 1168
        exit(1);
      }  
    }
    
    for (int32_t b = 0; b <bindTimes; ++b) {
D
stmt  
dapan1121 已提交
1169
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
1170 1171
        exit(1);
      }
D
stmt  
dapan1121 已提交
1172 1173 1174 1175 1176

      if (gCaseCtrl.checkParamNum) {
        bpCheckParamNum(stmt);
      }
    
D
stmt  
dapan1121 已提交
1177
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1178
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1179 1180 1181 1182
        exit(1);
      }

      if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1183
        printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1184 1185 1186 1187 1188
        exit(1);
      }
    }
  }

D
dapan1121 已提交
1189
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1190 1191 1192
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);
D
stmt  
dapan1121 已提交
1193 1194 1195 1196

  return 0;
}

D
stmt  
dapan1121 已提交
1197
/* prepare [settbname [settbname bind add exec]] */
D
dapan1121 已提交
1198
int insertMBMETest3(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1199
  BindData data = {0};
D
dapan1121 已提交
1200
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1201 1202 1203

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

D
dapan1121 已提交
1208
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1209

D
stmt  
dapan1121 已提交
1210 1211 1212 1213 1214 1215 1216
  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(stmt, buf);
      if (code != 0){
D
dapan1121 已提交
1217
        printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1218 1219 1220
        exit(1);
      }  
    }
D
stmt  
dapan1121 已提交
1221 1222 1223 1224

    if (gCaseCtrl.checkParamNum) {
      bpCheckParamNum(stmt);
    }
D
stmt  
dapan1121 已提交
1225 1226 1227 1228 1229 1230 1231
    
    for (int32_t b = 0; b <bindTimes; ++b) {
      if (gCurCase->tblNum > 1) {
        char buf[32];
        sprintf(buf, "t%d", t);
        code = taos_stmt_set_tbname(stmt, buf);
        if (code != 0){
D
dapan1121 已提交
1232
          printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1233 1234 1235 1236
          exit(1);
        }  
      }
      
D
stmt  
dapan1121 已提交
1237
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
1238 1239 1240 1241
        exit(1);
      }
      
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1242
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1243 1244 1245 1246
        exit(1);
      }

      if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1247
        printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1248 1249 1250 1251 1252
        exit(1);
      }
    }
  }

D
dapan1121 已提交
1253
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1254 1255 1256
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);
D
stmt  
dapan1121 已提交
1257 1258 1259 1260 1261 1262

  return 0;
}


/* prepare [settbname bind add exec]   */
D
dapan1121 已提交
1263
int insertMBMETest4(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1264
  BindData data = {0};
D
dapan1121 已提交
1265
  prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1266 1267 1268

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

D
dapan1121 已提交
1273
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1274

D
stmt  
dapan1121 已提交
1275 1276 1277 1278 1279 1280 1281 1282 1283
  int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum;

  for (int32_t b = 0; b <bindTimes; ++b) {
    for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
      if (gCurCase->tblNum > 1) {
        char buf[32];
        sprintf(buf, "t%d", t);
        code = taos_stmt_set_tbname(stmt, buf);
        if (code != 0){
D
dapan1121 已提交
1284
          printf("!!!taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1285 1286 1287 1288
          exit(1);
        }  
      }
    
D
stmt  
dapan1121 已提交
1289
      if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) {
D
stmt  
dapan1121 已提交
1290 1291
        exit(1);
      }
D
stmt  
dapan1121 已提交
1292 1293 1294 1295 1296

      if (gCaseCtrl.checkParamNum) {
        bpCheckParamNum(stmt);
      }
    
D
stmt  
dapan1121 已提交
1297
      if (taos_stmt_add_batch(stmt)) {
D
dapan1121 已提交
1298
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1299 1300 1301 1302
        exit(1);
      }

      if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1303
        printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1304 1305 1306 1307 1308
        exit(1);
      }
    }
  }

D
dapan1121 已提交
1309
  bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1310 1311 1312 1313 1314 1315 1316 1317
  bpCheckAffectedRows(stmt, 1);

  destroyData(&data);

  return 0;
}

/* [prepare [settbname [bind add] exec]]   */
D
dapan1121 已提交
1318
int insertMPMETest1(TAOS_STMT *stmt, TAOS *taos) {
D
stmt  
dapan1121 已提交
1319 1320 1321 1322
  int32_t loop = 0;
  
  while (gCurCase->bindColNum >= 2) {
    BindData data = {0};
D
dapan1121 已提交
1323
    prepareInsertData(&data);
D
stmt  
dapan1121 已提交
1324 1325 1326

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

D
dapan1121 已提交
1331
    bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1332 1333 1334 1335 1336 1337 1338 1339

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

      if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1361
        printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
stmt  
dapan1121 已提交
1362 1363 1364 1365
        exit(1);
      }
    }

D
dapan1121 已提交
1366
    bpCheckIsInsert(stmt, 1);
D
stmt  
dapan1121 已提交
1367 1368 1369 1370

    destroyData(&data);

    gCurCase->bindColNum -= 2;
D
stmt  
dapan1121 已提交
1371
    gCurCase->fullCol = false;
D
stmt  
dapan1121 已提交
1372 1373 1374 1375 1376 1377 1378
    loop++;
  }

  bpCheckAffectedRows(stmt, loop);

  gExecLoopTimes = loop;
  
D
stmt  
dapan1121 已提交
1379 1380 1381
  return 0;
}

D
dapan1121 已提交
1382
/* select * from table */
D
dapan1121 已提交
1383 1384 1385 1386 1387 1388 1389 1390 1391
int querySUBTTest1(TAOS_STMT *stmt, TAOS *taos) {
  BindData data = {0};

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

    int code = taos_stmt_prepare(stmt, data.sql, 0);
    if (code != 0){
D
dapan1121 已提交
1392
      printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
D
dapan1121 已提交
1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407
      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 已提交
1408
        printf("!!!taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt));
D
dapan1121 已提交
1409 1410 1411 1412
        exit(1);
      }

      if (taos_stmt_execute(stmt) != 0) {
D
dapan1121 已提交
1413
        printf("!!!taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt));
D
dapan1121 已提交
1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427
        exit(1);
      }

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

    destroyData(&data);
  }

  return 0;
}

D
dapan1121 已提交
1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495
/* 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));
    prepareQueryData(&data, t);

    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 已提交
1496

D
stmt  
dapan1121 已提交
1497
#if 0
1498 1499

//1 tables 10 records
D
stmt  
dapan1121 已提交
1500
int stmt_funcb_autoctb1(TAOS_STMT *stmt) {
1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512
  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 已提交
1513
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
1514
  
wafwerar's avatar
wafwerar 已提交
1515
  int *lb = taosMemoryMalloc(10 * sizeof(int));
1516

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

D
stmt  
dapan1121 已提交
1520
  unsigned long long starttime = taosGetTimestampUs();
1521

D
stmt  
dapan1121 已提交
1522
  char *sql = "insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)";
1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548
  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 已提交
1549
  unsigned long long endtime = taosGetTimestampUs();
1550 1551
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10));

wafwerar's avatar
wafwerar 已提交
1552 1553 1554 1555 1556 1557
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
  taosMemoryFree(tags);
1558 1559 1560 1561 1562 1563 1564 1565

  return 0;
}




//1 tables 10 records
D
stmt  
dapan1121 已提交
1566
int stmt_funcb_autoctb2(TAOS_STMT *stmt) {
1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578
  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 已提交
1579
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
1580
  
wafwerar's avatar
wafwerar 已提交
1581
  int *lb = taosMemoryMalloc(10 * sizeof(int));
1582

wafwerar's avatar
wafwerar 已提交
1583
  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
D
dapan1121 已提交
1584
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10);
1585 1586 1587 1588

//  int one_null = 1;
  int one_not_null = 0;
  
wafwerar's avatar
wafwerar 已提交
1589 1590
  char* is_null = taosMemoryMalloc(sizeof(char) * 10);
  char* no_null = taosMemoryMalloc(sizeof(char) * 10);
1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658

  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 已提交
1659 1660 1661
    params[i+7].length = NULL;
    params[i+7].is_null = is_null;
    params[i+7].num = 10;
1662

D
stmt  
dapan1121 已提交
1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676
    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;
    
1677 1678 1679 1680 1681 1682 1683 1684 1685
  }

  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 已提交
1686 1687
    tags[i+0].buffer_type = TSDB_DATA_TYPE_INT;
    tags[i+0].buffer = v.v4;
1688 1689 1690
    tags[i+0].is_null = &one_not_null;
    tags[i+0].length = NULL;

D
stmt  
dapan1121 已提交
1691 1692
    tags[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
    tags[i+1].buffer = v.b;
1693 1694 1695
    tags[i+1].is_null = &one_not_null;
    tags[i+1].length = NULL;

D
stmt  
dapan1121 已提交
1696 1697
    tags[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
    tags[i+2].buffer = v.v1;
1698 1699 1700
    tags[i+2].is_null = &one_not_null;
    tags[i+2].length = NULL;

D
stmt  
dapan1121 已提交
1701 1702
    tags[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    tags[i+3].buffer = v.v2;
1703
    tags[i+3].is_null = &one_not_null;
D
stmt  
dapan1121 已提交
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
    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;
1730 1731 1732
  }


D
stmt  
dapan1121 已提交
1733
  unsigned long long starttime = taosGetTimestampUs();
1734

D
stmt  
dapan1121 已提交
1735
  char *sql = "insert into ? using stb1 tags(1,true,2,3,4,5.0,6.0,'a','b') values(?,?,?,?,?,?,?,?,?,?)";
1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750
  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 已提交
1751
    taos_stmt_bind_param_batch(stmt, params + id * 10);
1752 1753 1754 1755 1756 1757 1758 1759 1760 1761
    taos_stmt_add_batch(stmt);
  }

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

  ++id;

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

wafwerar's avatar
wafwerar 已提交
1765 1766 1767 1768 1769 1770
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
  taosMemoryFree(tags);
1771 1772 1773 1774 1775 1776 1777 1778 1779

  return 0;
}





//1 tables 10 records
D
stmt  
dapan1121 已提交
1780
int stmt_funcb_autoctb3(TAOS_STMT *stmt) {
1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792
  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 已提交
1793
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
1794
  
wafwerar's avatar
wafwerar 已提交
1795
  int *lb = taosMemoryMalloc(10 * sizeof(int));
1796

wafwerar's avatar
wafwerar 已提交
1797
  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
D
dapan1121 已提交
1798
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10);
1799 1800 1801 1802

//  int one_null = 1;
  int one_not_null = 0;
  
wafwerar's avatar
wafwerar 已提交
1803 1804
  char* is_null = taosMemoryMalloc(sizeof(char) * 10);
  char* no_null = taosMemoryMalloc(sizeof(char) * 10);
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 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921

  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 已提交
1922
  unsigned long long starttime = taosGetTimestampUs();
1923

D
stmt  
dapan1121 已提交
1924
  char *sql = "insert into ? using stb1 tags(1,?,2,?,4,?,6.0,?,'b') values(?,?,?,?,?,?,?,?,?,?)";
1925 1926
  int code = taos_stmt_prepare(stmt, sql, 0);
  if (code != 0){
D
stmt  
dapan1121 已提交
1927 1928
    printf("failed to execute taos_stmt_prepare. code:0x%x\n", code);
    exit(1);
1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950
  }

  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 已提交
1951
  unsigned long long endtime = taosGetTimestampUs();
1952 1953
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10));

wafwerar's avatar
wafwerar 已提交
1954 1955 1956 1957 1958 1959
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
  taosMemoryFree(tags);
1960 1961 1962 1963 1964 1965 1966 1967

  return 0;
}





D
stmt  
dapan1121 已提交
1968 1969


1970
//1 tables 10 records
D
stmt  
dapan1121 已提交
1971
int stmt_funcb_autoctb4(TAOS_STMT *stmt) {
1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983
  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 已提交
1984
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
1985
  
wafwerar's avatar
wafwerar 已提交
1986
  int *lb = taosMemoryMalloc(10 * sizeof(int));
1987

wafwerar's avatar
wafwerar 已提交
1988
  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
D
dapan1121 已提交
1989
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*5);
1990 1991 1992 1993

//  int one_null = 1;
  int one_not_null = 0;
  
wafwerar's avatar
wafwerar 已提交
1994 1995
  char* is_null = taosMemoryMalloc(sizeof(char) * 10);
  char* no_null = taosMemoryMalloc(sizeof(char) * 10);
1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010

  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 已提交
2011
  for (int i = 0; i < 5; i+=5) {
2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025
    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 已提交
2026 2027 2028
    params[i+2].buffer_type = TSDB_DATA_TYPE_INT;
    params[i+2].buffer_length = sizeof(int32_t);
    params[i+2].buffer = v.v4;
2029 2030 2031 2032
    params[i+2].length = NULL;
    params[i+2].is_null = is_null;
    params[i+2].num = 10;

D
stmt  
dapan1121 已提交
2033 2034 2035
    params[i+3].buffer_type = TSDB_DATA_TYPE_BIGINT;
    params[i+3].buffer_length = sizeof(int64_t);
    params[i+3].buffer = v.v8;
2036 2037 2038 2039
    params[i+3].length = NULL;
    params[i+3].is_null = is_null;
    params[i+3].num = 10;

D
stmt  
dapan1121 已提交
2040 2041 2042
    params[i+4].buffer_type = TSDB_DATA_TYPE_DOUBLE;
    params[i+4].buffer_length = sizeof(double);
    params[i+4].buffer = v.f8;
2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054
    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 已提交
2055 2056
    tags[i+0].buffer_type = TSDB_DATA_TYPE_BOOL;
    tags[i+0].buffer = v.b;
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_SMALLINT;
    tags[i+1].buffer = v.v2;
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_FLOAT;
    tags[i+2].buffer = v.f4;
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_BINARY;
    tags[i+3].buffer = v.bin;
2072
    tags[i+3].is_null = &one_not_null;
D
stmt  
dapan1121 已提交
2073
    tags[i+3].length = (uintptr_t *)lb;
2074 2075 2076
  }


D
stmt  
dapan1121 已提交
2077
  unsigned long long starttime = taosGetTimestampUs();
2078

D
stmt  
dapan1121 已提交
2079
  char *sql = "insert into ? using stb1 tags(1,?,2,?,4,?,6.0,?,'b') (ts,b,v4,v8,f8) values(?,?,?,?,?)";
2080 2081 2082 2083 2084 2085 2086 2087 2088 2089
  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 已提交
2090
    code = taos_stmt_set_tbname_tags(stmt, buf, tags);
2091
    if (code != 0){
D
stmt  
dapan1121 已提交
2092
      printf("failed to execute taos_stmt_set_tbname_tags. code:0x%x\n", code);
2093 2094
    }  

D
stmt  
dapan1121 已提交
2095
    taos_stmt_bind_param_batch(stmt, params + id * 5);
2096 2097 2098 2099 2100 2101 2102 2103 2104 2105
    taos_stmt_add_batch(stmt);
  }

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

  ++id;

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

wafwerar's avatar
wafwerar 已提交
2109 2110 2111 2112 2113 2114
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
  taosMemoryFree(tags);
2115 2116 2117 2118 2119 2120 2121 2122 2123

  return 0;
}





//1 tables 10 records
D
stmt  
dapan1121 已提交
2124
int stmt_funcb_autoctb_e1(TAOS_STMT *stmt) {
2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136
  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 已提交
2137
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
2138
  
wafwerar's avatar
wafwerar 已提交
2139
  int *lb = taosMemoryMalloc(10 * sizeof(int));
2140

wafwerar's avatar
wafwerar 已提交
2141
  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
D
dapan1121 已提交
2142
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10);
2143 2144 2145 2146

//  int one_null = 1;
  int one_not_null = 0;
  
wafwerar's avatar
wafwerar 已提交
2147 2148
  char* is_null = taosMemoryMalloc(sizeof(char) * 10);
  char* no_null = taosMemoryMalloc(sizeof(char) * 10);
2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243

  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 已提交
2244 2245
    tags[i+0].buffer_type = TSDB_DATA_TYPE_BOOL;
    tags[i+0].buffer = v.b;
2246 2247 2248
    tags[i+0].is_null = &one_not_null;
    tags[i+0].length = NULL;

D
stmt  
dapan1121 已提交
2249 2250
    tags[i+1].buffer_type = TSDB_DATA_TYPE_SMALLINT;
    tags[i+1].buffer = v.v2;
2251 2252 2253
    tags[i+1].is_null = &one_not_null;
    tags[i+1].length = NULL;

D
stmt  
dapan1121 已提交
2254 2255
    tags[i+2].buffer_type = TSDB_DATA_TYPE_FLOAT;
    tags[i+2].buffer = v.f4;
2256 2257 2258
    tags[i+2].is_null = &one_not_null;
    tags[i+2].length = NULL;

D
stmt  
dapan1121 已提交
2259 2260
    tags[i+3].buffer_type = TSDB_DATA_TYPE_BINARY;
    tags[i+3].buffer = v.bin;
2261
    tags[i+3].is_null = &one_not_null;
D
stmt  
dapan1121 已提交
2262
    tags[i+3].length = (uintptr_t *)lb;
2263 2264 2265
  }


D
stmt  
dapan1121 已提交
2266
  unsigned long long starttime = taosGetTimestampUs();
2267

D
stmt  
dapan1121 已提交
2268
  char *sql = "insert into ? using stb1 (id1,id2,id3,id4,id5,id6,id7,id8,id9) tags(1,?,2,?,4,?,6.0,?,'b') values(?,?,?,?,?,?,?,?,?,?)";
2269 2270
  int code = taos_stmt_prepare(stmt, sql, 0);
  if (code != 0){
D
stmt  
dapan1121 已提交
2271
    printf("failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
2272 2273 2274 2275 2276 2277 2278
    return -1;
  }

  int id = 0;
  for (int zz = 0; zz < 1; zz++) {
    char buf[32];
    sprintf(buf, "m%d", zz);
D
stmt  
dapan1121 已提交
2279
    code = taos_stmt_set_tbname_tags(stmt, buf, tags);
2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294
    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 已提交
2295
  unsigned long long endtime = taosGetTimestampUs();
2296 2297
  printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10));

wafwerar's avatar
wafwerar 已提交
2298 2299 2300 2301 2302 2303
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
  taosMemoryFree(tags);
2304 2305 2306 2307 2308 2309 2310

  return 0;
}




D
stmt  
dapan1121 已提交
2311

2312
//1 tables 10 records
D
stmt  
dapan1121 已提交
2313
int stmt_funcb_autoctb_e2(TAOS_STMT *stmt) {
2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325
  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 已提交
2326
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
2327
  
wafwerar's avatar
wafwerar 已提交
2328
  int *lb = taosMemoryMalloc(10 * sizeof(int));
2329

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

D
dapan1121 已提交
2333
  unsigned long long starttime = taosGetTimestampUs();
2334

D
dapan1121 已提交
2335 2336 2337 2338 2339
  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);
2340 2341 2342 2343 2344 2345
  }

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

D
stmt  
dapan1121 已提交
2352
    taos_stmt_bind_param_batch(stmt, params + id * 10);
2353 2354 2355 2356 2357 2358 2359 2360 2361 2362
    taos_stmt_add_batch(stmt);
  }

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

  ++id;

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

wafwerar's avatar
wafwerar 已提交
2366 2367 2368 2369 2370 2371
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
  taosMemoryFree(tags);
2372 2373 2374 2375 2376 2377 2378 2379 2380

  return 0;
}






D
stmt  
dapan1121 已提交
2381

2382
//1 tables 10 records
D
stmt  
dapan1121 已提交
2383
int stmt_funcb_autoctb_e3(TAOS_STMT *stmt) {
2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395
  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 已提交
2396
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
2397
  
wafwerar's avatar
wafwerar 已提交
2398
  int *lb = taosMemoryMalloc(10 * sizeof(int));
2399

D
dapan1121 已提交
2400 2401
  TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1);
  TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10);
2402 2403


D
dapan1121 已提交
2404 2405 2406 2407 2408 2409 2410 2411
  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);
2412 2413
  }

D
dapan1121 已提交
2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425
  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);
2426 2427
  }

D
dapan1121 已提交
2428 2429 2430 2431
  if (taos_stmt_execute(stmt) != 0) {
    printf("failed to execute insert statement.\n");
    exit(1);
  }
2432

D
dapan1121 已提交
2433
  ++id;
2434

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

D
dapan1121 已提交
2438 2439 2440 2441 2442 2443
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
  taosMemoryFree(tags);
2444

D
dapan1121 已提交
2445 2446
  return 0;
}
2447 2448 2449 2450




D
dapan1121 已提交
2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463
//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};
2464

D
dapan1121 已提交
2465 2466 2467
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
  
  int *lb = taosMemoryMalloc(10 * sizeof(int));
2468

D
dapan1121 已提交
2469 2470
  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 已提交
2471

D
stmt  
dapan1121 已提交
2472
  unsigned long long starttime = taosGetTimestampUs();
2473

D
stmt  
dapan1121 已提交
2474
  char *sql = "insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)";
2475 2476
  int code = taos_stmt_prepare(stmt, sql, 0);
  if (code != 0){
D
stmt  
dapan1121 已提交
2477 2478
    printf("failed to execute taos_stmt_prepare. code:%s\n", taos_stmt_errstr(stmt));
    exit(1);
2479 2480 2481
  }

  int id = 0;
D
stmt  
dapan1121 已提交
2482 2483 2484 2485 2486 2487 2488 2489
  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);
    }  
2490

D
stmt  
dapan1121 已提交
2491 2492 2493 2494
    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);
2495
    }
D
stmt  
dapan1121 已提交
2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508
    
    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);
2509 2510
  }

D
stmt  
dapan1121 已提交
2511 2512
  ++id;

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

wafwerar's avatar
wafwerar 已提交
2516 2517 2518 2519 2520
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
D
stmt  
dapan1121 已提交
2521
  taosMemoryFree(tags);
2522 2523 2524 2525 2526

  return 0;
}


D
stmt  
dapan1121 已提交
2527 2528 2529 2530 2531 2532




//1 tables 10 records
int stmt_funcb_autoctb_e5(TAOS_STMT *stmt) {
2533 2534
  struct {
      int64_t *ts;
D
stmt  
dapan1121 已提交
2535 2536 2537 2538 2539 2540 2541 2542
      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];
2543 2544
  } v = {0};

D
stmt  
dapan1121 已提交
2545
  v.ts = taosMemoryMalloc(sizeof(int64_t) * 1 * 10);
2546
  
D
stmt  
dapan1121 已提交
2547 2548 2549
  int *lb = taosMemoryMalloc(10 * sizeof(int));

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

D
stmt  
dapan1121 已提交
2552
  unsigned long long starttime = taosGetTimestampUs();
2553

D
stmt  
dapan1121 已提交
2554 2555
  char *sql = "insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)";
  int code = taos_stmt_prepare(NULL, sql, 0);
2556
  if (code != 0){
D
stmt  
dapan1121 已提交
2557 2558
    printf("failed to execute taos_stmt_prepare. code:%s\n", taos_stmt_errstr(NULL));
    return -1;
2559 2560 2561
  }

  int id = 0;
D
stmt  
dapan1121 已提交
2562 2563 2564 2565 2566 2567 2568 2569
  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);
    }  
2570

D
stmt  
dapan1121 已提交
2571 2572 2573
    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));
2574 2575
      exit(1);
    }
D
stmt  
dapan1121 已提交
2576 2577 2578 2579 2580 2581 2582 2583 2584
    
    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);
  }
2585

D
stmt  
dapan1121 已提交
2586 2587 2588
  if (taos_stmt_execute(stmt) != 0) {
    printf("failed to execute insert statement.\n");
    exit(1);
2589 2590
  }

D
stmt  
dapan1121 已提交
2591 2592
  ++id;

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

wafwerar's avatar
wafwerar 已提交
2596 2597 2598 2599 2600
  taosMemoryFree(v.ts);  
  taosMemoryFree(lb);
  taosMemoryFree(params);
  taosMemoryFree(is_null);
  taosMemoryFree(no_null);
D
stmt  
dapan1121 已提交
2601
  taosMemoryFree(tags);
2602 2603 2604 2605

  return 0;
}

D
stmt  
dapan1121 已提交
2606
#endif
2607 2608


D
dapan1121 已提交
2609 2610 2611 2612
void prepareCheckResultImpl(TAOS     * taos, char *tname, bool printr, int expected, bool silent) {
  char sql[255] = "SELECT * FROM ";
  int32_t rows = 0;
  
2613
  strcat(sql, tname);
D
dapan1121 已提交
2614
  bpExecQuery(taos, sql, printr, &rows);
2615 2616
  
  if (rows == expected) {
D
dapan1121 已提交
2617
    if (!silent) {
D
dapan1121 已提交
2618
      printf("***%d rows are fetched as expected from %s\n", rows, tname);
D
dapan1121 已提交
2619
    }
2620
  } else {
D
dapan1121 已提交
2621
    printf("!!!expect rows %d mis-match rows %d fetched from %s\n", expected, rows, tname);
2622 2623 2624 2625 2626
    exit(1);
  }
}


D
dapan1121 已提交
2627
void prepareCheckResult(TAOS     *taos, bool silent) {
D
stmt  
dapan1121 已提交
2628 2629 2630
  char buf[32];
  for (int32_t t = 0; t< gCurCase->tblNum; ++t) {
    if (gCurCase->tblNum > 1) {
D
dapan1121 已提交
2631
      sprintf(buf, "%s%d", bpTbPrefix, t);
D
stmt  
dapan1121 已提交
2632
    } else {
D
dapan1121 已提交
2633
      sprintf(buf, "%s%d", bpTbPrefix, 0);
D
stmt  
dapan1121 已提交
2634 2635
    }

D
dapan1121 已提交
2636
    prepareCheckResultImpl(taos, buf, gCaseCtrl.printRes, gCurCase->rowNum * gExecLoopTimes, silent);
D
stmt  
dapan1121 已提交
2637
  }
D
stmt  
dapan1121 已提交
2638 2639

  gExecLoopTimes = 1;
D
stmt  
dapan1121 已提交
2640 2641 2642
}


2643 2644 2645 2646 2647 2648 2649

//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 已提交
2650
    sql[i] = taosMemoryCalloc(1, 1048576);
2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665
  }

  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 已提交
2666
  int64_t starttime = taosGetTimestampUs();
2667 2668 2669 2670
  for (int i = 0; i < 3000; ++i) {
      result = taos_query(taos, sql[i]);
      int code = taos_errno(result);
      if (code != 0) {
D
dapan1121 已提交
2671
        printf("%d failed to query table, reason:%s\n", taos_errstr(result));
2672 2673 2674 2675 2676 2677
        taos_free_result(result);
        exit(1);
    }

    taos_free_result(result);
  }
D
stmt  
dapan1121 已提交
2678
  int64_t endtime = taosGetTimestampUs();
2679 2680 2681
  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 已提交
2682
    taosMemoryFree(sql[i]);
2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693
  }

  return 0;
}





//one table 60 records one time
int sql_perf_s1(TAOS     *taos) {
D
stmt  
dapan1121 已提交
2694
  char **sql = calloc(1, sizeof(char*) * 360000);
2695 2696 2697
  TAOS_RES *result;

  for (int i = 0; i < 360000; i++) {
wafwerar's avatar
wafwerar 已提交
2698
    sql[i] = taosMemoryCalloc(1, 9000);
2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718
  }

  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 已提交
2719
  unsigned long long starttime = taosGetTimestampUs();
2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730
  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 已提交
2731
  unsigned long long endtime = taosGetTimestampUs();
2732 2733 2734
  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 已提交
2735
    taosMemoryFree(sql[i]);
2736 2737
  }

wafwerar's avatar
wafwerar 已提交
2738
  taosMemoryFree(sql);
2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749

  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 已提交
2750
    sql[i] = taosMemoryCalloc(1, 1048576);
2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765
  }

  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 已提交
2766
  unsigned long long starttime = taosGetTimestampUs();
2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777
  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 已提交
2778
  unsigned long long endtime = taosGetTimestampUs();
2779 2780 2781
  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 已提交
2782
    taosMemoryFree(sql[i]);
2783 2784 2785 2786 2787
  }

  return 0;
}

D
stmt  
dapan1121 已提交
2788 2789
void generateCreateTableSQL(char *buf, int32_t tblIdx, int32_t colNum, int32_t *colList, bool stable) {
  int32_t blen = 0;
D
dapan1121 已提交
2790
  blen = sprintf(buf, "create table %s%d ", (stable ? bpStbPrefix : bpTbPrefix), tblIdx);
D
stmt  
dapan1121 已提交
2791 2792 2793
  if (stable) {
    blen += sprintf(buf + blen, "tags (");
    for (int c = 0; c < colNum; ++c) {
D
stmt  
dapan1121 已提交
2794 2795 2796
      if (c > 0) {
        blen += sprintf(buf + blen, ",");
      }
D
stmt  
dapan1121 已提交
2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851
      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 ts");
          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, ")");    
  }

  blen += sprintf(buf + blen, " (");
  
  for (int c = 0; c < colNum; ++c) {
D
stmt  
dapan1121 已提交
2852 2853 2854 2855
    if (c > 0) {
      blen += sprintf(buf + blen, ",");
    }
  
D
stmt  
dapan1121 已提交
2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881
    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 已提交
2882
        blen += sprintf(buf + blen, "ts timestamp");
D
stmt  
dapan1121 已提交
2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905
        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 已提交
2906

D
stmt  
dapan1121 已提交
2907
  if (gCaseCtrl.printCreateTblSql) {
D
dapan1121 已提交
2908
    printf("\tCreate Table SQL:%s\n", buf);
D
stmt  
dapan1121 已提交
2909
  }
D
stmt  
dapan1121 已提交
2910
}
2911

D
dapan1121 已提交
2912
void prepare(TAOS     *taos, int32_t colNum, int32_t *colList, int prepareStb) {
2913 2914 2915 2916 2917 2918 2919 2920 2921
  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 已提交
2922
    printf("!!!failed to create database, reason:%s\n", taos_errstr(result));
2923 2924 2925 2926 2927 2928 2929 2930
    taos_free_result(result);
    exit(1);
  }
  taos_free_result(result);

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

D
dapan1121 已提交
2931
  if (!prepareStb) {
2932
    // create table
D
stmt  
dapan1121 已提交
2933
    for (int i = 0 ; i < 10; i++) {
2934
      char buf[1024];
D
stmt  
dapan1121 已提交
2935
      generateCreateTableSQL(buf, i, colNum, colList, false);
2936 2937 2938
      result = taos_query(taos, buf);
      code = taos_errno(result);
      if (code != 0) {
D
dapan1121 已提交
2939
        printf("!!!failed to create table, reason:%s\n", taos_errstr(result));
2940 2941 2942 2943 2944 2945 2946
        taos_free_result(result);
        exit(1);
      }
      taos_free_result(result);
    }
  } else {
    char buf[1024];
D
stmt  
dapan1121 已提交
2947
    generateCreateTableSQL(buf, 1, colNum, colList, true);
2948 2949 2950 2951
    
    result = taos_query(taos, buf);
    code = taos_errno(result);
    if (code != 0) {
D
dapan1121 已提交
2952
      printf("!!!failed to create table, reason:%s\n", taos_errstr(result));
2953 2954 2955 2956 2957 2958 2959 2960
      taos_free_result(result);
      exit(1);
    }
    taos_free_result(result);
  }

}

D
dapan1121 已提交
2961
int32_t runCase(TAOS *taos, int32_t caseIdx, int32_t caseRunIdx, bool silent) {
D
stmt  
dapan1121 已提交
2962
  TAOS_STMT *stmt = NULL;
D
dapan1121 已提交
2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978
  int64_t beginUs, endUs, totalUs;  
  CaseCfg cfg = gCase[caseIdx];
  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 已提交
2979
    
D
stmt  
dapan1121 已提交
2980
    gCurCase = &cfg;
D
dapan1121 已提交
2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007
  }
  
  if (gCaseCtrl.runTimes) {
    gCurCase->runTimes = gCaseCtrl.runTimes;
  }
  
  if (gCaseCtrl.rowNum) {
    gCurCase->rowNum = gCaseCtrl.rowNum;
  }
  
  if (gCurCase->fullCol) {
    gCurCase->bindColNum = gCurCase->colNum;
  }
  
  gCurCase->bindNullNum = gCaseCtrl.bindNullNum;
  gCurCase->prepareStb = gCaseCtrl.prepareStb;
  if (gCaseCtrl.bindColNum) {
    gCurCase->bindColNum = gCaseCtrl.bindColNum;
    gCurCase->fullCol = false;
  }
  if (gCaseCtrl.bindRowNum) {
    gCurCase->bindRowNum = gCaseCtrl.bindRowNum;
  }
  if (gCaseCtrl.bindColTypeNum) {
    gCurCase->bindColNum = gCaseCtrl.bindColTypeNum;
    gCurCase->fullCol = false;
  }
D
stmt  
dapan1121 已提交
3008

D
dapan1121 已提交
3009 3010 3011 3012 3013 3014 3015 3016
  if (!silent) {
    printf("* Case %d - [%s]%s Begin *\n", caseRunIdx, gCaseCtrl.caseCatalog, gCurCase->caseDesc);
  }
  
  totalUs = 0;
  for (int32_t n = 0; n < gCurCase->runTimes; ++n) {
    if (gCurCase->preCaseIdx < 0) {
      prepare(taos, gCurCase->colNum, gCurCase->colList, gCurCase->prepareStb);
D
stmt  
dapan1121 已提交
3017 3018
    }
    
D
dapan1121 已提交
3019 3020 3021 3022
    beginUs = taosGetTimestampUs();
   
    stmt = taos_stmt_init(taos);
    if (NULL == stmt) {
D
dapan1121 已提交
3023
      printf("!!!taos_stmt_init failed, error:%s\n", taos_stmt_errstr(stmt));
D
dapan1121 已提交
3024
      exit(1);
D
stmt  
dapan1121 已提交
3025
    }
D
dapan1121 已提交
3026 3027 3028 3029 3030 3031 3032
  
    (*gCurCase->runFn)(stmt, taos);
  
    taos_stmt_close(stmt);
  
    endUs = taosGetTimestampUs();
    totalUs += (endUs - beginUs);
D
dapan1121 已提交
3033

D
dapan1121 已提交
3034 3035
    prepareCheckResult(taos, silent);
  }
D
dapan1121 已提交
3036

D
dapan1121 已提交
3037 3038 3039 3040 3041 3042
  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 已提交
3043

D
dapan1121 已提交
3044 3045 3046 3047 3048
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;
3049

D
dapan1121 已提交
3050 3051 3052 3053
  for (int32_t i = caseIdx; i < sizeof(gCase)/sizeof(gCase[0]); ++i) {
    if (gCaseCtrl.caseNum > 0 && caseNum >= gCaseCtrl.caseNum) {
      break;
    }
3054

D
dapan1121 已提交
3055 3056 3057
    if (gCaseCtrl.caseRunNum > 0 && caseRunNum >= gCaseCtrl.caseRunNum) {
      break;
    }
D
dapan1121 已提交
3058

D
dapan1121 已提交
3059 3060 3061 3062
    if (gCaseCtrl.caseRunIdx >= 0 && caseRunIdx < gCaseCtrl.caseRunIdx) {
      caseRunIdx++;
      continue;
    }
D
dapan1121 已提交
3063

D
dapan1121 已提交
3064 3065
    if (runCase(taos, i, caseRunIdx, false)) {
      continue;
3066
    }
D
stmt  
dapan1121 已提交
3067

D
dapan1121 已提交
3068 3069
    caseRunIdx++;
    caseNum++;
D
dapan1121 已提交
3070
    caseRunNum++;
D
stmt  
dapan1121 已提交
3071
  }
3072

D
stmt  
dapan1121 已提交
3073 3074
  return NULL;
}
D
stmt  
dapan1121 已提交
3075

D
stmt  
dapan1121 已提交
3076
void runAll(TAOS *taos) {
D
dapan1121 已提交
3077 3078
  strcpy(gCaseCtrl.caseCatalog, "Normal Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
dapan1121 已提交
3079
  runCaseList(taos);
D
stmt  
dapan1121 已提交
3080

D
dapan1121 已提交
3081 3082
  strcpy(gCaseCtrl.caseCatalog, "Null Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
3083
  gCaseCtrl.bindNullNum = 1;
D
dapan1121 已提交
3084
  runCaseList(taos);
D
stmt  
dapan1121 已提交
3085
  gCaseCtrl.bindNullNum = 0;
D
stmt  
dapan1121 已提交
3086

D
dapan1121 已提交
3087 3088
  strcpy(gCaseCtrl.caseCatalog, "Bind Row Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
3089
  gCaseCtrl.bindRowNum = 1;
D
dapan1121 已提交
3090
  runCaseList(taos);
D
stmt  
dapan1121 已提交
3091
  gCaseCtrl.bindRowNum = 0;
D
stmt  
dapan1121 已提交
3092

D
dapan1121 已提交
3093 3094
  strcpy(gCaseCtrl.caseCatalog, "Row Num Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
3095
  gCaseCtrl.rowNum = 1000;
D
stmt  
dapan1121 已提交
3096
  gCaseCtrl.printRes = false;
D
dapan1121 已提交
3097
  runCaseList(taos);
D
stmt  
dapan1121 已提交
3098 3099
  gCaseCtrl.rowNum = 0;
  gCaseCtrl.printRes = true;
D
stmt  
dapan1121 已提交
3100

D
dapan1121 已提交
3101 3102
  strcpy(gCaseCtrl.caseCatalog, "Runtimes Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
3103
  gCaseCtrl.runTimes = 2;
D
dapan1121 已提交
3104
  runCaseList(taos);
D
stmt  
dapan1121 已提交
3105
  gCaseCtrl.runTimes = 0;
3106

D
dapan1121 已提交
3107 3108
  strcpy(gCaseCtrl.caseCatalog, "Check Param Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
3109
  gCaseCtrl.checkParamNum = true;
D
dapan1121 已提交
3110
  runCaseList(taos);
D
stmt  
dapan1121 已提交
3111
  gCaseCtrl.checkParamNum = false;
3112

D
dapan1121 已提交
3113 3114
  strcpy(gCaseCtrl.caseCatalog, "Bind Col Num Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
3115
  gCaseCtrl.bindColNum = 6;
D
dapan1121 已提交
3116
  runCaseList(taos);
D
stmt  
dapan1121 已提交
3117
  gCaseCtrl.bindColNum = 0;
3118

D
dapan1121 已提交
3119 3120
  strcpy(gCaseCtrl.caseCatalog, "Bind Col Type Test");
  printf("%s Begin\n", gCaseCtrl.caseCatalog);
D
stmt  
dapan1121 已提交
3121
  gCaseCtrl.bindColTypeNum = tListLen(bindColTypeList);
D
stmt  
dapan1121 已提交
3122
  gCaseCtrl.bindColTypeList = bindColTypeList;  
D
dapan1121 已提交
3123
  runCaseList(taos);
D
dapan1121 已提交
3124 3125
  
  printf("All Test End\n");  
3126 3127 3128 3129
}

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

D
stmt  
dapan1121 已提交
3132 3133
  srand(time(NULL));
  
3134 3135 3136 3137 3138 3139
  // connect to server
  if (argc < 2) {
    printf("please input server ip \n");
    return 0;
  }

D
stmt  
dapan1121 已提交
3140
  taos = taos_connect(argv[1], "root", "taosdata", NULL, 0);
3141 3142 3143 3144 3145
  if (taos == NULL) {
    printf("failed to connect to db, reason:%s\n", taos_errstr(taos));
    exit(1);
  }   

D
stmt  
dapan1121 已提交
3146
  runAll(taos);
3147 3148 3149 3150

  return 0;
}