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

taosdata / TDengine / #3653

14 Mar 2025 08:10AM UTC coverage: 22.565% (-41.0%) from 63.596%
#3653

push

travis-ci

web-flow
feat(keep): support keep on super table level. (#30097)

* Feat: support use keep while create super table.

* Test(keep): add test for create super table with keep option.

* Feat(keep): Add tmsg for create keep.

* Feat(keep): support alter table option keep.

* Fix(keep): Add baisc test for alter table option.

* Fix(keep): memory leek.

* Feat(keep): add keep to metaEntry&metaCache and fix earliestTs with stn keep.

* Test(keep): add some cases for select with stb keep.

* Fix: fix ci core while alter stb.

* Feat(keep): delete expired data in super table level.

* Feat: remove get stb keep while query.

* Fix : build error.

* Revert "Fix : build error."

This reverts commit 0ed66e4e8.

* Revert "Feat(keep): delete expired data in super table level."

This reverts commit 36330f6b4.

* Fix : build errors.

* Feat : support restart taosd.

* Fix : alter table comment problems.

* Test : add tests for super table keep.

* Fix: change sdb stb reserve size.

* Test: add more tests.

* Feat: Disable normal tables and sub tables from setting the keep parameter

* Fix: add more checks to avoid unknown address.

* Docs: Add docs for stable keep.

* Fix: some review changes.

* Fix: review errors.

49248 of 302527 branches covered (16.28%)

Branch coverage included in aggregate %.

53 of 99 new or added lines in 12 files covered. (53.54%)

155872 existing lines in 443 files now uncovered.

87359 of 302857 relevant lines covered (28.84%)

570004.22 hits per line

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

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

16
#define ALLOW_FORBID_FUNC
17
#define _BSD_SOURCE
18
#define _GNU_SOURCE
19
#define _XOPEN_SOURCE
20
#define _DEFAULT_SOURCE
21
#include "geosWrapper.h"
22
#include "shellAuto.h"
23
#include "shellInt.h"
24

25
SShellObj shell = {0};
26

27
typedef struct {
28
  const char *sql;
29
  bool        vertical;
30
  tsem_t      sem;
31
  int64_t     numOfRows;  // the num of this batch
32
  int64_t     numOfAllRows;
33

34
  int32_t     numFields;
35
  TAOS_FIELD *fields;
36
  int32_t     precision;
37

38
  int32_t maxColNameLen;            // for vertical print
39
  int32_t width[TSDB_MAX_COLUMNS];  // for horizontal print
40

41
  uint64_t resShowMaxNum;
42
} tsDumpInfo;
43

44
static bool    shellIsEmptyCommand(const char *cmd);
45
static int32_t shellRunSingleCommand(char *command);
46
static void    shellRecordCommandToHistory(char *command);
47
static int32_t shellRunCommand(char *command, bool recordHistory);
48
static void    shellRunSingleCommandImp(char *command);
49
static char   *shellFormatTimestamp(char *buf, int32_t bufSize, int64_t val, int32_t precision);
50
static int64_t shellDumpResultToFile(const char *fname, TAOS_RES *tres);
51
static void    shellPrintNChar(const char *str, int32_t length, int32_t width);
52
static void    shellPrintGeometry(const unsigned char *str, int32_t length, int32_t width);
53
static void    shellVerticalPrintResult(TAOS_RES *tres, tsDumpInfo *dump_info);
54
static void    shellHorizontalPrintResult(TAOS_RES *tres, tsDumpInfo *dump_info);
55
static int64_t shellDumpResult(TAOS_RES *tres, char *fname, int32_t *error_no, bool vertical, const char *sql);
56
static void    shellReadHistory();
57
static void    shellWriteHistory();
58
static void    shellPrintError(TAOS_RES *tres, int64_t st);
59
static bool    shellIsCommentLine(char *line);
60
static void    shellSourceFile(const char *file);
61
static int32_t shellGetGrantInfo(char* buf);
62

63
static void  shellCleanup(void *arg);
64
static void *shellCancelHandler(void *arg);
65
static void *shellThreadLoop(void *arg);
66

67
static bool shellCmdkilled = false;
68

UNCOV
69
bool shellIsEmptyCommand(const char *cmd) {
×
UNCOV
70
  for (char c = *cmd++; c != 0; c = *cmd++) {
×
UNCOV
71
    if (c != ' ' && c != '\t' && c != ';') {
×
UNCOV
72
      return false;
×
73
    }
74
  }
UNCOV
75
  return true;
×
76
}
77

UNCOV
78
int32_t shellRunSingleCommand(char *command) {
×
UNCOV
79
  shellCmdkilled = false;
×
80

UNCOV
81
  if (shellIsEmptyCommand(command)) {
×
UNCOV
82
    return 0;
×
83
  }
84

UNCOV
85
  if (shellRegexMatch(command, "^[ \t]*(quit|q|exit)[ \t;]*$", REG_EXTENDED | REG_ICASE)) {
×
UNCOV
86
    return -1;
×
87
  }
88

UNCOV
89
  if (shellRegexMatch(command, "^[\t ]*clear[ \t;]*$", REG_EXTENDED | REG_ICASE)) {
×
90
#pragma GCC diagnostic push
91
#pragma GCC diagnostic ignored "-Wunused-result"
92
#ifndef TD_ASTRA
UNCOV
93
    system("clear");
×
94
#else
95
    printf("\033[2J\033[H");
96
#endif
97
#pragma GCC diagnostic pop
UNCOV
98
    return 0;
×
99
  }
100

UNCOV
101
  if (shellRegexMatch(command, "^[\t ]*set[ \t]+max_binary_display_width[ \t]+(default|[1-9][0-9]*)[ \t;]*$",
×
102
                      REG_EXTENDED | REG_ICASE)) {
103
    strtok(command, " \t");
×
UNCOV
104
    strtok(NULL, " \t");
×
UNCOV
105
    char *p = strtok(NULL, " \t");
×
UNCOV
106
    if (strncasecmp(p, "default", 7) == 0) {
×
UNCOV
107
      shell.args.displayWidth = SHELL_DEFAULT_MAX_BINARY_DISPLAY_WIDTH;
×
108
    } else {
UNCOV
109
      int32_t displayWidth = atoi(p);
×
UNCOV
110
      displayWidth = TRANGE(displayWidth, 1, 10 * 1024);
×
UNCOV
111
      shell.args.displayWidth = displayWidth;
×
112
    }
UNCOV
113
    return 0;
×
114
  }
115

116
  if (shellRegexMatch(command, "^[ \t]*source[\t ]+[^ ]+[ \t;]*$", REG_EXTENDED | REG_ICASE)) {
×
117
    /* If source file. */
UNCOV
118
    char *c_ptr = strtok(command, " ;");
×
UNCOV
119
    if (c_ptr == NULL) {
×
UNCOV
120
      shellRunSingleCommandImp(command);
×
121
      return 0;
×
122
    }
UNCOV
123
    c_ptr = strtok(NULL, " ;");
×
UNCOV
124
    if (c_ptr == NULL) {
×
UNCOV
125
      shellRunSingleCommandImp(command);
×
UNCOV
126
      return 0;
×
127
    }
UNCOV
128
    shellSourceFile(c_ptr);
×
UNCOV
129
    return 0;
×
130
  }
131
#ifdef WEBSOCKET
UNCOV
132
  if (shell.args.restful || shell.args.cloud) {
×
UNCOV
133
    shellRunSingleCommandWebsocketImp(command);
×
134
  } else {
135
#endif
UNCOV
136
    shellRunSingleCommandImp(command);
×
137
#ifdef WEBSOCKET
138
  }
139
#endif
UNCOV
140
  return 0;
×
141
}
142

143
void shellRecordCommandToHistory(char *command) {
×
UNCOV
144
  if (strncasecmp(command, "create user ", 12) == 0 || strncasecmp(command, "alter user ", 11) == 0) {
×
UNCOV
145
    if (taosStrCaseStr(command, " pass ")) {
×
146
      // have password command forbid record to history because security
UNCOV
147
      return;
×
148
    }
149
  }
150

UNCOV
151
  SShellHistory *pHistory = &shell.history;
×
UNCOV
152
  if (pHistory->hstart == pHistory->hend ||
×
UNCOV
153
      pHistory->hist[(pHistory->hend + SHELL_MAX_HISTORY_SIZE - 1) % SHELL_MAX_HISTORY_SIZE] == NULL ||
×
UNCOV
154
      strcmp(command, pHistory->hist[(pHistory->hend + SHELL_MAX_HISTORY_SIZE - 1) % SHELL_MAX_HISTORY_SIZE]) != 0) {
×
UNCOV
155
    if (pHistory->hist[pHistory->hend] != NULL) {
×
UNCOV
156
      taosMemoryFreeClear(pHistory->hist[pHistory->hend]);
×
157
    }
158
    pHistory->hist[pHistory->hend] = taosStrdup(command);
×
159

UNCOV
160
    pHistory->hend = (pHistory->hend + 1) % SHELL_MAX_HISTORY_SIZE;
×
UNCOV
161
    if (pHistory->hend == pHistory->hstart) {
×
UNCOV
162
      pHistory->hstart = (pHistory->hstart + 1) % SHELL_MAX_HISTORY_SIZE;
×
163
    }
164
  }
165
}
166

UNCOV
167
int32_t shellRunCommand(char *command, bool recordHistory) {
×
UNCOV
168
  if (shellIsEmptyCommand(command)) {
×
UNCOV
169
    return 0;
×
170
  }
171

172
  // add help or help;
UNCOV
173
  if (strncasecmp(command, "help", 4) == 0) {
×
UNCOV
174
    if (command[4] == ';' || command[4] == ' ' || command[4] == 0) {
×
UNCOV
175
      showHelp();
×
UNCOV
176
      return 0;
×
177
    }
178
  }
179

UNCOV
180
  if (recordHistory) shellRecordCommandToHistory(command);
×
181

UNCOV
182
  char quote = 0, *cmd = command;
×
UNCOV
183
  for (char c = *command++; c != 0; c = *command++) {
×
UNCOV
184
    if (c == '\\' && (*command == '\'' || *command == '"' || *command == '`')) {
×
UNCOV
185
      command++;
×
UNCOV
186
      continue;
×
187
    }
188

UNCOV
189
    if (quote == c) {
×
UNCOV
190
      quote = 0;
×
UNCOV
191
    } else if (quote == 0 && (c == '\'' || c == '"' || c == '`')) {
×
UNCOV
192
      quote = c;
×
UNCOV
193
    } else if (c == ';' && quote == 0) {
×
UNCOV
194
      c = *command;
×
UNCOV
195
      *command = 0;
×
UNCOV
196
      if (shellRunSingleCommand(cmd) < 0) {
×
UNCOV
197
        return -1;
×
198
      }
UNCOV
199
      *command = c;
×
UNCOV
200
      cmd = command;
×
201
    }
202
  }
UNCOV
203
  return shellRunSingleCommand(cmd);
×
204
}
205

UNCOV
206
char *strendG(const char *pstr) {
×
UNCOV
207
  if (pstr == NULL) {
×
UNCOV
208
    return NULL;
×
209
  }
210

UNCOV
211
  size_t len = strlen(pstr);
×
UNCOV
212
  if (len < 4) {
×
UNCOV
213
    return NULL;
×
214
  }
215

UNCOV
216
  char *p = (char *)pstr + len - 2;
×
UNCOV
217
  if (strcmp(p, "\\G") == 0) {
×
UNCOV
218
    return p;
×
219
  }
220

UNCOV
221
  p = (char *)pstr + len - 3;
×
UNCOV
222
  if (strcmp(p, "\\G;") == 0) {
×
UNCOV
223
    return p;
×
224
  }
225

UNCOV
226
  return NULL;
×
227
}
228

UNCOV
229
void shellRunSingleCommandImp(char *command) {
×
230
  int64_t st, et;
UNCOV
231
  char   *sptr = NULL;
×
UNCOV
232
  char   *cptr = NULL;
×
UNCOV
233
  char   *fname = NULL;
×
UNCOV
234
  bool    printMode = false;
×
235

UNCOV
236
  if ((sptr = strstr(command, ">>")) != NULL) {
×
UNCOV
237
    fname = sptr + 2;
×
UNCOV
238
    while (*fname == ' ') fname++;
×
UNCOV
239
    *sptr = '\0';
×
240

UNCOV
241
    cptr = strstr(fname, ";");
×
UNCOV
242
    if (cptr != NULL) {
×
UNCOV
243
      *cptr = '\0';
×
244
    }
245
  }
246

UNCOV
247
  if ((sptr = strendG(command)) != NULL) {
×
UNCOV
248
    *sptr = '\0';
×
UNCOV
249
    printMode = true;  // When output to a file, the switch does not work.
×
250
  }
251

UNCOV
252
  st = taosGetTimestampUs();
×
253

UNCOV
254
  TAOS_RES *pSql = taos_query(shell.conn, command);
×
UNCOV
255
  if (taos_errno(pSql)) {
×
UNCOV
256
    shellPrintError(pSql, st);
×
UNCOV
257
    return;
×
258
  }
259

UNCOV
260
  if (shellRegexMatch(command, "^\\s*use\\s+[a-zA-Z0-9_]+\\s*;\\s*$", REG_EXTENDED | REG_ICASE)) {
×
UNCOV
261
    printf("Database changed.\r\n\r\n");
×
262

263
    // call back auto tab module
UNCOV
264
    callbackAutoTab(command, pSql, true);
×
265

UNCOV
266
    taos_free_result(pSql);
×
267

UNCOV
268
    return;
×
269
  }
270

271
  // pre string
UNCOV
272
  char *pre = "Query OK";
×
UNCOV
273
  if (shellRegexMatch(command, "^\\s*delete\\s*from\\s*.*", REG_EXTENDED | REG_ICASE)) {
×
UNCOV
274
    pre = "Delete OK";
×
UNCOV
275
  } else if (shellRegexMatch(command, "^\\s*insert\\s*into\\s*.*", REG_EXTENDED | REG_ICASE)) {
×
UNCOV
276
    pre = "Insert OK";
×
UNCOV
277
  } else if (shellRegexMatch(command, "^\\s*create\\s*.*", REG_EXTENDED | REG_ICASE)) {
×
UNCOV
278
    pre = "Create OK";
×
UNCOV
279
  } else if (shellRegexMatch(command, "^\\s*drop\\s*.*", REG_EXTENDED | REG_ICASE)) {
×
UNCOV
280
    pre = "Drop OK";
×
281
  }
282

UNCOV
283
  TAOS_FIELD *pFields = taos_fetch_fields(pSql);
×
UNCOV
284
  if (pFields != NULL) {  // select and show kinds of commands
×
UNCOV
285
    int32_t error_no = 0;
×
286

UNCOV
287
    int64_t numOfRows = shellDumpResult(pSql, fname, &error_no, printMode, command);
×
UNCOV
288
    if (numOfRows < 0) return;
×
289

290
    et = taosGetTimestampUs();
×
291
    if (error_no == 0) {
×
292
      printf("Query OK, %" PRId64 " row(s) in set (%.6fs)\r\n", numOfRows, (et - st) / 1E6);
×
293
    } else {
UNCOV
294
      terrno = error_no;
×
UNCOV
295
      printf("Query interrupted (%s), %" PRId64 " row(s) in set (%.6fs)\r\n", taos_errstr(NULL), numOfRows,
×
UNCOV
296
             (et - st) / 1E6);
×
297
    }
UNCOV
298
    taos_free_result(pSql);
×
299
  } else {
UNCOV
300
    int64_t num_rows_affacted = taos_affected_rows64(pSql);
×
UNCOV
301
    taos_free_result(pSql);
×
UNCOV
302
    et = taosGetTimestampUs();
×
UNCOV
303
    printf("%s, %" PRId64 " row(s) affected (%.6fs)\r\n", pre, num_rows_affacted, (et - st) / 1E6);
×
304

305
    // call auto tab
UNCOV
306
    callbackAutoTab(command, NULL, false);
×
307
  }
308

UNCOV
309
  printf("\r\n");
×
310
}
311

UNCOV
312
char *shellFormatTimestamp(char *buf, int32_t bufSize, int64_t val, int32_t precision) {
×
UNCOV
313
  if (shell.args.is_raw_time) {
×
UNCOV
314
    sprintf(buf, "%" PRId64, val);
×
UNCOV
315
    return buf;
×
316
  }
317

318
  time_t  tt;
UNCOV
319
  int32_t ms = 0;
×
UNCOV
320
  if (precision == TSDB_TIME_PRECISION_NANO) {
×
UNCOV
321
    tt = (time_t)(val / 1000000000);
×
UNCOV
322
    ms = val % 1000000000;
×
UNCOV
323
  } else if (precision == TSDB_TIME_PRECISION_MICRO) {
×
UNCOV
324
    tt = (time_t)(val / 1000000);
×
UNCOV
325
    ms = val % 1000000;
×
326
  } else {
UNCOV
327
    tt = (time_t)(val / 1000);
×
UNCOV
328
    ms = val % 1000;
×
329
  }
330

UNCOV
331
  if (tt <= 0 && ms < 0) {
×
332
    tt--;
×
UNCOV
333
    if (precision == TSDB_TIME_PRECISION_NANO) {
×
UNCOV
334
      ms += 1000000000;
×
UNCOV
335
    } else if (precision == TSDB_TIME_PRECISION_MICRO) {
×
UNCOV
336
      ms += 1000000;
×
337
    } else {
UNCOV
338
      ms += 1000;
×
339
    }
340
  }
341

UNCOV
342
  struct tm ptm = {0};
×
UNCOV
343
  if (taosLocalTime(&tt, &ptm, buf, bufSize, NULL) == NULL) {
×
UNCOV
344
    return buf;
×
345
  }
UNCOV
346
  size_t pos = strftime(buf, 35, "%Y-%m-%d %H:%M:%S", &ptm);
×
347

UNCOV
348
  if (precision == TSDB_TIME_PRECISION_NANO) {
×
UNCOV
349
    sprintf(buf + pos, ".%09d", ms);
×
UNCOV
350
  } else if (precision == TSDB_TIME_PRECISION_MICRO) {
×
UNCOV
351
    sprintf(buf + pos, ".%06d", ms);
×
352
  } else {
UNCOV
353
    sprintf(buf + pos, ".%03d", ms);
×
354
  }
355

356
  return buf;
×
357
}
358

359
char *shellDumpHexValue(char *buf, const char *val, int32_t length) {
×
UNCOV
360
  for (int32_t i = 0; i < length; i++) {
×
361
    sprintf(buf + (i * 2), "%02X", val[i]);
×
362
  }
UNCOV
363
  buf[length * 2] = 0;
×
364

UNCOV
365
  return buf;
×
366
}
367

UNCOV
368
void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, int32_t length, int32_t precision) {
×
UNCOV
369
  if (val == NULL) {
×
UNCOV
370
    taosFprintfFile(pFile, "NULL");
×
UNCOV
371
    return;
×
372
  }
373

UNCOV
374
  char    quotationStr[2] = {'"', 0};
×
375
  int32_t width;
376

377
  int n = 0;
×
378
#define LENGTH 64
379
  char buf[LENGTH] = {0};
×
380
  switch (field->type) {
×
381
    case TSDB_DATA_TYPE_BOOL:
×
382
      taosFprintfFile(pFile, "%d", ((((int32_t)(*((char *)val))) == 1) ? 1 : 0));
×
383
      break;
×
384
    case TSDB_DATA_TYPE_TINYINT:
×
385
      taosFprintfFile(pFile, "%d", *((int8_t *)val));
×
386
      break;
×
387
    case TSDB_DATA_TYPE_UTINYINT:
×
388
      taosFprintfFile(pFile, "%u", *((uint8_t *)val));
×
389
      break;
×
390
    case TSDB_DATA_TYPE_SMALLINT:
×
391
      taosFprintfFile(pFile, "%d", *((int16_t *)val));
×
UNCOV
392
      break;
×
UNCOV
393
    case TSDB_DATA_TYPE_USMALLINT:
×
UNCOV
394
      taosFprintfFile(pFile, "%u", *((uint16_t *)val));
×
395
      break;
×
396
    case TSDB_DATA_TYPE_INT:
×
397
      taosFprintfFile(pFile, "%d", *((int32_t *)val));
×
UNCOV
398
      break;
×
UNCOV
399
    case TSDB_DATA_TYPE_UINT:
×
UNCOV
400
      taosFprintfFile(pFile, "%u", *((uint32_t *)val));
×
401
      break;
×
402
    case TSDB_DATA_TYPE_BIGINT:
×
403
      taosFprintfFile(pFile, "%" PRId64, *((int64_t *)val));
×
UNCOV
404
      break;
×
UNCOV
405
    case TSDB_DATA_TYPE_UBIGINT:
×
UNCOV
406
      taosFprintfFile(pFile, "%" PRIu64, *((uint64_t *)val));
×
407
      break;
×
UNCOV
408
    case TSDB_DATA_TYPE_FLOAT:
×
UNCOV
409
      width = SHELL_FLOAT_WIDTH;
×
UNCOV
410
      if (tsEnableScience) {
×
411
        taosFprintfFile(pFile, "%*.7e", width, GET_FLOAT_VAL(val));
×
412
      } else {
UNCOV
413
        n = tsnprintf(buf, LENGTH, "%*.7f", width, GET_FLOAT_VAL(val));
×
UNCOV
414
        if (n > SHELL_FLOAT_WIDTH) {
×
UNCOV
415
          taosFprintfFile(pFile, "%*.7e", width, GET_FLOAT_VAL(val));
×
416
        } else {
UNCOV
417
          taosFprintfFile(pFile, "%s", buf);
×
418
        }
419
      }
420
      break;
×
421
    case TSDB_DATA_TYPE_DOUBLE:
×
UNCOV
422
      width = SHELL_DOUBLE_WIDTH;
×
UNCOV
423
      if (tsEnableScience) {
×
UNCOV
424
        snprintf(buf, LENGTH, "%*.15e", width, GET_DOUBLE_VAL(val));
×
UNCOV
425
        taosFprintfFile(pFile, "%s", buf);
×
426
      } else {
UNCOV
427
        n = tsnprintf(buf, LENGTH, "%*.15f", width, GET_DOUBLE_VAL(val));
×
UNCOV
428
        if (n > SHELL_DOUBLE_WIDTH) {
×
UNCOV
429
          taosFprintfFile(pFile, "%*.15e", width, GET_DOUBLE_VAL(val));
×
430
        } else {
UNCOV
431
          taosFprintfFile(pFile, "%s", buf);
×
432
        }
433
      }
UNCOV
434
      break;
×
UNCOV
435
    case TSDB_DATA_TYPE_BINARY:
×
436
    case TSDB_DATA_TYPE_NCHAR:
437
    case TSDB_DATA_TYPE_JSON: {
UNCOV
438
      int32_t bufIndex = 0;
×
UNCOV
439
      char   *tmp = (char *)taosMemoryCalloc(length * 2 + 1, 1);
×
UNCOV
440
      if (tmp == NULL) break;
×
441
      for (int32_t i = 0; i < length; i++) {
×
442
        tmp[bufIndex] = val[i];
×
UNCOV
443
        bufIndex++;
×
UNCOV
444
        if (val[i] == '\"') {
×
UNCOV
445
          tmp[bufIndex] = val[i];
×
UNCOV
446
          bufIndex++;
×
447
        }
448
      }
UNCOV
449
      tmp[bufIndex] = 0;
×
450

451
      taosFprintfFile(pFile, "%s%s%s", quotationStr, tmp, quotationStr);
×
452
      taosMemoryFree(tmp);
×
453
    } break;
×
454
    case TSDB_DATA_TYPE_VARBINARY: {
×
UNCOV
455
      void    *tmp = NULL;
×
456
      uint32_t size = 0;
×
457
      if (taosAscii2Hex(val, length, &tmp, &size) < 0) {
×
458
        break;
×
459
      }
460
      taosFprintfFile(pFile, "%s%s%s", quotationStr, tmp, quotationStr);
×
461
      taosMemoryFree(tmp);
×
462
      break;
×
463
    }
464
    case TSDB_DATA_TYPE_GEOMETRY: {
×
465
      char *tmp = (char *)taosMemoryCalloc(length * 2 + 1, 1);
×
466
      if (tmp == NULL) break;
×
UNCOV
467
      shellDumpHexValue(tmp, val, length);
×
UNCOV
468
      taosFprintfFile(pFile, "%s", buf);
×
UNCOV
469
      taosMemoryFree(tmp);
×
UNCOV
470
      break;
×
471
    }
472
    case TSDB_DATA_TYPE_TIMESTAMP:
×
473
      shellFormatTimestamp(buf, sizeof(buf), *(int64_t *)val, precision);
×
UNCOV
474
      taosFprintfFile(pFile, "%s%s%s", quotationStr, buf, quotationStr);
×
UNCOV
475
      break;
×
UNCOV
476
    default:
×
UNCOV
477
      break;
×
478
  }
479
}
480

