diff --git a/.gitignore b/.gitignore index 091e1d7361495df8da21c79f77e90cc20e595596..d1f1dc4dedb31da5b41a1046d7a4419881746071 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ cmake-build-debug/ cmake-build-release/ cscope.out cscope.files +tags .DS_Store debug/ release/ diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 4021fca42f6db2417068953b0b8dd2d78ada6527..750412117c0d6342b380775881fe30f253004ea6 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; } @@ -8012,7 +8011,9 @@ int32_t validateColumnName(char* name) { return validateColumnName(token.z); } else if (token.type == TK_ID) { stringProcess(name, token.n); - return TSDB_CODE_SUCCESS; + if (strlen(name) == 0) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } } else { if (isNumber(&token)) { return TSDB_CODE_TSC_INVALID_OPERATION; diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index 578756d03e8395ae1d51b4041d9b605df23dffb4..2174437f319d2ff812dccd6ee27fb7c87886b9e8 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -810,6 +810,7 @@ 3,,pytest,python3 test.py -f dbmgmt/dbNameCaseSensitive.py 3,,pytest,python3 test.py -f insert/schemalessCaseSensitive.py 3,,pytest,python3 test.py -f table/columnNameCaseSensitive.py +3,,pytest,python3 test.py -f table/columnNameValidation.py 3,,pytest,python3 test.py -f table/tagNameCaseSensitive.py 3,,pytest,python3 test.py -f table/tbNameCaseSensitive.py 3,,develop-test,python3 ./test.py -f 2-query/ts_hidden_column.py diff --git a/tests/pytest/table/columnNameValidation.py b/tests/pytest/table/columnNameValidation.py new file mode 100644 index 0000000000000000000000000000000000000000..a2968a2ea5053f2f9dd488456ebc62ae37513c27 --- /dev/null +++ b/tests/pytest/table/columnNameValidation.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- + +import sys +import string +import random +import subprocess +from util.log import * +from util.cases import * +from util.sql import * + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + def run(self): + tdSql.prepare() + + tdSql.query('show tables') + tdSql.checkRows(0) + + # uniqueness + tdSql.error("create table t (t timestamp, f int, F int)") + tdSql.error("create table t (t timestamp, `f` int, F int)") + tdSql.error("create table t (t timestamp, `f` int, `f` int)") + tdSql.execute("create table t (t timestamp, `f` int, `F` int)") + tdSql.query("show tables") + tdSql.checkRows(1) + tdSql.execute("drop table t") + + tdSql.error("create table t (t timestamp, f int, `F` int) tags (T int)") + tdSql.error("create table t (t timestamp, f int, `F` int) tags (`T` int, `T` int)") + tdSql.execute("create table t (t timestamp, f int, `F` int) tags (`T` int)") + tdSql.query("show stables") + tdSql.checkRows(1) + tdSql.execute("drop table t") + + # non-emptiness + tdSql.error("create table t (t timestamp, `` int)") + tdSql.error("create table t (t timestamp, `f` int) tags (`` int)") + tdSql.query("show tables") + tdSql.checkRows(0) + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase())