提交 2e6f68ab 编写于 作者: wmmhello's avatar wmmhello

revert [change json output format]

上级 0b54133a
...@@ -215,23 +215,13 @@ static int32_t tscProcessDescribeTable(SSqlObj *pSql) { ...@@ -215,23 +215,13 @@ static int32_t tscProcessDescribeTable(SSqlObj *pSql) {
return tscSetValueToResObj(pSql, rowLen); return tscSetValueToResObj(pSql, rowLen);
} }
static int32_t tscGetNthFieldResult(TAOS_ROW row, TAOS_FIELD* fields, int *lengths, int idx, char *result) { 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) { if (val == NULL) {
sprintf(result, "%s", TSDB_DATA_NULL_STR); sprintf(result, "%s", TSDB_DATA_NULL_STR);
return -1; return -1;
} }
uint8_t type = fields[idx].type; uint8_t type = fields[idx].type;
int32_t length = lengths[idx]; 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);
}
}
switch (type) { switch (type) {
case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_BOOL:
...@@ -257,6 +247,7 @@ static int32_t tscGetNthFieldResult(TAOS_ROW row, TAOS_FIELD* fields, int *lengt ...@@ -257,6 +247,7 @@ static int32_t tscGetNthFieldResult(TAOS_ROW row, TAOS_FIELD* fields, int *lengt
break; break;
case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_NCHAR:
case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_JSON:
memcpy(result, val, length); memcpy(result, val, length);
break; break;
case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_TIMESTAMP:
......
...@@ -470,23 +470,12 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) { ...@@ -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) { if (val == NULL) {
fprintf(fp, "%s", TSDB_DATA_NULL_STR); fprintf(fp, "%s", TSDB_DATA_NULL_STR);
return; 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]; char buf[TSDB_MAX_BYTES_PER_ROW];
switch (field->type) { switch (field->type) {
case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_BOOL:
...@@ -567,7 +556,7 @@ static int dumpResultToFile(const char* fname, TAOS_RES* tres) { ...@@ -567,7 +556,7 @@ static int dumpResultToFile(const char* fname, TAOS_RES* tres) {
if (i > 0) { if (i > 0) {
fputc(',', fp); 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); fputc('\n', fp);
...@@ -646,7 +635,7 @@ static void shellPrintNChar(const char *str, int length, int width) { ...@@ -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) { if (val == NULL) {
int w = width; int w = width;
if (field->type < TSDB_DATA_TYPE_TINYINT || field->type > TSDB_DATA_TYPE_DOUBLE) { 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, ...@@ -659,19 +648,8 @@ static void printField(char* val, TAOS_FIELD* field, int width, int32_t length,
return; 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]; char buf[TSDB_MAX_BYTES_PER_ROW];
switch (type) { switch (field->type) {
case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_BOOL:
printf("%*s", width, ((((int32_t)(*((char *)val))) == 1) ? "true" : "false")); printf("%*s", width, ((((int32_t)(*((char *)val))) == 1) ? "true" : "false"));
break; break;
...@@ -707,6 +685,7 @@ static void printField(char* val, TAOS_FIELD* field, int width, int32_t length, ...@@ -707,6 +685,7 @@ static void printField(char* val, TAOS_FIELD* field, int width, int32_t length,
break; break;
case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_NCHAR:
case TSDB_DATA_TYPE_JSON:
shellPrintNChar(val, length, width); shellPrintNChar(val, length, width);
break; break;
case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_TIMESTAMP:
...@@ -768,7 +747,7 @@ static int verticalPrintResult(TAOS_RES* tres) { ...@@ -768,7 +747,7 @@ static int verticalPrintResult(TAOS_RES* tres) {
int padding = (int)(maxColNameLen - strlen(field->name)); int padding = (int)(maxColNameLen - strlen(field->name));
printf("%*.s%s: ", padding, " ", 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'); putchar('\n');
} }
} else if (showMore) { } else if (showMore) {
...@@ -898,7 +877,7 @@ static int horizontalPrintResult(TAOS_RES* tres) { ...@@ -898,7 +877,7 @@ static int horizontalPrintResult(TAOS_RES* tres) {
if (numOfRows < resShowMaxNum) { if (numOfRows < resShowMaxNum) {
for (int i = 0; i < num_fields; i++) { for (int i = 0; i < num_fields; i++) {
putchar(' '); 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(' ');
putchar('|'); putchar('|');
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册