UNCOV
481
int64_t shellDumpResultToFile(const char *fname, TAOS_RES *tres) {
×
UNCOV
482
  char fullname[PATH_MAX] = {0};
×
UNCOV
483
  if (taosExpandDir(fname, fullname, PATH_MAX) != 0) {
×
UNCOV
484
    tstrncpy(fullname, fname, PATH_MAX);
×
485
  }
486

UNCOV
487
  TAOS_ROW row = taos_fetch_row(tres);
×
UNCOV
488
  if (row == NULL) {
×
UNCOV
489
    return 0;
×
490
  }
491

UNCOV
492
  TdFilePtr pFile = taosOpenFile(fullname, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM);
×
UNCOV
493
  if (pFile == NULL) {
×
UNCOV
494
    fprintf(stderr, "failed to open file: %s\r\n", fullname);
×
UNCOV
495
    return -1;
×
496
  }
497

UNCOV
498
  TAOS_FIELD *fields = taos_fetch_fields(tres);
×
UNCOV
499
  int32_t     num_fields = taos_num_fields(tres);
×
UNCOV
500
  int32_t     precision = taos_result_precision(tres);
×
501

UNCOV
502
  for (int32_t col = 0; col < num_fields; col++) {
×
UNCOV
503
    if (col > 0) {
×
UNCOV
504
      taosFprintfFile(pFile, ",");
×
505
    }
UNCOV
506
    taosFprintfFile(pFile, "%s", fields[col].name);
×
507
  }
UNCOV
508
  taosFprintfFile(pFile, "\r\n");
×
509

UNCOV
510
  int64_t numOfRows = 0;
×
511
  do {
UNCOV
512
    int32_t *length = taos_fetch_lengths(tres);
×
UNCOV
513
    for (int32_t i = 0; i < num_fields; i++) {
×
UNCOV
514
      if (i > 0) {
×
UNCOV
515
        taosFprintfFile(pFile, ",");
×
516
      }
UNCOV
517
      shellDumpFieldToFile(pFile, (const char *)row[i], fields + i, length[i], precision);
×
518
    }
UNCOV
519
    taosFprintfFile(pFile, "\r\n");
×
520

UNCOV
521
    numOfRows++;
×
UNCOV
522
    row = taos_fetch_row(tres);
×
UNCOV
523
  } while (row != NULL);
×
524

UNCOV
525
  taosCloseFile(&pFile);
×
526

UNCOV
527
  return numOfRows;
×
528
}
529

