From 439ed872017d9d01d6da2171ac199ab82ea44256 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Mon, 25 Oct 2021 17:46:34 +0800 Subject: [PATCH] [TD-10700]: The escape char backstick can be used for both tag name and column name --- src/client/inc/tscParseLine.h | 1 - src/client/src/tscParseLineProtocol.c | 6 +++--- src/client/src/tscSQLParser.c | 4 ++-- src/inc/taosdef.h | 1 + 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/client/inc/tscParseLine.h b/src/client/inc/tscParseLine.h index 626982e573..f5db644a96 100644 --- a/src/client/inc/tscParseLine.h +++ b/src/client/inc/tscParseLine.h @@ -24,7 +24,6 @@ extern "C" { #define SML_TIMESTAMP_MILLI_SECOND_DIGITS 13 typedef TSDB_SML_PROTOCOL_TYPE SMLProtocolType; -#define SML_ESCAPE_CHAR_SIZE 2 typedef struct { char* key; diff --git a/src/client/src/tscParseLineProtocol.c b/src/client/src/tscParseLineProtocol.c index aefbbd68c2..a2aaa0ac88 100644 --- a/src/client/src/tscParseLineProtocol.c +++ b/src/client/src/tscParseLineProtocol.c @@ -1925,7 +1925,7 @@ static int32_t parseSmlKey(TAOS_SML_KV *pKV, const char **index, SHashObj *pHash return TSDB_CODE_TSC_LINE_SYNTAX_ERROR; } - pKV->key = calloc(len + SML_ESCAPE_CHAR_SIZE + 1, 1); + pKV->key = calloc(len + TS_ESCAPE_CHAR_SIZE + 1, 1); memcpy(pKV->key, key, len + 1); addEscapeCharToString(pKV->key, len); tscDebug("SML:0x%"PRIx64" Key:%s|len:%d", info->id, pKV->key, len); @@ -2022,7 +2022,7 @@ static int32_t parseSmlMeasurement(TAOS_SML_DATA_POINT *pSml, const char **index const char *cur = *index; int16_t len = 0; - pSml->stableName = calloc(TSDB_TABLE_NAME_LEN + SML_ESCAPE_CHAR_SIZE, 1); + pSml->stableName = calloc(TSDB_TABLE_NAME_LEN + TS_ESCAPE_CHAR_SIZE, 1); if (pSml->stableName == NULL){ return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -2119,7 +2119,7 @@ static int32_t parseSmlKvPairs(TAOS_SML_KV **pKVs, int *num_kvs, goto error; } if (!isField && (strcasecmp(pkv->key, "`ID`") == 0)) { - smlData->childTableName = malloc(pkv->length + SML_ESCAPE_CHAR_SIZE + 1); + smlData->childTableName = malloc(pkv->length + TS_ESCAPE_CHAR_SIZE + 1); memcpy(smlData->childTableName, pkv->value, pkv->length); strntolower_s(smlData->childTableName, smlData->childTableName, (int32_t)pkv->length); addEscapeCharToString(smlData->childTableName, (int32_t)pkv->length); diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index f4f6af34e7..2587ce1120 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -6324,8 +6324,8 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { //handle Escape character backstick if (name.z[0] == TS_ESCAPE_CHAR && name.z[name.n - 1] == TS_ESCAPE_CHAR) { memmove(name.z, name.z + 1, name.n); - name.z[name.n - 2] = '\0'; - name.n -= 2; + name.z[name.n - TS_ESCAPE_CHAR_SIZE] = '\0'; + name.n -= TS_ESCAPE_CHAR_SIZE; } if (getColumnIndexByName(&name, pQueryInfo, &columnIndex, tscGetErrorMsgPayload(pCmd)) != TSDB_CODE_SUCCESS) { diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index d7848937b1..78fb2ac01c 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -99,6 +99,7 @@ extern const int32_t TYPE_BYTES[15]; #define TS_PATH_DELIMITER "." #define TS_ESCAPE_CHAR '`' +#define TS_ESCAPE_CHAR_SIZE 2 #define TSDB_TIME_PRECISION_MILLI 0 #define TSDB_TIME_PRECISION_MICRO 1 -- GitLab