提交 a375df2b 编写于 作者: H Haojun Liao

Merge branch 'feature/query' of https://github.com/taosdata/TDengine into feature/query

...@@ -708,27 +708,24 @@ void *readTable(void *sarg) { ...@@ -708,27 +708,24 @@ void *readTable(void *sarg) {
sprintf(command, "select %s from %s%d where ts>= %" PRId64, aggreFunc[j], tb_prefix, i, sTime); sprintf(command, "select %s from %s%d where ts>= %" PRId64, aggreFunc[j], tb_prefix, i, sTime);
double t = getCurrentTime(); double t = getCurrentTime();
if (taos_query(taos, command) != 0) { TAOS_RES *pSql = taos_query(taos, command);
fprintf(stderr, "Failed to query\n"); int32_t code = taos_errno(pSql);
taos_close(taos);
exit(EXIT_FAILURE);
}
TAOS_RES *result = taos_use_result(taos); if (code != 0) {
if (result == NULL) { fprintf(stderr, "Failed to query:%s\n", taos_errstr(taos));
fprintf(stderr, "Failed to retreive results:%s\n", taos_errstr(taos)); taos_free_result(pSql);
taos_close(taos); taos_close(taos);
exit(1); exit(EXIT_FAILURE);
} }
while (taos_fetch_row(result) != NULL) { while (taos_fetch_row(pSql) != NULL) {
count++; count++;
} }
t = getCurrentTime() - t; t = getCurrentTime() - t;
totalT += t; totalT += t;
taos_free_result(result); taos_free_result(pSql);
} }
fprintf(fp, "|%10s | %10d | %12.2f | %10.2f |\n", fprintf(fp, "|%10s | %10d | %12.2f | %10.2f |\n",
...@@ -779,20 +776,18 @@ void *readMetric(void *sarg) { ...@@ -779,20 +776,18 @@ void *readMetric(void *sarg) {
fprintf(fp, "%s\n", command); fprintf(fp, "%s\n", command);
double t = getCurrentTime(); double t = getCurrentTime();
if (taos_query(taos, command) != 0) {
fprintf(stderr, "Failed to query\n");
taos_close(taos);
exit(EXIT_FAILURE);
}
TAOS_RES *result = taos_use_result(taos); TAOS_RES *pSql = taos_query(taos, command);
if (result == NULL) { int32_t code = taos_errno(pSql);
fprintf(stderr, "Failed to retreive results:%s\n", taos_errstr(taos));
if (code != 0) {
fprintf(stderr, "Failed to query:%s\n", taos_errstr(taos));
taos_free_result(pSql);
taos_close(taos); taos_close(taos);
exit(1); exit(1);
} }
int count = 0; int count = 0;
while (taos_fetch_row(result) != NULL) { while (taos_fetch_row(pSql) != NULL) {
count++; count++;
} }
t = getCurrentTime() - t; t = getCurrentTime() - t;
...@@ -800,7 +795,7 @@ void *readMetric(void *sarg) { ...@@ -800,7 +795,7 @@ void *readMetric(void *sarg) {
fprintf(fp, "| Speed: %12.2f(per s) | Latency: %.4f(ms) |\n", num_of_tables * num_of_DPT / t, t * 1000); fprintf(fp, "| Speed: %12.2f(per s) | Latency: %.4f(ms) |\n", num_of_tables * num_of_DPT / t, t * 1000);
printf("select %10s took %.6f second(s)\n\n", aggreFunc[j], t); printf("select %10s took %.6f second(s)\n\n", aggreFunc[j], t);
taos_free_result(result); taos_free_result(pSql);
} }
fprintf(fp, "\n"); fprintf(fp, "\n");
} }
...@@ -811,10 +806,19 @@ void *readMetric(void *sarg) { ...@@ -811,10 +806,19 @@ void *readMetric(void *sarg) {
void queryDB(TAOS *taos, char *command) { void queryDB(TAOS *taos, char *command) {
int i = 5; int i = 5;
while (i > 0) { TAOS_RES *pSql = NULL;
if (taos_query(taos, command) == 0) break; int32_t code = -1;
while (i > 0 && code != 0) {
pSql = taos_query(taos, command);
code = taos_errno(pSql);
taos_free_result(pSql);
pSql = NULL;
if (code == 0) {
break;
}
i--; i--;
} }
if (i == 0) { if (i == 0) {
fprintf(stderr, "Failed to run %s, reason: %s\n", command, taos_errstr(taos)); fprintf(stderr, "Failed to run %s, reason: %s\n", command, taos_errstr(taos));
taos_close(taos); taos_close(taos);
...@@ -947,6 +951,7 @@ void callBack(void *param, TAOS_RES *res, int code) { ...@@ -947,6 +951,7 @@ void callBack(void *param, TAOS_RES *res, int code) {
break; break;
} }
} }
tb_info->timestamp = tmp_time;
taos_query_a(tb_info->taos, buffer, callBack, tb_info); taos_query_a(tb_info->taos, buffer, callBack, tb_info);
......
...@@ -372,14 +372,12 @@ int taosGetTableRecordInfo(char *table, STableRecordInfo *pTableRecordInfo) { ...@@ -372,14 +372,12 @@ int taosGetTableRecordInfo(char *table, STableRecordInfo *pTableRecordInfo) {
memset(pTableRecordInfo, 0, sizeof(STableRecordInfo)); memset(pTableRecordInfo, 0, sizeof(STableRecordInfo));
sprintf(command, "show tables like %s", table); sprintf(command, "show tables like %s", table);
if (taos_query(taos, command) != 0) { TAOS_RES *result = taos_query(taos, command);\
fprintf(stderr, "failed to run command %s\n", command); int32_t code = taos_errno(result);
return -1;
}
result = taos_use_result(taos); if (code != 0) {
if (result == NULL) { fprintf(stderr, "failed to run command %s, error: %s\n", command, taos_errstr(result));
fprintf(stderr, "failed to use result\n"); taos_free_result(result);
return -1; return -1;
} }
...@@ -400,14 +398,12 @@ int taosGetTableRecordInfo(char *table, STableRecordInfo *pTableRecordInfo) { ...@@ -400,14 +398,12 @@ int taosGetTableRecordInfo(char *table, STableRecordInfo *pTableRecordInfo) {
if (isSet) return 0; if (isSet) return 0;
sprintf(command, "show stables like %s", table); sprintf(command, "show stables like %s", table);
if (taos_query(taos, command) != 0) {
fprintf(stderr, "failed to run command %s\n", command);
return -1;
}
result = taos_use_result(taos); result = taos_query(taos, command);
if (result == NULL) { code = taos_errno(result);
fprintf(stderr, "failed to use result\n"); if (code != 0) {
fprintf(stderr, "failed to run command %s, error: %s\n", command, taos_errstr(result));
taos_free_result(result);
return -1; return -1;
} }
...@@ -467,14 +463,11 @@ int taosDumpOut(SDumpArguments *arguments) { ...@@ -467,14 +463,11 @@ int taosDumpOut(SDumpArguments *arguments) {
taosDumpCharset(fp); taosDumpCharset(fp);
sprintf(command, "show databases"); sprintf(command, "show databases");
if (taos_query(taos, command) != 0) { result = taos_query(taos, command);
int32_t code = taos_errno(result);
if (code != 0) {
fprintf(stderr, "failed to run command: %s, reason: %s\n", command, taos_errstr(taos)); fprintf(stderr, "failed to run command: %s, reason: %s\n", command, taos_errstr(taos));
goto _exit_failure; taos_free_result(result);
}
result = taos_use_result(taos);
if (result == NULL) {
fprintf(stderr, "failed to use result\n");
goto _exit_failure; goto _exit_failure;
} }
...@@ -612,7 +605,7 @@ int taosDumpDb(SDbInfo *dbInfo, SDumpArguments *arguments, FILE *fp) { ...@@ -612,7 +605,7 @@ int taosDumpDb(SDbInfo *dbInfo, SDumpArguments *arguments, FILE *fp) {
taosDumpCreateDbClause(dbInfo, arguments->with_property, fp); taosDumpCreateDbClause(dbInfo, arguments->with_property, fp);
sprintf(command, "use %s", dbInfo->name); sprintf(command, "use %s", dbInfo->name);
if (taos_query(taos, command) != 0) { if (taos_errno(taos_query(taos, command)) != 0) {
fprintf(stderr, "invalid database %s\n", dbInfo->name); fprintf(stderr, "invalid database %s\n", dbInfo->name);
return -1; return -1;
} }
...@@ -620,14 +613,11 @@ int taosDumpDb(SDbInfo *dbInfo, SDumpArguments *arguments, FILE *fp) { ...@@ -620,14 +613,11 @@ int taosDumpDb(SDbInfo *dbInfo, SDumpArguments *arguments, FILE *fp) {
fprintf(fp, "USE %s\n\n", dbInfo->name); fprintf(fp, "USE %s\n\n", dbInfo->name);
sprintf(command, "show tables"); sprintf(command, "show tables");
if (taos_query(taos, command) != 0) { result = taos_query(taos,command);
fprintf(stderr, "failed to run command %s\n", command); int32_t code = taos_errno(result);
return -1; if (code != 0) {
} fprintf(stderr, "failed to run command %s, error: %s\n", command, taos_errstr(result));
taos_free_result(result);
result = taos_use_result(taos);
if (result == NULL) {
fprintf(stderr, "failed to use result\n");
return -1; return -1;
} }
...@@ -725,14 +715,11 @@ void taosDumpCreateMTableClause(STableDef *tableDes, char *metric, int numOfCols ...@@ -725,14 +715,11 @@ void taosDumpCreateMTableClause(STableDef *tableDes, char *metric, int numOfCols
TAOS_ROW row = NULL; TAOS_ROW row = NULL;
sprintf(command, "select %s from %s limit 1", tableDes->cols[counter].field, tableDes->name); sprintf(command, "select %s from %s limit 1", tableDes->cols[counter].field, tableDes->name);
if (taos_query(taos, command) != 0) {
fprintf(stderr, "failed to run command %s\n", command);
return;
}
result = taos_use_result(taos); result = taos_query(taos, command);
if (result == NULL) { int32_t code = taos_errno(result);
fprintf(stderr, "failed to use result\n"); if (code != 0) {
fprintf(stderr, "failed to run command %s, error: %s\n", command, taos_errstr(result));
return; return;
} }
...@@ -806,14 +793,12 @@ int taosGetTableDes(char *table, STableDef *tableDes) { ...@@ -806,14 +793,12 @@ int taosGetTableDes(char *table, STableDef *tableDes) {
int count = 0; int count = 0;
sprintf(command, "describe %s", table); sprintf(command, "describe %s", table);
if (taos_query(taos, command) != 0) {
fprintf(stderr, "failed to run command %s\n", command);
return -1;
}
result = taos_use_result(taos); result = taos_query(taos, command);
if (result == NULL) { int32_t code = taos_errno(result);
fprintf(stderr, "failed to use result\n"); if (code != 0) {
fprintf(stderr, "failed to run command %s, error: %s\n", command, taos_errstr(result));
taos_free_result(result);
return -1; return -1;
} }
...@@ -889,14 +874,11 @@ int32_t taosDumpMetric(char *metric, SDumpArguments *arguments, FILE *fp) { ...@@ -889,14 +874,11 @@ int32_t taosDumpMetric(char *metric, SDumpArguments *arguments, FILE *fp) {
strcpy(tableRecord.metric, metric); strcpy(tableRecord.metric, metric);
sprintf(command, "select tbname from %s", metric); sprintf(command, "select tbname from %s", metric);
if (taos_query(taos, command) != 0) { result = taos_query(taos, command);
fprintf(stderr, "failed to run command %s\n", command); int32_t code = taos_errno(result);
return -1; if (code != 0) {
} fprintf(stderr, "failed to run command %s, error: %s\n", command, taos_errstr(result));
taos_free_result(result);
result = taos_use_result(taos);
if (result == NULL) {
fprintf(stderr, "failed to use result\n");
return -1; return -1;
} }
...@@ -942,18 +924,16 @@ int taosDumpTableData(FILE *fp, char *tbname, SDumpArguments *arguments) { ...@@ -942,18 +924,16 @@ int taosDumpTableData(FILE *fp, char *tbname, SDumpArguments *arguments) {
sprintf(command, "select * from %s where _c0 >= %" PRId64 " and _c0 <= %" PRId64 " order by _c0 asc", tbname, arguments->start_time, sprintf(command, "select * from %s where _c0 >= %" PRId64 " and _c0 <= %" PRId64 " order by _c0 asc", tbname, arguments->start_time,
arguments->end_time); arguments->end_time);
if (taos_query(taos, command) != 0) {
fprintf(stderr, "failed to run command %s, reason: %s\n", command, taos_errstr(taos)); result = taos_query(taos, command);
return -1; int32_t code = taos_errno(result);
} if (code != 0) {
fprintf(stderr, "failed to run command %s, reason: %s\n", command, taos_errstr(result));
result = taos_use_result(taos); taos_free_result(result);
if (result == NULL) {
fprintf(stderr, "failed to use result\n");
return -1; return -1;
} }
numFields = taos_field_count(taos); numFields = taos_field_count(result);
assert(numFields > 0); assert(numFields > 0);
TAOS_FIELD *fields = taos_fetch_fields(result); TAOS_FIELD *fields = taos_fetch_fields(result);
tbuf = (char *)malloc(COMMAND_SIZE); tbuf = (char *)malloc(COMMAND_SIZE);
...@@ -1242,9 +1222,14 @@ int taosDumpIn(SDumpArguments *arguments) { ...@@ -1242,9 +1222,14 @@ int taosDumpIn(SDumpArguments *arguments) {
tcommand = command; tcommand = command;
} }
taosReplaceCtrlChar(tcommand); taosReplaceCtrlChar(tcommand);
if (taos_query(taos, tcommand) != 0) result = taos_query(taos, tcommand);
int32_t code = taos_errno(result);
if (code != 0)
{
fprintf(stderr, "linenu:%" PRId64 " failed to run command %s reason: %s \ncontinue...\n", linenu, command, fprintf(stderr, "linenu:%" PRId64 " failed to run command %s reason: %s \ncontinue...\n", linenu, command,
taos_errstr(taos)); taos_errstr(taos));
}
taos_free_result(result);
} }
pstr = command; pstr = command;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册