UNCOV
530
void shellPrintNChar(const char *str, int32_t length, int32_t width) {
×
531
  TdWchar tail[3];
UNCOV
532
  int32_t pos = 0, cols = 0, totalCols = 0, tailLen = 0;
×
533

UNCOV
534
  while (pos < length) {
×
535
    TdWchar wc;
UNCOV
536
    int32_t bytes = taosMbToWchar(&wc, str + pos, MB_CUR_MAX);
×
UNCOV
537
    if (bytes <= 0) {
×
538
      break;
×
539
    }
540

UNCOV
541
    if (pos + bytes > length) {
×
542
      break;
×
543
    }
UNCOV
544
    int w = 0;
×
UNCOV
545
    if (*(str + pos) == '\t' || *(str + pos) == '\n' || *(str + pos) == '\r') {
×
UNCOV
546
      w = bytes;
×
547
    } else {
UNCOV
548
      w = taosWcharWidth(wc);
×
549
    }
UNCOV
550
    pos += bytes;
×
551

UNCOV
552
    if (w <= 0) {
×
UNCOV
553
      continue;
×
554
    }
555

UNCOV
556
    if (width <= 0) {
×
UNCOV
557
      printf("%lc", wc);
×
UNCOV
558
      continue;
×
559
    }
560

UNCOV
561
    totalCols += w;
×
UNCOV
562
    if (totalCols > width) {
×
UNCOV
563
      break;
×
564
    }
UNCOV
565
    if (totalCols <= (width - 3)) {
×
UNCOV
566
      printf("%lc", wc);
×
UNCOV
567
      cols += w;
×
568
    } else {
UNCOV
569
      tail[tailLen] = wc;
×
UNCOV
570
      tailLen++;
×
571
    }
572
  }
573

574
  if (totalCols > width) {
×
575
    // width could be 1 or 2, so printf("...") cannot be used
UNCOV
576
    for (int32_t i = 0; i < 3; i++) {
×
UNCOV
577
      if (cols >= width) {
×
UNCOV
578
        break;
×
579
      }
UNCOV
580
      putchar('.');
×
UNCOV
581
      ++cols;
×
582
    }
583
  } else {
UNCOV
584
    for (int32_t i = 0; i < tailLen; i++) {
×
UNCOV
585
      printf("%lc", tail[i]);
×
586
    }
UNCOV
587
    cols = totalCols;
×
588
  }
589

UNCOV
590
  for (; cols < width; cols++) {
×
UNCOV
591
    putchar(' ');
×
592
  }
UNCOV
593
}
×
594

