From cd3a40e5e43e708507903fb61e567d3b0b849c3a Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Sat, 9 Oct 2021 14:11:19 +0800 Subject: [PATCH] fix shell sql convertion issue --- src/client/src/tscLocal.c | 2 +- src/kit/shell/src/shellEngine.c | 8 +++---- src/util/inc/tutil.h | 1 + src/util/src/tutil.c | 37 +++++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index a9d7b0a01f..da51961d0c 100644 --- a/src/client/src/tscLocal.c +++ b/src/client/src/tscLocal.c @@ -398,7 +398,7 @@ static int32_t tscSCreateBuildResultFields(SSqlObj *pSql, BuildType type, const TAOS_FIELD f; if (type == SCREATE_BUILD_TABLE) { f.type = TSDB_DATA_TYPE_BINARY; - f.bytes = (TSDB_COL_NAME_LEN - 1) + VARSTR_HEADER_SIZE; + f.bytes = (TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE; tstrncpy(f.name, "Table", sizeof(f.name)); } else { f.type = TSDB_DATA_TYPE_BINARY; diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index 21ac5e0b7e..4f0e640b75 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -309,8 +309,8 @@ void shellRunCommandOnServer(TAOS *con, char command[]) { char * fname = NULL; bool printMode = false; - if ((sptr = strstr(command, ">>")) != NULL) { - cptr = strstr(command, ";"); + if ((sptr = tstrstr(command, ">>", true)) != NULL) { + cptr = tstrstr(command, ";", true); if (cptr != NULL) { *cptr = '\0'; } @@ -323,8 +323,8 @@ void shellRunCommandOnServer(TAOS *con, char command[]) { fname = full_path.we_wordv[0]; } - if ((sptr = strstr(command, "\\G")) != NULL) { - cptr = strstr(command, ";"); + if ((sptr = tstrstr(command, "\\G", true)) != NULL) { + cptr = tstrstr(command, ";", true); if (cptr != NULL) { *cptr = '\0'; } diff --git a/src/util/inc/tutil.h b/src/util/inc/tutil.h index 4e2609eb28..4443716bca 100644 --- a/src/util/inc/tutil.h +++ b/src/util/inc/tutil.h @@ -29,6 +29,7 @@ int32_t strdequote(char *src); int32_t strRmquote(char *z, int32_t len); int32_t strRmquoteEscape(char *z, int32_t len); size_t strtrim(char *src); +char * tstrstr(char *src, char *dst, bool ignoreInEsc); char * strnchr(char *haystack, char needle, int32_t len, bool skipquote); char ** strsplit(char *src, const char *delim, int32_t *num); char * strtolower(char *dst, const char *src); diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index 8ae93c5402..24cea24571 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -179,6 +179,43 @@ char *strnchr(char *haystack, char needle, int32_t len, bool skipquote) { return NULL; } +char *tstrstr(char *src, char *dst, bool ignoreInEsc) { + if (!ignoreInEsc) { + return strstr(src, dst); + } + + int32_t len = strlen(src); + bool inEsc = false; + char escChar = 0; + char *str = src, *res = NULL; + + for (int32_t i = 0; i < len; ++i) { + if (src[i] == TS_ESCAPE_CHAR || src[i] == '\'' || src[i] == '\"') { + if (!inEsc) { + escChar = src[i]; + src[i] = 0; + res = strstr(str, dst); + src[i] = escChar; + if (res) { + return res; + } + str = NULL; + } else { + if (src[i] != escChar) { + continue; + } + + str = src + i + 1; + } + + inEsc = !inEsc; + continue; + } + } + + return str ? strstr(str, dst) : NULL; +} + char* strtolower(char *dst, const char *src) { -- GitLab