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
This commit is contained in:
parent
5c7b82372f
commit
d418e888c3
|
@ -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:
|
||||||
|
if (taos_is_null(res, c, f)) {
|
||||||
|
printf("col%d, row: %"PRId64" "
|
||||||
|
"value: NULL\n", f, c);
|
||||||
|
} else {
|
||||||
|
printf("col%d, row: %"PRId64", "
|
||||||
|
"value: %"PRId64"\n",
|
||||||
|
f, c,
|
||||||
|
*(int64_t*)(row[f]+c*sizeof(int64_t)));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
int *offsets = taos_get_column_data_offset(res, f);
|
case TSDB_DATA_TYPE_INT:
|
||||||
if (offsets) {
|
if (taos_is_null(res, c, f)) {
|
||||||
for (int c = 0; c < rows; c++) {
|
printf("col%d, row: %"PRId64" "
|
||||||
if (offsets[c] != -1) {
|
"value: NULL\n", f, c);
|
||||||
int length = *(int16_t*)(row[f] + offsets[c]);
|
} else {
|
||||||
char *buf = calloc(1, length + 1);
|
printf("col%d, row: %"PRId64", "
|
||||||
strncpy(buf, (char *)(row[f] + offsets[c] + 2), length);
|
"value: %d\n",
|
||||||
printf("row: %d, col: %d, offset: %d, length: %d, content: %s\n",
|
f, c,
|
||||||
c, f, offsets[c], length, buf);
|
*(int32_t*)(row[f]+c*sizeof(int32_t)));
|
||||||
free(buf);
|
}
|
||||||
} else {
|
break;
|
||||||
printf("row: %d, col: %d, offset: -1, means content is NULL\n",
|
|
||||||
c, f);
|
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;
|
||||||
|
|
Loading…
Reference in New Issue