From 2e6f68ab52f8a51cf331b6eb18a4a5c1d552aa0c Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Tue, 23 Nov 2021 18:00:32 +0800 Subject: [PATCH] revert [change json output format] --- src/client/src/tscLocal.c | 15 +++----------- src/kit/shell/src/shellEngine.c | 35 +++++++-------------------------- 2 files changed, 10 insertions(+), 40 deletions(-) diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index 41151803e1..25e1513b47 100644 --- a/src/client/src/tscLocal.c +++ b/src/client/src/tscLocal.c @@ -215,23 +215,13 @@ static int32_t tscProcessDescribeTable(SSqlObj *pSql) { return tscSetValueToResObj(pSql, rowLen); } static int32_t tscGetNthFieldResult(TAOS_ROW row, TAOS_FIELD* fields, int *lengths, int idx, char *result) { - char *val = (char*)row[idx]; + const char *val = (const char*)row[idx]; if (val == NULL) { sprintf(result, "%s", TSDB_DATA_NULL_STR); return -1; } uint8_t type = fields[idx].type; - int32_t length = lengths[idx]; - - if (type == TSDB_DATA_TYPE_JSON){ - char* p = val; - type = *p; - val += CHAR_BYTES; - if(type == TSDB_DATA_TYPE_NCHAR) { - length = varDataLen(val); - val = varDataVal(val); - } - } + int32_t length = lengths[idx]; switch (type) { case TSDB_DATA_TYPE_BOOL: @@ -257,6 +247,7 @@ static int32_t tscGetNthFieldResult(TAOS_ROW row, TAOS_FIELD* fields, int *lengt break; case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_BINARY: + case TSDB_DATA_TYPE_JSON: memcpy(result, val, length); break; case TSDB_DATA_TYPE_TIMESTAMP: diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index 1283183441..a6cc5a76cb 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -470,23 +470,12 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) { } -static void dumpFieldToFile(FILE* fp, char* val, TAOS_FIELD* field, int32_t length, int precision) { +static void dumpFieldToFile(FILE* fp, const char* val, TAOS_FIELD* field, int32_t length, int precision) { if (val == NULL) { fprintf(fp, "%s", TSDB_DATA_NULL_STR); return; } - uint8_t type = field->type; - if (type == TSDB_DATA_TYPE_JSON){ - char* p = val; - type = *p; - val += CHAR_BYTES; - if(type == TSDB_DATA_TYPE_NCHAR) { - length = varDataLen(val); - val = varDataVal(val); - } - } - char buf[TSDB_MAX_BYTES_PER_ROW]; switch (field->type) { case TSDB_DATA_TYPE_BOOL: @@ -567,7 +556,7 @@ static int dumpResultToFile(const char* fname, TAOS_RES* tres) { if (i > 0) { fputc(',', fp); } - dumpFieldToFile(fp, row[i], fields +i, length[i], precision); + dumpFieldToFile(fp, (const char*)row[i], fields +i, length[i], precision); } fputc('\n', fp); @@ -646,7 +635,7 @@ static void shellPrintNChar(const char *str, int length, int width) { } -static void printField(char* val, TAOS_FIELD* field, int width, int32_t length, int precision) { +static void printField(const char* val, TAOS_FIELD* field, int width, int32_t length, int precision) { if (val == NULL) { int w = width; if (field->type < TSDB_DATA_TYPE_TINYINT || field->type > TSDB_DATA_TYPE_DOUBLE) { @@ -659,19 +648,8 @@ static void printField(char* val, TAOS_FIELD* field, int width, int32_t length, return; } - uint8_t type = field->type; - if (type == TSDB_DATA_TYPE_JSON){ - char* p = val; - type = *p; - val += CHAR_BYTES; - if(type == TSDB_DATA_TYPE_NCHAR) { - length = varDataLen(val); - val = varDataVal(val); - } - } - char buf[TSDB_MAX_BYTES_PER_ROW]; - switch (type) { + switch (field->type) { case TSDB_DATA_TYPE_BOOL: printf("%*s", width, ((((int32_t)(*((char *)val))) == 1) ? "true" : "false")); break; @@ -707,6 +685,7 @@ static void printField(char* val, TAOS_FIELD* field, int width, int32_t length, break; case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_NCHAR: + case TSDB_DATA_TYPE_JSON: shellPrintNChar(val, length, width); break; case TSDB_DATA_TYPE_TIMESTAMP: @@ -768,7 +747,7 @@ static int verticalPrintResult(TAOS_RES* tres) { int padding = (int)(maxColNameLen - strlen(field->name)); printf("%*.s%s: ", padding, " ", field->name); - printField(row[i], field, 0, length[i], precision); + printField((const char*)row[i], field, 0, length[i], precision); putchar('\n'); } } else if (showMore) { @@ -898,7 +877,7 @@ static int horizontalPrintResult(TAOS_RES* tres) { if (numOfRows < resShowMaxNum) { for (int i = 0; i < num_fields; i++) { putchar(' '); - printField(row[i], fields + i, width[i], length[i], precision); + printField((const char*)row[i], fields + i, width[i], length[i], precision); putchar(' '); putchar('|'); } -- GitLab