From f45fde3cc3b4e9495e54c3cdde71c7ff41f50994 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Tue, 24 Aug 2021 15:15:24 +0800 Subject: [PATCH] [TS-165] fix space error when parse sql --- src/client/src/tscParseInsert.c | 5 +++-- src/client/src/tscUtil.c | 4 ++-- src/kit/shell/src/shellEngine.c | 2 +- src/plugins/http/src/httpParser.c | 2 +- src/util/src/ttokenizer.c | 2 +- src/util/src/tutil.c | 6 +++--- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index f5d9a6a17e..2c3c3f2ddf 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -114,7 +114,7 @@ int tsParseTime(SStrToken *pToken, int64_t *time, char **next, char *error, int1 } for (int k = pToken->n; pToken->z[k] != '\0'; k++) { - if (pToken->z[k] == ' ' || pToken->z[k] == '\t') continue; + if (isspace(pToken->z[k])) continue; if (pToken->z[k] == ',') { *next = pTokenEnd; *time = useconds; @@ -1589,7 +1589,8 @@ int tsParseSql(SSqlObj *pSql, bool initial) { ret = tsParseInsertSql(pSql); if (pSql->parseRetry < 1 && (ret == TSDB_CODE_TSC_SQL_SYNTAX_ERROR || ret == TSDB_CODE_TSC_INVALID_OPERATION)) { - tscDebug("0x%"PRIx64 " parse insert sql statement failed, code:%s, clear meta cache and retry ", pSql->self, tstrerror(ret)); + SInsertStatementParam* pInsertParam = &pCmd->insertParam; + tscDebug("0x%"PRIx64 " parse insert sql statement failed, code:%s, msg:%s, clear meta cache and retry ", pSql->self, pInsertParam->msg, tstrerror(ret)); tscResetSqlCmd(pCmd, true); pSql->parseRetry++; diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 1af8eaac2e..ffde345817 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -2684,7 +2684,7 @@ void tscDequoteAndTrimToken(SStrToken* pToken) { // trim leading spaces while (first < last) { char c = pToken->z[first]; - if (c != ' ' && c != '\t') { + if (isspace(c)) { break; } first++; @@ -2693,7 +2693,7 @@ void tscDequoteAndTrimToken(SStrToken* pToken) { // trim ending spaces while (first < last) { char c = pToken->z[last - 1]; - if (c != ' ' && c != '\t') { + if (isspace(c)) { break; } last--; diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index 51a25d59c4..cd88aa78a4 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -147,7 +147,7 @@ TAOS *shellInit(SShellArguments *_args) { static bool isEmptyCommand(const char* cmd) { for (char c = *cmd++; c != 0; c = *cmd++) { - if (c != ' ' && c != '\t' && c != ';') { + if (isspace(c) && c != ';') { return false; } } diff --git a/src/plugins/http/src/httpParser.c b/src/plugins/http/src/httpParser.c index 02f21037b8..7066f19769 100644 --- a/src/plugins/http/src/httpParser.c +++ b/src/plugins/http/src/httpParser.c @@ -663,7 +663,7 @@ static int32_t httpParserOnTarget(HttpParser *parser, HTTP_PARSER_STATE state, c HttpContext *pContext = parser->pContext; int32_t ok = 0; do { - if (!isspace(c) && c != '\r' && c != '\n') { + if (!isspace(c)) { if (httpAppendString(&parser->str, &c, 1)) { httpError("context:%p, fd:%d, parser state:%d, char:[%c]%02x, oom", pContext, pContext->fd, state, c, c); ok = -1; diff --git a/src/util/src/ttokenizer.c b/src/util/src/ttokenizer.c index c4d05b2d5a..1efab138ef 100644 --- a/src/util/src/ttokenizer.c +++ b/src/util/src/ttokenizer.c @@ -608,7 +608,7 @@ SStrToken tStrGetToken(char* str, int32_t* i, bool isPrevOptr) { int32_t numOfComma = 0; char t = str[*i]; - while (t == ' ' || t == '\n' || t == '\r' || t == '\t' || t == '\f' || t == ',') { + while (isspace(t) || t == ',') { if (t == ',' && (++numOfComma > 1)) { // comma only allowed once t0.n = 0; return t0; diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index 1a73991ade..7987d95dca 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -223,7 +223,7 @@ char *paGetToken(char *string, char **token, int32_t *tokenLen) { char quote = 0; while (*string != 0) { - if (*string == ' ' || *string == '\t') { + if (isspace(*string)) { ++string; } else { break; @@ -244,12 +244,12 @@ char *paGetToken(char *string, char **token, int32_t *tokenLen) { break; } - if (*string == '#' || *string == '\n' || *string == '\r') { + if (*string == '#' || isspace(*string)) { *string = 0; break; } - if ((*string == ' ' || *string == '\t') && !quote) { + if (isspace(*string) && !quote) { break; } else { ++string; -- GitLab