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

revert [change json output format]

上级 0b54133a
......@@ -215,7 +215,7 @@ 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;
......@@ -223,16 +223,6 @@ static int32_t tscGetNthFieldResult(TAOS_ROW row, TAOS_FIELD* fields, int *lengt
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);
}
}
switch (type) {
case TSDB_DATA_TYPE_BOOL:
sprintf(result, "%s", ((((int32_t)(*((char *)val))) == 1) ? "true" : "false"));
......@@ -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:
......
......@@ -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('|');
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册