UNCOV
595
void shellPrintString(const char *str, int32_t width) {
×
UNCOV
596
  int32_t len = strlen(str);
×
597

598
  if (width == 0) {
×
UNCOV
599
    printf("%s", str);
×
UNCOV
600
  } else if (len > width) {
×
UNCOV
601
    if (width <= 3) {
×
UNCOV
602
      printf("%.*s.", width - 1, str);
×
603
    } else {
UNCOV
604
      printf("%.*s...", width - 3, str);
×
605
    }
606
  } else {
UNCOV
607
    printf("%s%*.s", str, width - len, "");
×
608
  }
609
}
×
610

UNCOV
611
void shellPrintGeometry(const unsigned char *val, int32_t length, int32_t width) {
×
UNCOV
612
  if (length == 0) {  // empty value
×
UNCOV
613
    shellPrintString("", width);
×
UNCOV
614
    return;
×
615
  }
616

617
  int32_t code = TSDB_CODE_FAILED;
×
618

UNCOV
619
  code = initCtxAsText();
×
UNCOV
620
  if (code != TSDB_CODE_SUCCESS) {
×
UNCOV
621
    shellPrintString(getGeosErrMsg(code), width);
×
UNCOV
622
    return;
×
623
  }
624

625
  char *outputWKT = NULL;
×
UNCOV
626
  code = doAsText(val, length, &outputWKT);
×
UNCOV
627
  if (code != TSDB_CODE_SUCCESS) {
×
UNCOV
628
    shellPrintString(getGeosErrMsg(code), width);  // should NOT happen
×
UNCOV
629
    return;
×
630
  }
631

UNCOV
632
  shellPrintString(outputWKT, width);
×
633

UNCOV
634
  geosFreeBuffer(outputWKT);
×
635
}
636

UNCOV
637
void shellPrintField(const char *val, TAOS_FIELD *field, int32_t width, int32_t length, int32_t precision) {
×
UNCOV
638
  if (val == NULL) {
×
UNCOV
639
    shellPrintString(TSDB_DATA_NULL_STR, width);
×
UNCOV
640
    return;
×
641
  }
642

UNCOV
643
  int n = 0;
×
644
#define LENGTH 64
UNCOV
645
  char buf[LENGTH] = {0};
×
UNCOV
646
  switch (field->type) {
×
UNCOV
647
    case TSDB_DATA_TYPE_BOOL:
×
UNCOV
648
      shellPrintString(((((int32_t)(*((char *)val))) == TSDB_FALSE) ? "false" : "true"), width);
×
UNCOV
649
      break;
×
UNCOV
650
    case TSDB_DATA_TYPE_TINYINT:
×
UNCOV
651
      printf("%*d", width, *((int8_t *)val));
×
UNCOV
652
      break;
×
UNCOV
653
    case TSDB_DATA_TYPE_UTINYINT:
×
UNCOV
654
      printf("%*u", width, *((uint8_t *)val));
×
UNCOV
655
      break;
×
UNCOV
656
    case TSDB_DATA_TYPE_SMALLINT:
×
UNCOV
657
      printf("%*d", width, *((int16_t *)val));
×
UNCOV
658
      break;
×
UNCOV
659
    case TSDB_DATA_TYPE_USMALLINT:
×
UNCOV
660
      printf("%*u", width, *((uint16_t *)val));
×
UNCOV
661
      break;
×
UNCOV
662
    case TSDB_DATA_TYPE_INT:
×
UNCOV
663
      printf("%*d", width, *((int32_t *)val));
×
UNCOV
664
      break;
×
UNCOV
665
    case TSDB_DATA_TYPE_UINT:
×
UNCOV
666
      printf("%*u", width, *((uint32_t *)val));
×
UNCOV
667
      break;
×
UNCOV
668
    case TSDB_DATA_TYPE_BIGINT:
×
UNCOV
669
      printf("%*" PRId64, width, taosGetInt64Aligned((int64_t *)val));
×
UNCOV
670
      break;
×
UNCOV
671
    case TSDB_DATA_TYPE_UBIGINT:
×
UNCOV
672
      printf("%*" PRIu64, width, taosGetUInt64Aligned((uint64_t *)val));
×
673
      break;
×
UNCOV
674
    case TSDB_DATA_TYPE_FLOAT:
×
UNCOV
675
      width = width >= LENGTH ? LENGTH - 1 : width;
×
UNCOV
676
      if (tsEnableScience) {
×
UNCOV
677
        printf("%*.7e", width, taosGetFloatAligned((float *)val));
×
678
      } else {
UNCOV
679
        snprintf(buf, LENGTH, "%*.*g", width, FLT_DIG, taosGetFloatAligned((float *)val));
×
UNCOV
680
        printf("%s", buf);
×
681
      }
682
      break;
×
683
    case TSDB_DATA_TYPE_DOUBLE:
×
UNCOV
684
      width = width >= LENGTH ? LENGTH - 1 : width;
×
UNCOV
685
      if (tsEnableScience) {
×
UNCOV
686
        snprintf(buf, LENGTH, "%*.15e", width, taosGetDoubleAligned((double *)val));
×
UNCOV
687
        printf("%s", buf);
×
688
      } else {
UNCOV
689
        snprintf(buf, LENGTH, "%*.*g", width, DBL_DIG, taosGetDoubleAligned((double *)val));
×
UNCOV
690
        printf("%*s", width, buf);
×
691
      }
UNCOV
692
      break;
×
693
    case TSDB_DATA_TYPE_VARBINARY: {
×
UNCOV
694
      void    *data = NULL;
×
UNCOV
695
      uint32_t size = 0;
×
UNCOV
696
      if (taosAscii2Hex(val, length, &data, &size) < 0) {
×
UNCOV
697
        break;
×
698
      }
UNCOV
699
      shellPrintNChar(data, size, width);
×
UNCOV
700
      taosMemoryFree(data);
×
UNCOV
701
      break;
×
702
    }
UNCOV
703
    case TSDB_DATA_TYPE_BINARY:
×
704
    case TSDB_DATA_TYPE_NCHAR:
705
    case TSDB_DATA_TYPE_JSON:
UNCOV
706
      shellPrintNChar(val, length, width);
×
UNCOV
707
      break;
×
UNCOV
708
    case TSDB_DATA_TYPE_GEOMETRY:
×
UNCOV
709
      shellPrintGeometry(val, length, width);
×
UNCOV
710
      break;
×
711
    case TSDB_DATA_TYPE_TIMESTAMP:
×
712
      shellFormatTimestamp(buf, sizeof(buf), taosGetInt64Aligned((int64_t *)val), precision);
×
UNCOV
713
      printf("%s", buf);
×
UNCOV
714
      break;
×
UNCOV
715
    default:
×
UNCOV
716
      break;
×
717
  }
718
}
719

