From c346e0b0fc626b8180148abf01216f87b8ad6d85 Mon Sep 17 00:00:00 2001 From: Bomin Zhang Date: Wed, 23 Sep 2020 11:09:41 +0800 Subject: [PATCH] fix TD-1469 --- src/client/inc/tscUtil.h | 1 + src/client/src/tscParseInsert.c | 3 +-- src/client/src/tscUtil.c | 46 +++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index c4fba06426..79a792ab65 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -191,6 +191,7 @@ SColumn* tscColumnListInsert(SArray* pColList, SColumnIndex* colIndex); SArray* tscColumnListClone(const SArray* src, int16_t tableIndex); void tscColumnListDestroy(SArray* pColList); +void tscDequoteAndTrimToken(SStrToken* pToken); int32_t tscValidateName(SStrToken* pToken); void tscIncStreamExecutionCount(void* pStream); diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index 327aac22d1..6fd97c09e9 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -1192,8 +1192,7 @@ int tsParseInsertSql(SSqlObj *pSql) { str += index; if (TK_STRING == sToken.type) { - strdequote(sToken.z); - sToken.n = (uint32_t)strtrim(sToken.z); + tscDequoteAndTrimToken(&sToken); } if (sToken.type == TK_RP) { diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 38fb63f18e..de4a52aed4 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -1265,6 +1265,51 @@ static int32_t validateQuoteToken(SStrToken* pToken) { return TSDB_CODE_SUCCESS; } +void tscDequoteAndTrimToken(SStrToken* pToken) { + assert(pToken->type == TK_STRING); + + uint32_t first = 0, last = pToken->n; + + // trim leading spaces + while (first < last) { + char c = pToken->z[first]; + if (c != ' ' && c != '\t') { + break; + } + first++; + } + + // trim ending spaces + while (first < last) { + char c = pToken->z[last - 1]; + if (c != ' ' && c != '\t') { + break; + } + last--; + } + + // there are still at least two characters + if (first < last - 1) { + char c = pToken->z[first]; + // dequote + if ((c == '\'' || c == '"') && c == pToken->z[last - 1]) { + first++; + last--; + } + } + + // left shift the string and pad spaces + for (uint32_t i = 0; i + first < last; i++) { + pToken->z[i] = pToken->z[first + i]; + } + for (uint32_t i = last - first; i < pToken->n; i++) { + pToken->z[i] = ' '; + } + + // adjust token length + pToken->n = last - first; +} + int32_t tscValidateName(SStrToken* pToken) { if (pToken->type != TK_STRING && pToken->type != TK_ID) { return TSDB_CODE_TSC_INVALID_SQL; @@ -1750,6 +1795,7 @@ SSqlObj* createSimpleSubObj(SSqlObj* pSql, void (*fp)(), void* param, int32_t cm SSqlCmd* pCmd = &pNew->cmd; pCmd->command = cmd; pCmd->parseFinished = 1; + pCmd->autoCreated = pSql->cmd.autoCreated; if (tscAddSubqueryInfo(pCmd) != TSDB_CODE_SUCCESS) { tscFreeSqlObj(pNew); -- GitLab