未验证 提交 d418e888 编写于 作者: sangshuduo's avatar sangshuduo 提交者: GitHub

enh: add int, float, timestamp value convert in demoapi.c (#11558)

* [TD-13558]<feature>: taos shell refactor

add taosTools as submodule

* add tools/taos-tools

* add more client interface for taosTools compile

* update taos-tools

* update taos-tools

* refactor shell

* [TD-13558]<feature>: taos shell test speed

* [TD-13558]<feature>: taos -n startup works

* taos -n rpc works

* taos -n server works

* cleanup code since no endPort in 3.0

* update taos-tools

* [TD-13558]<feature>: taos -C works

* improve taos shell -c WIP

* update taos-tools

* add demoapi.c

* adjust show databases result for 3.0

* test: add platform logic

* add nchar

* adjust taos_fetch_lengths

* print fields

* remove show databases check from insert cases

* fix lua example compile for 3.0

still not work

* remove lua.py from smoketest

* use get_column_data_offset() to get offset and convert length

* add int, float, timestamp value convert
上级 5c7b8237
...@@ -179,33 +179,77 @@ static int print_result(char *tbname, TAOS_RES* res, int block) { ...@@ -179,33 +179,77 @@ static int print_result(char *tbname, TAOS_RES* res, int block) {
warnPrint("%s", "call taos_fetch_block()\n"); warnPrint("%s", "call taos_fetch_block()\n");
int rows = 0; int rows = 0;
while ((rows = taos_fetch_block(res, &row))) { while ((rows = taos_fetch_block(res, &row))) {
int *lengths = taos_fetch_lengths(res);
for (int f = 0; f < num_fields; f++) { for (int f = 0; f < num_fields; f++) {
if ((fields[f].type != TSDB_DATA_TYPE_VARCHAR) if ((fields[f].type != TSDB_DATA_TYPE_VARCHAR)
&& (fields[f].type != TSDB_DATA_TYPE_NCHAR) && (fields[f].type != TSDB_DATA_TYPE_NCHAR)
&& (fields[f].type != TSDB_DATA_TYPE_JSON)) { && (fields[f].type != TSDB_DATA_TYPE_JSON)) {
printf("col%d type is %d, no need get offset\n", printf("col%d type is %d, no need get offset\n",
f, fields[f].type); f, fields[f].type);
continue; for (int64_t c = 0; c < rows; c++) {
} switch(fields[f].type) {
case TSDB_DATA_TYPE_TIMESTAMP:
int *offsets = taos_get_column_data_offset(res, f); if (taos_is_null(res, c, f)) {
if (offsets) { printf("col%d, row: %"PRId64" "
for (int c = 0; c < rows; c++) { "value: NULL\n", f, c);
if (offsets[c] != -1) { } else {
int length = *(int16_t*)(row[f] + offsets[c]); printf("col%d, row: %"PRId64", "
char *buf = calloc(1, length + 1); "value: %"PRId64"\n",
strncpy(buf, (char *)(row[f] + offsets[c] + 2), length); f, c,
printf("row: %d, col: %d, offset: %d, length: %d, content: %s\n", *(int64_t*)(row[f]+c*sizeof(int64_t)));
c, f, offsets[c], length, buf); }
free(buf); break;
} else {
printf("row: %d, col: %d, offset: -1, means content is NULL\n", case TSDB_DATA_TYPE_INT:
c, f); if (taos_is_null(res, c, f)) {
printf("col%d, row: %"PRId64" "
"value: NULL\n", f, c);
} else {
printf("col%d, row: %"PRId64", "
"value: %d\n",
f, c,
*(int32_t*)(row[f]+c*sizeof(int32_t)));
}
break;
case TSDB_DATA_TYPE_FLOAT:
if (taos_is_null(res, c, f)) {
printf("col%d, row: %"PRId64" "
"value: NULL\n", f, c);
} else {
printf("col%d, row: %"PRId64", "
"value: %f\n",
f, c,
*(float*)(row[f]+c*sizeof(float)));
}
break;
default:
printf("type: %d is not processed\n",
fields[f].type);
break;
} }
} }
} else { } else {
errorPrint("%s() LN%d: col%d's lengths is NULL\n", int *offsets = taos_get_column_data_offset(res, f);
__func__, __LINE__, f); if (offsets) {
for (int c = 0; c < rows; c++) {
if (offsets[c] != -1) {
int length = *(int16_t*)(row[f] + offsets[c]);
char *buf = calloc(1, length + 1);
strncpy(buf, (char *)(row[f] + offsets[c] + 2), length);
printf("row: %d, col: %d, offset: %d, length: %d, content: %s\n",
c, f, offsets[c], length, buf);
free(buf);
} else {
printf("row: %d, col: %d, offset: -1, means content is NULL\n",
c, f);
}
}
} else {
errorPrint("%s() LN%d: col%d's offsets is NULL\n",
__func__, __LINE__, f);
}
} }
} }
num_rows += rows; num_rows += rows;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册