720
// show whole result for this query return true, like limit or describe
UNCOV
721
bool shellIsShowWhole(const char *sql) {
×
722
  // limit
723
  if (taosStrCaseStr(sql, " limit ") != NULL) {
×
724
    return true;
×
725
  }
726
  // describe
727
  if (taosStrCaseStr(sql, "describe ") != NULL) {
×
728
    return true;
×
729
  }
730
  // desc
731
  if (taosStrCaseStr(sql, "desc ") != NULL) {
×
732
    return true;
×
733
  }
734
  // show
735
  if (taosStrCaseStr(sql, "show ") != NULL) {
×
736
    return true;
×
737
  }
738
  // explain
739
  if (taosStrCaseStr(sql, "explain ") != NULL) {
×
UNCOV
740
    return true;
×
741
  }
742

UNCOV
743
  return false;
×
744
}
745

UNCOV
746
bool shellIsShowQuery(const char *sql) {
×
747
  // todo refactor
748
  if (taosStrCaseStr(sql, "show ") != NULL) {
×
UNCOV
749
    return true;
×
750
  }
751

UNCOV
752
  return false;
×
753
}
754

UNCOV
755
void init_dump_info(tsDumpInfo *dump_info, TAOS_RES *tres, const char *sql, bool vertical) {
×
UNCOV
756
  dump_info->sql = sql;
×
UNCOV
757
  dump_info->vertical = vertical;
×
UNCOV
758
  tsem_init(&dump_info->sem, 0, 0);
×
UNCOV
759
  dump_info->numOfAllRows = 0;
×
760

UNCOV
761
  dump_info->numFields = taos_num_fields(tres);
×
UNCOV
762
  dump_info->fields = taos_fetch_fields(tres);
×
UNCOV
763
  dump_info->precision = taos_result_precision(tres);
×
764

UNCOV
765
  dump_info->resShowMaxNum = UINT64_MAX;
×
766

UNCOV
767
  if (shell.args.commands == NULL && shell.args.file[0] == 0 && !shellIsShowWhole(dump_info->sql)) {
×
UNCOV
768
    dump_info->resShowMaxNum = SHELL_DEFAULT_RES_SHOW_NUM;
×
769
  }
770

UNCOV
771
  if (vertical) {
×
UNCOV
772
    dump_info->maxColNameLen = 0;
×
UNCOV
773
    for (int32_t col = 0; col < dump_info->numFields; col++) {
×
UNCOV
774
      int32_t len = (int32_t)strlen(dump_info->fields[col].name);
×
UNCOV
775
      if (len > dump_info->maxColNameLen) {
×
UNCOV
776
        dump_info->maxColNameLen = len;
×
777
      }
778
    }
779
  } else {
UNCOV
780
    for (int32_t col = 0; col < dump_info->numFields; col++) {
×
UNCOV
781
      dump_info->width[col] = shellCalcColWidth(dump_info->fields + col, dump_info->precision);
×
782
    }
783
  }
UNCOV
784
}
×
785

786
void shellVerticalPrintResult(TAOS_RES *tres, tsDumpInfo *dump_info) {
×
UNCOV
787
  TAOS_ROW row = taos_fetch_row(tres);
×
UNCOV
788
  if (row == NULL) {
×
UNCOV
789
    printf("\033[31mtaos_fetch_row failed.\033[0m\n");
×
UNCOV
790
    return;
×
791
  }
792

UNCOV
793
  int64_t numOfPintRows = dump_info->numOfAllRows;
×
UNCOV
794
  int     numOfPrintRowsThisOne = 0;
×
795

UNCOV
796
  while (row != NULL) {
×
UNCOV
797
    printf("*************************** %" PRId64 ".row ***************************\r\n", numOfPintRows + 1);
×
798

UNCOV
799
    int32_t *length = taos_fetch_lengths(tres);
×
800

UNCOV
801
    for (int32_t i = 0; i < dump_info->numFields; i++) {
×
UNCOV
802
      TAOS_FIELD *field = dump_info->fields + i;
×
803

UNCOV
804
      int32_t padding = (int32_t)(dump_info->maxColNameLen - strlen(field->name));
×
UNCOV
805
      printf("%*.s%s: ", padding, " ", field->name);
×
806

UNCOV
807
      shellPrintField((const char *)row[i], field, 0, length[i], dump_info->precision);
×
UNCOV
808
      putchar('\r');
×
UNCOV
809
      putchar('\n');
×
810
    }
811

812
    numOfPintRows++;
×
813
    numOfPrintRowsThisOne++;
×
814

815
    if (numOfPintRows == dump_info->resShowMaxNum) {
×
816
      printf("\r\n");
×
817
      printf(" Notice: The result shows only the first %d rows.\r\n", SHELL_DEFAULT_RES_SHOW_NUM);
×
818
      printf("         You can use the `LIMIT` clause to get fewer result to show.\r\n");
×
819
      printf("           Or use '>>' to redirect the whole set of the result to a specified file.\r\n");
×
UNCOV
820
      printf("\r\n");
×
UNCOV
821
      printf("         You can use Ctrl+C to stop the underway fetching.\r\n");
×
UNCOV
822
      printf("\r\n");
×
UNCOV
823
      return;
×
824
    }
825

UNCOV
826
    if (numOfPrintRowsThisOne == dump_info->numOfRows) {
×
UNCOV
827
      return;
×
828
    }
829

UNCOV
830
    row = taos_fetch_row(tres);
×
831
  }
UNCOV
832
  return;
×
833
}
834

835
int32_t shellCalcColWidth(TAOS_FIELD *field, int32_t precision) {
×
836
  int32_t width = (int32_t)strlen(field->name);
×
837

UNCOV
838
  switch (field->type) {
×
UNCOV
839
    case TSDB_DATA_TYPE_NULL:
×
UNCOV
840
      return TMAX(4, width);  // null
×
UNCOV
841
    case TSDB_DATA_TYPE_BOOL:
×
UNCOV
842
      return TMAX(5, width);  // 'false'
×
843

UNCOV
844
    case TSDB_DATA_TYPE_TINYINT:
×
845
    case TSDB_DATA_TYPE_UTINYINT:
UNCOV
846
      return TMAX(4, width);  // '-127'
×
847

UNCOV
848
    case TSDB_DATA_TYPE_SMALLINT:
×
849
    case TSDB_DATA_TYPE_USMALLINT:
UNCOV
850
      return TMAX(6, width);  // '-32767'
×
851

UNCOV
852
    case TSDB_DATA_TYPE_INT:
×
853
    case TSDB_DATA_TYPE_UINT:
UNCOV
854
      return TMAX(11, width);  // '-2147483648'
×
855

UNCOV
856
    case TSDB_DATA_TYPE_BIGINT:
×
857
    case TSDB_DATA_TYPE_UBIGINT:
UNCOV
858
      return TMAX(21, width);  // '-9223372036854775807'
×
859

UNCOV
860
    case TSDB_DATA_TYPE_FLOAT:
×
UNCOV
861
      return TMAX(SHELL_FLOAT_WIDTH, width);
×
862

UNCOV
863
    case TSDB_DATA_TYPE_DOUBLE:
×
UNCOV
864
      return TMAX(SHELL_DOUBLE_WIDTH, width);
×
865

UNCOV
866
    case TSDB_DATA_TYPE_BINARY:
×
867
    case TSDB_DATA_TYPE_GEOMETRY:
UNCOV
868
      if (field->bytes > shell.args.displayWidth) {
×
UNCOV
869
        return TMAX(shell.args.displayWidth, width);
×
870
      } else {
UNCOV
871
        return TMAX(field->bytes + 2, width);
×
872
      }
UNCOV
873
    case TSDB_DATA_TYPE_VARBINARY: {
×
UNCOV
874
      int32_t bytes = field->bytes * 2 + 2;
×
UNCOV
875
      if (bytes > shell.args.displayWidth) {
×
UNCOV
876
        return TMAX(shell.args.displayWidth, width);
×
877
      } else {
UNCOV
878
        return TMAX(bytes + 2, width);
×
879
      }
880
    }
UNCOV
881
    case TSDB_DATA_TYPE_NCHAR:
×
882
    case TSDB_DATA_TYPE_JSON: {
883
      uint16_t bytes = field->bytes * TSDB_NCHAR_SIZE;
×
UNCOV
884
      if (bytes > shell.args.displayWidth) {
×
UNCOV
885
        return TMAX(shell.args.displayWidth, width);
×
886
      } else {
UNCOV
887
        return TMAX(bytes + 2, width);
×
888
      }
889
    }
890

UNCOV
891
    case TSDB_DATA_TYPE_TIMESTAMP:
×
UNCOV
892
      if (shell.args.is_raw_time) {
×
UNCOV
893
        return TMAX(14, width);
×
894
      }
UNCOV
895
      if (precision == TSDB_TIME_PRECISION_NANO) {
×
UNCOV
896
        return TMAX(29, width);
×
UNCOV
897
      } else if (precision == TSDB_TIME_PRECISION_MICRO) {
×
UNCOV
898
        return TMAX(26, width);  // '2020-01-01 00:00:00.000000'
×
899
      } else {
900
        return TMAX(23, width);  // '2020-01-01 00:00:00.000'
×
901
      }
902

903
    default:
×
UNCOV
904
      ASSERT(false);
×
905
  }
906

UNCOV
907
  return 0;
×
908
}
909

