From efd2d768cb54ee7663f42c21d9de5aa4b5ffdd5d Mon Sep 17 00:00:00 2001 From: Benguang Zhao Date: Thu, 23 Jun 2022 19:15:04 +0800 Subject: [PATCH] fix: Uniqueness checking of names of columns and tags --- src/client/src/tscSQLParser.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 4021fca42f..988d2ef38f 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -1632,7 +1632,7 @@ static bool validateTableColumnInfo(SArray* pFieldList, SSqlCmd* pCmd) { } // field name must be unique - if (has(pFieldList, i + 1, pField->name) == true) { + if (has(pFieldList, i, pField->name) == true) { invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); return false; } @@ -1691,7 +1691,7 @@ static bool validateTagParams(SArray* pTagsList, SArray* pFieldList, SSqlCmd* pC return false; } - if (has(pTagsList, i + 1, p->name) == true) { + if (has(pTagsList, i, p->name) == true) { invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); return false; } @@ -1720,8 +1720,8 @@ static bool validateTagParams(SArray* pTagsList, SArray* pFieldList, SSqlCmd* pC // field name must be unique for (int32_t i = 0; i < numOfTags; ++i) { TAOS_FIELD* p = taosArrayGet(pTagsList, i); - - if (has(pFieldList, 0, p->name) == true) { + size_t numOfCols = taosArrayGetSize(pFieldList); + if (has(pFieldList, numOfCols, p->name) == true) { invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); return false; } @@ -1867,9 +1867,8 @@ int32_t validateOneColumn(SSqlCmd* pCmd, TAOS_FIELD* pColField) { } /* is contained in pFieldList or not */ -static bool has(SArray* pFieldList, int32_t startIdx, const char* name) { - size_t numOfCols = taosArrayGetSize(pFieldList); - for (int32_t j = startIdx; j < numOfCols; ++j) { +static bool has(SArray* pFieldList, int32_t endIdx, const char* name) { + for (int32_t j = 0; j < endIdx; ++j) { TAOS_FIELD* field = taosArrayGet(pFieldList, j); if (strncmp(name, field->name, sizeof(field->name) - 1) == 0) return true; } -- GitLab