fix: backslash add G only valid in string end

This commit is contained in:
Alex Duan 2024-01-06 21:01:34 +08:00
parent d666897043
commit 0aef021d88
2 changed files with 22 additions and 2 deletions

View File

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