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

Merge pull request #14182 from taosdata/fix/TS-1631-V24

fix: Uniqueness and non-emptiness validation of column or tag names
......@@ -1569,7 +1569,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;
}
......@@ -1628,7 +1628,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;
}
......@@ -1657,8 +1657,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;
}
......@@ -1804,9 +1804,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;
}
......@@ -7552,7 +7551,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;
......
# -*- 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.
先完成此消息的编辑!
想要评论请 注册