UNCOV
910
void shellPrintHeader(TAOS_FIELD *fields, int32_t *width, int32_t num_fields) {
×
UNCOV
911
  int32_t rowWidth = 0;
×
UNCOV
912
  for (int32_t col = 0; col < num_fields; col++) {
×
UNCOV
913
    TAOS_FIELD *field = fields + col;
×
UNCOV
914
    int32_t     padding = (int32_t)(width[col] - strlen(field->name));
×
UNCOV
915
    int32_t     left = padding / 2;
×
UNCOV
916
    printf(" %*.s%s%*.s |", left, " ", field->name, padding - left, " ");
×
UNCOV
917
    rowWidth += width[col] + 3;
×
918
  }
919

UNCOV
920
  putchar('\r');
×
UNCOV
921
  putchar('\n');
×
UNCOV
922
  for (int32_t i = 0; i < rowWidth; i++) {
×
UNCOV
923
    putchar('=');
×
924
  }
UNCOV
925
  putchar('\r');
×
UNCOV
926
  putchar('\n');
×
UNCOV
927
}
×
928

929
void shellHorizontalPrintResult(TAOS_RES *tres, tsDumpInfo *dump_info) {
×
UNCOV
930
  TAOS_ROW row = taos_fetch_row(tres);
×
UNCOV
931
  if (row == NULL) {
×
UNCOV
932
    printf("\033[31mtaos_fetch_row failed.\033[0m\n");
×
UNCOV
933
    return;
×
934
  }
935

UNCOV
936
  int64_t numOfPintRows = dump_info->numOfAllRows;
×
UNCOV
937
  int     numOfPrintRowsThisOne = 0;
×
UNCOV
938
  if (numOfPintRows == 0) {
×
UNCOV
939
    shellPrintHeader(dump_info->fields, dump_info->width, dump_info->numFields);
×
940
  }
941

UNCOV
942
  while (row != NULL) {
×
UNCOV
943
    int32_t *length = taos_fetch_lengths(tres);
×
UNCOV
944
    for (int32_t i = 0; i < dump_info->numFields; i++) {
×
UNCOV
945
      putchar(' ');
×
UNCOV
946
      shellPrintField((const char *)row[i], dump_info->fields + i, dump_info->width[i], length[i],
×
947
                      dump_info->precision);
UNCOV
948
      putchar(' ');
×
UNCOV
949
      putchar('|');
×
950
    }
UNCOV
951
    putchar('\r');
×
UNCOV
952
    putchar('\n');
×
953

954
    numOfPintRows++;
×
955
    numOfPrintRowsThisOne++;
×
956

957
    if (numOfPintRows == dump_info->resShowMaxNum) {
×
UNCOV
958
      printf("\r\n");
×
959
      printf(" Notice: The result shows only the first %d rows.\r\n", SHELL_DEFAULT_RES_SHOW_NUM);
×
960
      if (shellIsShowQuery(dump_info->sql)) {
×
UNCOV
961
        printf("         You can use '>>' to redirect the whole set of the result to a specified file.\r\n");
×
962
      } else {
963
        printf("         You can use the `LIMIT` clause to get fewer result to show.\r\n");
×
964
        printf("           Or use '>>' to redirect the whole set of the result to a specified file.\r\n");
×
965
      }
UNCOV
966
      printf("\r\n");
×
UNCOV
967
      printf("         You can use Ctrl+C to stop the underway fetching.\r\n");
×
UNCOV
968
      printf("\r\n");
×
UNCOV
969
      return;
×
970
    }
971

UNCOV
972
    if (numOfPrintRowsThisOne == dump_info->numOfRows) {
×
UNCOV
973
      return;
×
974
    }
975

UNCOV
976
    row = taos_fetch_row(tres);
×
977
  }
UNCOV
978
  return;
×
979
}
980

UNCOV
981
void shellDumpResultCallback(void *param, TAOS_RES *tres, int num_of_rows) {
×
UNCOV
982
  tsDumpInfo *dump_info = (tsDumpInfo *)param;
×
UNCOV
983
  if (num_of_rows > 0) {
×
UNCOV
984
    dump_info->numOfRows = num_of_rows;
×
UNCOV
985
    if (dump_info->numOfAllRows < dump_info->resShowMaxNum) {
×
UNCOV
986
      if (dump_info->vertical) {
×
UNCOV
987
        shellVerticalPrintResult(tres, dump_info);
×
988
      } else {
UNCOV
989
        shellHorizontalPrintResult(tres, dump_info);
×
990
      }
991
    }
992
    dump_info->numOfAllRows += num_of_rows;
×
UNCOV
993
    if (!shellCmdkilled) {
×
UNCOV
994
      taos_fetch_rows_a(tres, shellDumpResultCallback, param);
×
995
    } else {
996
      tsem_post(&dump_info->sem);
×
997
    }
998
  } else {
UNCOV
999
    if (num_of_rows < 0) {
×
UNCOV
1000
      printf("\033[31masync retrieve failed, code: %d\033, %s[0m\n", num_of_rows, tstrerror(num_of_rows));
×
1001
    }
UNCOV
1002
    tsem_post(&dump_info->sem);
×
1003
  }
UNCOV
1004
}
×
1005

UNCOV
1006
int64_t shellDumpResult(TAOS_RES *tres, char *fname, int32_t *error_no, bool vertical, const char *sql) {
×
UNCOV
1007
  int64_t num_of_rows = 0;
×
UNCOV
1008
  if (fname != NULL) {
×
UNCOV
1009
    num_of_rows = shellDumpResultToFile(fname, tres);
×
1010
  } else {
1011
    tsDumpInfo dump_info;
UNCOV
1012
    if (!shellCmdkilled) {
×
UNCOV
1013
      init_dump_info(&dump_info, tres, sql, vertical);
×
UNCOV
1014
      taos_fetch_rows_a(tres, shellDumpResultCallback, &dump_info);
×
UNCOV
1015
      tsem_wait(&dump_info.sem);
×
UNCOV
1016
      num_of_rows = dump_info.numOfAllRows;
×
1017
    }
1018
  }
1019

UNCOV
1020
  *error_no = shellCmdkilled ? TSDB_CODE_TSC_QUERY_KILLED : taos_errno(tres);
×
UNCOV
1021
  return num_of_rows;
×
1022
}
1023

UNCOV
1024
void shellReadHistory() {
×
UNCOV
1025
  SShellHistory *pHistory = &shell.history;
×
UNCOV
1026
  TdFilePtr      pFile = taosOpenFile(pHistory->file, TD_FILE_READ | TD_FILE_STREAM);
×
UNCOV
1027
  if (pFile == NULL) return;
×
1028

UNCOV
1029
  char   *line = taosMemoryMalloc(TSDB_MAX_ALLOWED_SQL_LEN + 1);
×
UNCOV
1030
  int32_t read_size = 0;
×
UNCOV
1031
  while ((read_size = taosGetsFile(pFile, TSDB_MAX_ALLOWED_SQL_LEN, line)) > 0) {
×
UNCOV
1032
    line[read_size - 1] = '\0';
×
UNCOV
1033
    taosMemoryFree(pHistory->hist[pHistory->hend]);
×
UNCOV
1034
    pHistory->hist[pHistory->hend] = taosStrdup(line);
×
1035

UNCOV
1036
    pHistory->hend = (pHistory->hend + 1) % SHELL_MAX_HISTORY_SIZE;
×
1037

UNCOV
1038
    if (pHistory->hend == pHistory->hstart) {
×
UNCOV
1039
      pHistory->hstart = (pHistory->hstart + 1) % SHELL_MAX_HISTORY_SIZE;
×
1040
    }
1041
  }
1042

1043
  taosMemoryFreeClear(line);
×
1044
  taosCloseFile(&pFile);
×
1045
  int64_t file_size;
1046
  if (taosStatFile(pHistory->file, &file_size, NULL, NULL) == 0 && file_size > SHELL_MAX_COMMAND_SIZE) {
×
1047
    TdFilePtr pFile = taosOpenFile(pHistory->file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_STREAM | TD_FILE_TRUNC);
×
UNCOV
1048
    if (pFile == NULL) return;
×
1049
    int32_t endIndex = pHistory->hstart;
×
1050
    if (endIndex != 0) {
×
1051
      endIndex = pHistory->hend;
×
1052
    }
1053
    for (int32_t i = (pHistory->hend + SHELL_MAX_HISTORY_SIZE - 1) % SHELL_MAX_HISTORY_SIZE; i != endIndex;) {
×
UNCOV
1054
      taosFprintfFile(pFile, "%s\n", pHistory->hist[i]);
×
UNCOV
1055
      i = (i + SHELL_MAX_HISTORY_SIZE - 1) % SHELL_MAX_HISTORY_SIZE;
×
1056
    }
1057
    taosFprintfFile(pFile, "%s\n", pHistory->hist[endIndex]);
×
1058

1059
    /* coverity[+retval] */
UNCOV
1060
    taosFsyncFile(pFile);
×
UNCOV
1061
    taosCloseFile(&pFile);
×
1062
  }
UNCOV
1063
  pHistory->hstart = pHistory->hend;
×
1064
}
1065

