Merge pull request #24358 from taosdata/fix/TD-28164-3.0

fix: backslash add G only valid in string end
This commit is contained in:
Alex Duan 2024-01-07 17:21:48 +08:00 committed by GitHub
commit 3d6818b2f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 2 deletions

View File

@ -195,6 +195,30 @@ int32_t shellRunCommand(char *command, bool recordHistory) {
return shellRunSingleCommand(cmd); return shellRunSingleCommand(cmd);
} }
char * strendG(const char* pstr) {
if(pstr == NULL) {
return NULL;
}
size_t len = strlen(pstr);
if(len < 4) {
return NULL;
}
char * p = (char *)pstr + len - 2;
if (strcmp(p, "\\G") == 0 ){
return p;
}
p = (char *)pstr + len - 3;
if (strcmp(p, "\\G;") == 0) {
return p;
}
return NULL;
}
void shellRunSingleCommandImp(char *command) { void shellRunSingleCommandImp(char *command) {
int64_t st, et; int64_t st, et;
char *sptr = NULL; char *sptr = NULL;
@ -213,7 +237,7 @@ void shellRunSingleCommandImp(char *command) {
} }
} }
if ((sptr = strstr(command, "\\G")) != NULL) { if ((sptr = strendG(command)) != NULL) {
*sptr = '\0'; *sptr = '\0';
printMode = true; // When output to a file, the switch does not work. printMode = true; // When output to a file, the switch does not work.
} }

View File

@ -238,6 +238,7 @@ static int shellDumpWebsocket(WS_RES *wres, char *fname,
return numOfRows; return numOfRows;
} }
char * strendG(const char* pstr);
void shellRunSingleCommandWebsocketImp(char *command) { void shellRunSingleCommandWebsocketImp(char *command) {
int64_t st, et; int64_t st, et;
char *sptr = NULL; char *sptr = NULL;
@ -256,7 +257,7 @@ void shellRunSingleCommandWebsocketImp(char *command) {
} }
} }
if ((sptr = strstr(command, "\\G")) != NULL) { if ((sptr = strendG(command)) != NULL) {
*sptr = '\0'; *sptr = '\0';
printMode = true; // When output to a file, the switch does not work. printMode = true; // When output to a file, the switch does not work.
} }