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

[TD-4322]<fix>: taosdemo query then fetch result. (#6211)

* [TD-4322]<fix>: taosdemo query then fetch result.

* build again.
Co-authored-by: NShuduo Sang <sdsang@taosdata.com>
上级 8e6a5acb
...@@ -1148,7 +1148,6 @@ static int queryDbExec(TAOS *taos, char *command, QUERY_TYPE type, bool quiet) { ...@@ -1148,7 +1148,6 @@ static int queryDbExec(TAOS *taos, char *command, QUERY_TYPE type, bool quiet) {
static void appendResultBufToFile(char *resultBuf, char *resultFile) static void appendResultBufToFile(char *resultBuf, char *resultFile)
{ {
FILE *fp = NULL; FILE *fp = NULL;
if (resultFile[0] != 0) {
fp = fopen(resultFile, "at"); fp = fopen(resultFile, "at");
if (fp == NULL) { if (fp == NULL) {
errorPrint( errorPrint(
...@@ -1156,12 +1155,12 @@ static void appendResultBufToFile(char *resultBuf, char *resultFile) ...@@ -1156,12 +1155,12 @@ static void appendResultBufToFile(char *resultBuf, char *resultFile)
__func__, __LINE__, resultFile); __func__, __LINE__, resultFile);
return; return;
} }
fprintf(fp, "%s", resultBuf); fprintf(fp, "%s", resultBuf);
tmfclose(fp); tmfclose(fp);
}
} }
static void appendResultToFile(TAOS_RES *res, char* resultFile) { static void fetchResult(TAOS_RES *res, char* resultFile) {
TAOS_ROW row = NULL; TAOS_ROW row = NULL;
int num_rows = 0; int num_rows = 0;
int num_fields = taos_field_count(res); int num_fields = taos_field_count(res);
...@@ -1179,7 +1178,8 @@ static void appendResultToFile(TAOS_RES *res, char* resultFile) { ...@@ -1179,7 +1178,8 @@ static void appendResultToFile(TAOS_RES *res, char* resultFile) {
// fetch the records row by row // fetch the records row by row
while((row = taos_fetch_row(res))) { while((row = taos_fetch_row(res))) {
if (totalLen >= 100*1024*1024 - 32000) { if ((resultFile)
&& (totalLen >= 100*1024*1024 - 32000)) {
appendResultBufToFile(databuf, resultFile); appendResultBufToFile(databuf, resultFile);
totalLen = 0; totalLen = 0;
memset(databuf, 0, 100*1024*1024); memset(databuf, 0, 100*1024*1024);
...@@ -1194,7 +1194,9 @@ static void appendResultToFile(TAOS_RES *res, char* resultFile) { ...@@ -1194,7 +1194,9 @@ static void appendResultToFile(TAOS_RES *res, char* resultFile) {
verbosePrint("%s() LN%d, databuf=%s resultFile=%s\n", verbosePrint("%s() LN%d, databuf=%s resultFile=%s\n",
__func__, __LINE__, databuf, resultFile); __func__, __LINE__, databuf, resultFile);
if (resultFile) {
appendResultBufToFile(databuf, resultFile); appendResultBufToFile(databuf, resultFile);
}
free(databuf); free(databuf);
} }
...@@ -1210,9 +1212,7 @@ static void selectAndGetResult( ...@@ -1210,9 +1212,7 @@ static void selectAndGetResult(
return; return;
} }
if ((strlen(pThreadInfo->fp))) { fetchResult(res, pThreadInfo->fp);
appendResultToFile(res, pThreadInfo->fp);
}
taos_free_result(res); taos_free_result(res);
} else if (0 == strncasecmp(g_queryInfo.queryMode, "rest", strlen("rest"))) { } else if (0 == strncasecmp(g_queryInfo.queryMode, "rest", strlen("rest"))) {
...@@ -2053,13 +2053,13 @@ static void printfQuerySystemInfo(TAOS * taos) { ...@@ -2053,13 +2053,13 @@ static void printfQuerySystemInfo(TAOS * taos) {
// show variables // show variables
res = taos_query(taos, "show variables;"); res = taos_query(taos, "show variables;");
//appendResultToFile(res, filename); //fetchResult(res, filename);
xDumpResultToFile(filename, res); xDumpResultToFile(filename, res);
// show dnodes // show dnodes
res = taos_query(taos, "show dnodes;"); res = taos_query(taos, "show dnodes;");
xDumpResultToFile(filename, res); xDumpResultToFile(filename, res);
//appendResultToFile(res, filename); //fetchResult(res, filename);
// show databases // show databases
res = taos_query(taos, "show databases;"); res = taos_query(taos, "show databases;");
...@@ -6712,7 +6712,7 @@ static void stable_sub_callback( ...@@ -6712,7 +6712,7 @@ static void stable_sub_callback(
} }
if (param) if (param)
appendResultToFile(res, ((threadInfo *)param)->fp); fetchResult(res, ((threadInfo *)param)->fp);
// tao_unscribe() will free result. // tao_unscribe() will free result.
} }
...@@ -6725,7 +6725,7 @@ static void specified_sub_callback( ...@@ -6725,7 +6725,7 @@ static void specified_sub_callback(
} }
if (param) if (param)
appendResultToFile(res, ((threadInfo *)param)->fp); fetchResult(res, ((threadInfo *)param)->fp);
// tao_unscribe() will free result. // tao_unscribe() will free result.
} }
...@@ -6866,13 +6866,13 @@ static void *superSubscribe(void *sarg) { ...@@ -6866,13 +6866,13 @@ static void *superSubscribe(void *sarg) {
sprintf(pThreadInfo->fp, "%s-%d", sprintf(pThreadInfo->fp, "%s-%d",
g_queryInfo.superQueryInfo.result[pThreadInfo->querySeq], g_queryInfo.superQueryInfo.result[pThreadInfo->querySeq],
pThreadInfo->threadID); pThreadInfo->threadID);
appendResultToFile(res, pThreadInfo->fp); fetchResult(res, pThreadInfo->fp);
} }
if (g_queryInfo.superQueryInfo.result[pThreadInfo->querySeq][0] != 0) { if (g_queryInfo.superQueryInfo.result[pThreadInfo->querySeq][0] != 0) {
sprintf(pThreadInfo->fp, "%s-%d", sprintf(pThreadInfo->fp, "%s-%d",
g_queryInfo.superQueryInfo.result[pThreadInfo->querySeq], g_queryInfo.superQueryInfo.result[pThreadInfo->querySeq],
pThreadInfo->threadID); pThreadInfo->threadID);
appendResultToFile(res, pThreadInfo->fp); fetchResult(res, pThreadInfo->fp);
} }
consumed[tsubSeq] ++; consumed[tsubSeq] ++;
...@@ -6973,7 +6973,7 @@ static void *specifiedSubscribe(void *sarg) { ...@@ -6973,7 +6973,7 @@ static void *specifiedSubscribe(void *sarg) {
sprintf(pThreadInfo->fp, "%s-%d", sprintf(pThreadInfo->fp, "%s-%d",
g_queryInfo.specifiedQueryInfo.result[pThreadInfo->querySeq], g_queryInfo.specifiedQueryInfo.result[pThreadInfo->querySeq],
pThreadInfo->threadID); pThreadInfo->threadID);
appendResultToFile(res, pThreadInfo->fp); fetchResult(res, pThreadInfo->fp);
} }
consumed ++; consumed ++;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册