UNCOV
1066
void shellWriteHistory() {
×
UNCOV
1067
  SShellHistory *pHistory = &shell.history;
×
UNCOV
1068
  if (pHistory->hend == pHistory->hstart) return;
×
UNCOV
1069
  TdFilePtr pFile = taosOpenFile(pHistory->file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_STREAM | TD_FILE_APPEND);
×
UNCOV
1070
  if (pFile == NULL) return;
×
1071

UNCOV
1072
  for (int32_t i = pHistory->hstart; i != pHistory->hend;) {
×
UNCOV
1073
    if (pHistory->hist[i] != NULL) {
×
UNCOV
1074
      taosFprintfFile(pFile, "%s\n", pHistory->hist[i]);
×
UNCOV
1075
      taosMemoryFree(pHistory->hist[i]);
×
UNCOV
1076
      pHistory->hist[i] = NULL;
×
1077
    }
UNCOV
1078
    i = (i + 1) % SHELL_MAX_HISTORY_SIZE;
×
1079
  }
UNCOV
1080
  taosCloseFile(&pFile);
×
1081
}
1082

UNCOV
1083
void shellCleanupHistory() {
×
UNCOV
1084
  SShellHistory *pHistory = &shell.history;
×
UNCOV
1085
  for (int32_t i = 0; i < SHELL_MAX_HISTORY_SIZE; ++i) {
×
UNCOV
1086
    if (pHistory->hist[i] != NULL) {
×
UNCOV
1087
      taosMemoryFree(pHistory->hist[i]);
×
UNCOV
1088
      pHistory->hist[i] = NULL;
×
1089
    }
1090
  }
UNCOV
1091
}
×
1092

UNCOV
1093
void shellPrintError(TAOS_RES *tres, int64_t st) {
×
UNCOV
1094
  int64_t et = taosGetTimestampUs();
×
UNCOV
1095
  fprintf(stderr, "\r\nDB error: %s[0x%08X] (%.6fs)\r\n", taos_errstr(tres), taos_errno(tres), (et - st) / 1E6);
×
UNCOV
1096
  taos_free_result(tres);
×
UNCOV
1097
}
×
1098

UNCOV
1099
bool shellIsCommentLine(char *line) {
×
UNCOV
1100
  if (line == NULL) return true;
×
UNCOV
1101
  return shellRegexMatch(line, "^\\s*#.*", REG_EXTENDED);
×
1102
}
1103

UNCOV
1104
void shellSourceFile(const char *file) {
×
UNCOV
1105
  int32_t read_len = 0;
×
UNCOV
1106
  char   *cmd = taosMemoryCalloc(1, TSDB_MAX_ALLOWED_SQL_LEN + 1);
×
UNCOV
1107
  size_t  cmd_len = 0;
×
1108
  char    fullname[PATH_MAX] = {0};
×
UNCOV
1109
  char    sourceFileCommand[PATH_MAX + 8] = {0};
×
1110

UNCOV
1111
  if (taosExpandDir(file, fullname, PATH_MAX) != 0) {
×
UNCOV
1112
    tstrncpy(fullname, file, PATH_MAX);
×
1113
  }
1114

UNCOV
1115
  sprintf(sourceFileCommand, "source %s;", fullname);
×
UNCOV
1116
  shellRecordCommandToHistory(sourceFileCommand);
×
1117

UNCOV
1118
  TdFilePtr pFile = taosOpenFile(fullname, TD_FILE_READ | TD_FILE_STREAM);
×
UNCOV
1119
  if (pFile == NULL) {
×
UNCOV
1120
    fprintf(stderr, "failed to open file %s\r\n", fullname);
×
UNCOV
1121
    taosMemoryFree(cmd);
×
UNCOV
1122
    return;
×
1123
  }
1124

UNCOV
1125
  char *line = taosMemoryMalloc(TSDB_MAX_ALLOWED_SQL_LEN + 1);
×
1126
  while ((read_len = taosGetsFile(pFile, TSDB_MAX_ALLOWED_SQL_LEN, line)) > 0) {
×
1127
    if (cmd_len + read_len >= TSDB_MAX_ALLOWED_SQL_LEN) {
×
1128
      printf("read command line too long over 1M, ignore this line. cmd_len = %d read_len=%d \n", (int32_t)cmd_len,
×
1129
             read_len);
UNCOV
1130
      cmd_len = 0;
×
UNCOV
1131
      memset(line, 0, TSDB_MAX_ALLOWED_SQL_LEN + 1);
×
UNCOV
1132
      continue;
×
1133
    }
UNCOV
1134
    line[--read_len] = '\0';
×
1135

UNCOV
1136
    if (read_len == 0 || shellIsCommentLine(line)) {  // line starts with #
×
1137
      continue;
×
1138
    }
1139

1140
    if (line[read_len - 1] == '\\') {
×
UNCOV
1141
      line[read_len - 1] = ' ';
×
UNCOV
1142
      memcpy(cmd + cmd_len, line, read_len);
×
UNCOV
1143
      cmd_len += read_len;
×
1144
      continue;
×
1145
    }
1146

UNCOV
1147
    if (line[read_len - 1] == '\r') {
×
UNCOV
1148
      line[read_len - 1] = ' ';
×
1149
    }
1150

UNCOV
1151
    memcpy(cmd + cmd_len, line, read_len);
×
UNCOV
1152
    printf("%s%s\r\n", shell.info.promptHeader, cmd);
×
UNCOV
1153
    shellRunCommand(cmd, false);
×
UNCOV
1154
    memset(cmd, 0, TSDB_MAX_ALLOWED_SQL_LEN);
×
UNCOV
1155
    cmd_len = 0;
×
1156
  }
1157

UNCOV
1158
  taosMemoryFree(cmd);
×
UNCOV
1159
  taosMemoryFreeClear(line);
×
UNCOV
1160
  taosCloseFile(&pFile);
×
1161
}
1162

UNCOV
1163
int32_t shellGetGrantInfo(char *buf) {
×
UNCOV
1164
  int32_t verType = TSDB_VERSION_UNKNOWN;
×
UNCOV
1165
  char    sinfo[256] = {0};
×
UNCOV
1166
  tstrncpy(sinfo, taos_get_server_info(shell.conn), sizeof(sinfo));
×
UNCOV
1167
  strtok(sinfo, "\r\n");
×
1168

1169
#ifndef TD_ASTRA
UNCOV
1170
  char sql[] = "show grants";
×
1171

UNCOV
1172
  TAOS_RES *tres = taos_query(shell.conn, sql);
×
1173

UNCOV
1174
  int32_t code = taos_errno(tres);
×
1175
  if (code != TSDB_CODE_SUCCESS) {
×
1176
    if (code != TSDB_CODE_OPS_NOT_SUPPORT && code != TSDB_CODE_MND_NO_RIGHTS &&
×
1177
        code != TSDB_CODE_PAR_PERMISSION_DENIED) {
UNCOV
1178
      fprintf(stderr, "Failed to check Server Edition, Reason:0x%04x:%s\r\n\r\n", code, taos_errstr(tres));
×
1179
    }
UNCOV
1180
    taos_free_result(tres);
×
1181
    return verType;
×
1182
  }
1183

UNCOV
1184
  int32_t num_fields = taos_field_count(tres);
×
1185
  if (num_fields == 0) {
×
1186
    fprintf(stderr, "\r\nInvalid grant information.\r\n");
×
UNCOV
1187
    exit(0);
×
1188
  } else {
UNCOV
1189
    if (tres == NULL) {
×
UNCOV
1190
      fprintf(stderr, "\r\nGrant information is null.\r\n");
×
UNCOV
1191
      exit(0);
×
1192
    }
1193

UNCOV
1194
    TAOS_FIELD *fields = taos_fetch_fields(tres);
×
UNCOV
1195
    TAOS_ROW    row = taos_fetch_row(tres);
×
UNCOV
1196
    if (row == NULL) {
×
UNCOV
1197
      fprintf(stderr, "\r\nFailed to get grant information from server. Abort.\r\n");
×
UNCOV
1198
      exit(0);
×
1199
    }
UNCOV
1200
    char serverVersion[64] = {0};
×
UNCOV
1201
    char expiretime[32] = {0};
×
UNCOV
1202
    char expired[32] = {0};
×
1203

1204
    tstrncpy(serverVersion, row[0], 64);
×
UNCOV
1205
    memcpy(expiretime, row[1], fields[1].bytes);
×
1206
    memcpy(expired, row[2], fields[2].bytes);
×
1207

UNCOV
1208
    if (strcmp(serverVersion, "community") == 0) {
×
UNCOV
1209
      verType = TSDB_VERSION_OSS;
×
UNCOV
1210
    } else if (strcmp(expiretime, "unlimited") == 0) {
×
UNCOV
1211
      verType = TSDB_VERSION_ENTERPRISE;
×
UNCOV
1212
      sprintf(buf, "Server is %s, %s and will never expire.\r\n", serverVersion, sinfo);
×
1213
    } else {
UNCOV
1214
      verType = TSDB_VERSION_ENTERPRISE;
×
UNCOV
1215
      sprintf(buf, "Server is %s, %s and will expire at %s.\r\n", serverVersion, sinfo, expiretime);
×
1216
    }
1217

UNCOV
1218
    taos_free_result(tres);
×
1219
  }
1220

UNCOV
1221
  fprintf(stdout, "\r\n");
×
1222
#else
1223
  verType = TSDB_VERSION_ENTERPRISE;
1224
  sprintf(buf, "Server is %s, %s and will never expire.\r\n", TD_PRODUCT_NAME, sinfo);
1225
#endif
UNCOV
1226
  return verType;
×
1227
}
1228

