This commit is contained in:
dapan1121 2020-12-16 12:08:07 +00:00
parent 29408010b0
commit fce7a9d299
4 changed files with 19 additions and 10 deletions

View File

@ -381,6 +381,7 @@ void tscQueueAsyncError(void(*fp), void *param, int32_t code) {
taosScheduleTask(tscQhandle, &schedMsg); taosScheduleTask(tscQhandle, &schedMsg);
} }
void tscQueueAsyncRes(SSqlObj *pSql) { void tscQueueAsyncRes(SSqlObj *pSql) {
if (pSql == NULL || pSql->signature != pSql) { if (pSql == NULL || pSql->signature != pSql) {
tscDebug("%p SqlObj is freed, not add into queue async res", pSql); tscDebug("%p SqlObj is freed, not add into queue async res", pSql);
@ -390,7 +391,10 @@ void tscQueueAsyncRes(SSqlObj *pSql) {
tscError("%p add into queued async res, code:%s", pSql, tstrerror(pSql->res.code)); tscError("%p add into queued async res, code:%s", pSql, tstrerror(pSql->res.code));
SSqlRes *pRes = &pSql->res; SSqlRes *pRes = &pSql->res;
assert(pSql->fp != NULL && pSql->fetchFp != NULL);
if (pSql->fp == NULL || pSql->fetchFp == NULL){
return;
}
pSql->fp = pSql->fetchFp; pSql->fp = pSql->fetchFp;
(*pSql->fp)(pSql->param, pSql, pRes->code); (*pSql->fp)(pSql->param, pSql, pRes->code);

View File

@ -86,6 +86,6 @@ extern void set_terminal_mode();
extern int get_old_terminal_mode(struct termios* tio); extern int get_old_terminal_mode(struct termios* tio);
extern void reset_terminal_mode(); extern void reset_terminal_mode();
extern SShellArguments args; extern SShellArguments args;
extern TAOS_RES* result; extern int64_t result;
#endif #endif

View File

@ -46,7 +46,7 @@ char CONTINUE_PROMPT[] = " -> ";
int prompt_size = 6; int prompt_size = 6;
#endif #endif
TAOS_RES *result = NULL; int64_t result = 0;
SShellHistory history; SShellHistory history;
#define DEFAULT_MAX_BINARY_DISPLAY_WIDTH 30 #define DEFAULT_MAX_BINARY_DISPLAY_WIDTH 30
@ -294,17 +294,20 @@ void shellRunCommandOnServer(TAOS *con, char command[]) {
st = taosGetTimestampUs(); st = taosGetTimestampUs();
TAOS_RES* pSql = taos_query_h(con, command, &result); TAOS_RES* tmpSql = NULL;
TAOS_RES* pSql = taos_query_h(con, command, &tmpSql);
if (taos_errno(pSql)) { if (taos_errno(pSql)) {
taos_error(pSql, st); taos_error(pSql, st);
return; return;
} }
result = ((SSqlObj*)tmpSql)->self;
if (regex_match(command, "^\\s*use\\s+[a-zA-Z0-9_]+\\s*;\\s*$", REG_EXTENDED | REG_ICASE)) { if (regex_match(command, "^\\s*use\\s+[a-zA-Z0-9_]+\\s*;\\s*$", REG_EXTENDED | REG_ICASE)) {
fprintf(stdout, "Database changed.\n\n"); fprintf(stdout, "Database changed.\n\n");
fflush(stdout); fflush(stdout);
atomic_store_ptr(&result, 0); atomic_store_64(&result, 0);
taos_free_result(pSql); taos_free_result(pSql);
return; return;
} }
@ -313,7 +316,7 @@ void shellRunCommandOnServer(TAOS *con, char command[]) {
int error_no = 0; int error_no = 0;
int numOfRows = shellDumpResult(pSql, fname, &error_no, printMode); int numOfRows = shellDumpResult(pSql, fname, &error_no, printMode);
if (numOfRows < 0) { if (numOfRows < 0) {
atomic_store_ptr(&result, 0); atomic_store_64(&result, 0);
taos_free_result(pSql); taos_free_result(pSql);
return; return;
} }
@ -336,7 +339,7 @@ void shellRunCommandOnServer(TAOS *con, char command[]) {
wordfree(&full_path); wordfree(&full_path);
} }
atomic_store_ptr(&result, 0); atomic_store_64(&result, 0);
taos_free_result(pSql); taos_free_result(pSql);
} }
@ -501,7 +504,7 @@ static int dumpResultToFile(const char* fname, TAOS_RES* tres) {
row = taos_fetch_row(tres); row = taos_fetch_row(tres);
} while( row != NULL); } while( row != NULL);
result = NULL; result = 0;
fclose(fp); fclose(fp);
return numOfRows; return numOfRows;

View File

@ -22,8 +22,10 @@ pthread_t pid;
void shellQueryInterruptHandler(int signum) { void shellQueryInterruptHandler(int signum) {
#ifdef LINUX #ifdef LINUX
void* pResHandle = atomic_val_compare_exchange_64(&result, result, 0); int64_t rid = atomic_val_compare_exchange_64(&result, result, 0);
taos_stop_query(pResHandle); SSqlObj* pSql = taosAcquireRef(tscObjRef, rid);
taos_stop_query(pSql);
taosReleaseRef(tscObjRef, rid);
#else #else
printf("\nReceive ctrl+c or other signal, quit shell.\n"); printf("\nReceive ctrl+c or other signal, quit shell.\n");
exit(0); exit(0);