未验证 提交 087b1532 编写于 作者: M Minglei Jin 提交者: GitHub

Merge pull request #14199 from taosdata/fix/TS-1631-V26

fix: uniqueness and non-emptiness validation of column or tag names
......@@ -6,6 +6,7 @@ cmake-build-debug/
cmake-build-release/
cscope.out
cscope.files
tags
.DS_Store
debug/
release/
......
......@@ -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;
......
......@@ -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
......
# -*- 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())
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册