1229
#ifdef WINDOWS
1230
BOOL shellQueryInterruptHandler(DWORD fdwCtrlType) {
1231
  tsem_post(&shell.cancelSem);
1232
  return TRUE;
1233
}
1234
#else
UNCOV
1235
void shellQueryInterruptHandler(int32_t signum, void *sigInfo, void *context) { tsem_post(&shell.cancelSem); }
×
1236
#endif
1237

UNCOV
1238
void shellCleanup(void *arg) { taosResetTerminalMode(); }
×
1239

1240
void *shellCancelHandler(void *arg) {
×
UNCOV
1241
  setThreadName("shellCancelHandler");
×
1242
  while (1) {
UNCOV
1243
    if (shell.exit == true) {
×
UNCOV
1244
      break;
×
1245
    }
1246

UNCOV
1247
    if (tsem_wait(&shell.cancelSem) != 0) {
×
UNCOV
1248
      taosMsleep(10);
×
UNCOV
1249
      continue;
×
1250
    }
1251

1252
#ifdef WEBSOCKET
UNCOV
1253
    if (shell.args.restful || shell.args.cloud) {
×
UNCOV
1254
      shell.stop_query = true;
×
1255
    } else {
1256
#endif
UNCOV
1257
      if (shell.conn) {
×
UNCOV
1258
        shellCmdkilled = true;
×
UNCOV
1259
        taos_kill_query(shell.conn);
×
1260
      }
1261
#ifdef WEBSOCKET
1262
    }
1263
#endif
1264
#ifdef WINDOWS
1265
    printf("\n%s", shell.info.promptHeader);
1266
#endif
1267
  }
1268

UNCOV
1269
  return NULL;
×
1270
}
1271

1272
#pragma GCC diagnostic push
1273
#pragma GCC diagnostic ignored "-Wstringop-overflow"
1274

1275
void *shellThreadLoop(void *arg) {
×
UNCOV
1276
  setThreadName("shellThreadLoop");
×
UNCOV
1277
  taosGetOldTerminalMode();
×
UNCOV
1278
  taosThreadCleanupPush(shellCleanup, NULL);
×
1279

1280
  do {
UNCOV
1281
    char *command = taosMemoryMalloc(SHELL_MAX_COMMAND_SIZE);
×
UNCOV
1282
    if (command == NULL) {
×
UNCOV
1283
      printf("failed to malloc command\r\n");
×
UNCOV
1284
      break;
×
1285
    }
1286

1287
    do {
UNCOV
1288
      memset(command, 0, SHELL_MAX_COMMAND_SIZE);
×
UNCOV
1289
      taosSetTerminalMode();
×
1290

UNCOV
1291
      if (shellReadCommand(command) != 0) {
×
UNCOV
1292
        break;
×
1293
      }
1294

UNCOV
1295
      taosResetTerminalMode();
×
UNCOV
1296
    } while (shellRunCommand(command, true) == 0);
×
1297

UNCOV
1298
    taosMemoryFreeClear(command);
×
UNCOV
1299
    shellWriteHistory();
×
UNCOV
1300
    shellExit();
×
1301
  } while (0);
1302

UNCOV
1303
  taosThreadCleanupPop(1);
×
UNCOV
1304
  return NULL;
×
1305
}
1306
#pragma GCC diagnostic pop
1307

UNCOV
1308
int32_t shellExecute(int argc, char *argv[]) {
×
UNCOV
1309
  int32_t code = 0;
×
UNCOV
1310
  printf(shell.info.clientVersion, shell.info.cusName, taos_get_client_info(), shell.info.cusName);
×
UNCOV
1311
  fflush(stdout);
×
1312

UNCOV
1313
  SShellArgs *pArgs = &shell.args;
×
1314
#ifdef WEBSOCKET
UNCOV
1315
  if (shell.args.restful || shell.args.cloud) {
×
UNCOV
1316
    if (shell_conn_ws_server(1)) {
×
UNCOV
1317
      printf("failed to connect to server, reason: %s[0x%08X]\n%s", ws_errstr(NULL), ws_errno(NULL), ERROR_CODE_DETAIL);
×
UNCOV
1318
      fflush(stdout);
×
UNCOV
1319
      return -1;
×
1320
    }
1321
  } else {
1322
#endif
UNCOV
1323
    if (shell.args.auth == NULL) {
×
UNCOV
1324
      shell.conn = taos_connect(pArgs->host, pArgs->user, pArgs->password, pArgs->database, pArgs->port);
×
1325
    } else {
UNCOV
1326
      shell.conn = taos_connect_auth(pArgs->host, pArgs->user, pArgs->auth, pArgs->database, pArgs->port);
×
1327
    }
1328

UNCOV
1329
    if (shell.conn == NULL) {
×
UNCOV
1330
      printf("failed to connect to server, reason: %s[0x%08X]\n%s", taos_errstr(NULL), taos_errno(NULL), ERROR_CODE_DETAIL);
×
UNCOV
1331
      fflush(stdout);
×
UNCOV
1332
      return -1;
×
1333
    }
1334
#ifdef WEBSOCKET
1335
  }
1336
#endif
1337

UNCOV
1338
  bool runOnce = pArgs->commands != NULL || pArgs->file[0] != 0;
×
UNCOV
1339
  shellSetConn(shell.conn, runOnce);
×
UNCOV
1340
  shellReadHistory();
×
1341

UNCOV
1342
  if (shell.args.is_bi_mode) {
×
1343
    // need set bi mode
UNCOV
1344
    printf("Set BI mode is true.\n");
×
1345
#ifndef WEBSOCKET
1346
    taos_set_conn_mode(shell.conn, TAOS_CONN_MODE_BI, 1);
1347
#endif
1348
  }
1349

UNCOV
1350
  if (runOnce) {
×
UNCOV
1351
    if (pArgs->commands != NULL) {
×
UNCOV
1352
      printf("%s%s\r\n", shell.info.promptHeader, pArgs->commands);
×
UNCOV
1353
      char *cmd = taosStrdup(pArgs->commands);
×
UNCOV
1354
      shellRunCommand(cmd, true);
×
UNCOV
1355
      taosMemoryFree(cmd);
×
1356
    }
1357

UNCOV
1358
    if (pArgs->file[0] != 0) {
×
UNCOV
1359
      shellSourceFile(pArgs->file);
×
1360
    }
1361
#ifdef WEBSOCKET
UNCOV
1362
    if (shell.args.restful || shell.args.cloud) {
×
UNCOV
1363
      ws_close(shell.ws_conn);
×
1364
    } else {
1365
#endif
UNCOV
1366
      taos_close(shell.conn);
×
1367
#ifdef WEBSOCKET
1368
    }
1369
#endif
1370

UNCOV
1371
    shellWriteHistory();
×
UNCOV
1372
    shellCleanupHistory();
×
UNCOV
1373
    return 0;
×
1374
  }
1375

UNCOV
1376
  if ((code = tsem_init(&shell.cancelSem, 0, 0)) != 0) {
×
UNCOV
1377
    printf("failed to create cancel semaphore since %s\r\n", tstrerror(code));
×
UNCOV
1378
    return code;
×
1379
  }
1380

UNCOV
1381
  TdThread spid = {0};
×
UNCOV
1382
  taosThreadCreate(&spid, NULL, shellCancelHandler, NULL);
×
1383

UNCOV
1384
  taosSetSignal(SIGTERM, shellQueryInterruptHandler);
×
UNCOV
1385
  taosSetSignal(SIGHUP, shellQueryInterruptHandler);
×
UNCOV
1386
  taosSetSignal(SIGINT, shellQueryInterruptHandler);
×
1387

1388
#ifdef WEBSOCKET
UNCOV
1389
  if (!shell.args.restful && !shell.args.cloud) {
×
1390
#endif
UNCOV
1391
    char    buf[512] = {0};
×
UNCOV
1392
    int32_t verType = shellGetGrantInfo(buf);
×
1393
#ifndef WINDOWS
UNCOV
1394
    printfIntroduction(verType);
×
1395
#else
1396
#ifndef WEBSOCKET
1397
  if (verType == TSDB_VERSION_OSS) {
1398
    showAD(false);
1399
  }
1400
#endif
1401
#endif
1402
    // printf version
UNCOV
1403
    if (verType == TSDB_VERSION_ENTERPRISE || verType == TSDB_VERSION_CLOUD) {
×
UNCOV
1404
      printf("%s\n", buf);
×
1405
    }
1406

1407
#ifdef WEBSOCKET
1408
  }
1409
#endif
1410
  while (1) {
UNCOV
1411
    taosThreadCreate(&shell.pid, NULL, shellThreadLoop, NULL);
×
UNCOV
1412
    taosThreadJoin(shell.pid, NULL);
×
UNCOV
1413
    taosThreadClear(&shell.pid);
×
UNCOV
1414
    if (shell.exit) {
×
UNCOV
1415
      tsem_post(&shell.cancelSem);
×
UNCOV
1416
      break;
×
1417
    }
1418
  }
1419
#ifndef WEBSOCKET
1420
  // commnuity
1421
  if (verType == TSDB_VERSION_OSS) {
1422
    showAD(true);
1423
  }
1424
#endif
1425

UNCOV
1426
  taosThreadJoin(spid, NULL);
×
1427

UNCOV
1428
  shellCleanupHistory();
×
UNCOV
1429
  taos_kill_query(shell.conn);
×
UNCOV
1430
  taos_close(shell.conn);
×
1431

UNCOV
1432
  TAOS_RETURN(code);
×
1433
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc