Merge pull request #19987 from taosdata/fix/TD-22454-MAIN

fix:  exit call kill query and not to obtain dbname if have -s argument
This commit is contained in:
dapan1121 2023-02-15 18:34:54 +08:00 committed by GitHub
commit 29df9d6034
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 8 deletions

View File

@ -28,7 +28,7 @@ void pressOtherKey(char c);
bool shellAutoInit();
// set conn
void shellSetConn(TAOS* conn);
void shellSetConn(TAOS* conn, bool runOnce);
// exit shell auto funciton, shell exit call once
void shellAutoExit();

View File

@ -332,6 +332,7 @@ bool varMode = false; // enter var names list mode
TAOS* varCon = NULL;
SShellCmd* varCmd = NULL;
bool varRunOnce = false;
SMatch* lastMatch = NULL; // save last match result
int cntDel = 0; // delete byte count after next press tab
@ -375,7 +376,7 @@ void showHelp() {
----- C ----- \n\
create table <tb_name> using <stb_name> tags ...\n\
create database <db_name> <db_options> ...\n\
create dnode \"fqdn:port\"n\
create dnode \"fqdn:port\" ...\n\
create index ...\n\
create mnode on dnode <dnode_id> ;\n\
create qnode on dnode <dnode_id> ;\n\
@ -637,10 +638,11 @@ bool shellAutoInit() {
}
// set conn
void shellSetConn(TAOS* conn) {
varCon = conn;
void shellSetConn(TAOS* conn, bool runOnce) {
varCon = conn;
varRunOnce = runOnce;
// init database and stable
updateTireValue(WT_VAR_DBNAME, false);
if (!runOnce) updateTireValue(WT_VAR_DBNAME, false);
}
// exit shell auto funciton, shell exit call once
@ -784,6 +786,12 @@ int writeVarNames(int type, TAOS_RES* tres) {
return numOfRows;
}
void setThreadNull(int type) {
taosThreadMutexLock(&tiresMutex);
threads[type] = NULL;
taosThreadMutexUnlock(&tiresMutex);
}
bool firstMatchCommand(TAOS* con, SShellCmd* cmd);
//
// thread obtain var thread from db server
@ -799,6 +807,7 @@ void* varObtainThread(void* param) {
TAOS_RES* pSql = taos_query(varCon, varSqls[type]);
if (taos_errno(pSql)) {
taos_free_result(pSql);
setThreadNull(type);
return NULL;
}
@ -814,6 +823,7 @@ void* varObtainThread(void* param) {
firstMatchCommand(varCon, varCmd);
}
setThreadNull(type);
return NULL;
}
@ -1977,7 +1987,7 @@ void callbackAutoTab(char* sqlstr, TAOS* pSql, bool usedb) {
if (dealUseDB(sql)) {
// change to new db
updateTireValue(WT_VAR_STABLE, false);
if (!varRunOnce) updateTireValue(WT_VAR_STABLE, false);
return;
}

View File

@ -1097,10 +1097,11 @@ int32_t shellExecute() {
}
#endif
shellSetConn(shell.conn);
bool runOnce = pArgs->commands != NULL || pArgs->file[0] != 0;
shellSetConn(shell.conn, runOnce);
shellReadHistory();
if (pArgs->commands != NULL || pArgs->file[0] != 0) {
if (runOnce) {
if (pArgs->commands != NULL) {
printf("%s%s\r\n", shell.info.promptHeader, pArgs->commands);
char *cmd = strdup(pArgs->commands);
@ -1160,5 +1161,8 @@ int32_t shellExecute() {
taosThreadJoin(spid, NULL);
shellCleanupHistory();
taos_kill_query(shell.conn);
taos_close(shell.conn);
return 0;
}