diff --git a/src/common/src/tname.c b/src/common/src/tname.c index 29236ed0ff89a4bb2b803a4d924591ba7a05c291..3566f26abd944d1f170b2569e8058c08c0478807 100644 --- a/src/common/src/tname.c +++ b/src/common/src/tname.c @@ -29,6 +29,7 @@ void extractTableName(const char* tableId, char* name) { size_t s2 = strcspn(&tableId[s1 + 1], &TS_PATH_DELIMITER[0]); strncpy(name, &tableId[s1 + s2 + 2], TSDB_TABLE_NAME_LEN); + name[TSDB_TABLE_NAME_LEN] = 0; } char* extractDBName(const char* tableId, char* name) { diff --git a/src/mnode/src/mgmtTable.c b/src/mnode/src/mgmtTable.c index f0c55449a3608de0140d617658890991592330fe..87243d25c00fd883c0a4e1fefe63867aeea72e53 100644 --- a/src/mnode/src/mgmtTable.c +++ b/src/mnode/src/mgmtTable.c @@ -1139,7 +1139,7 @@ int32_t mgmtRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, v prefixLen = strlen(prefix); SPatternCompareInfo info = PATTERN_COMPARE_INFO_INITIALIZER; - char stableName[TSDB_TABLE_NAME_LEN] = {0}; + char stableName[TSDB_TABLE_NAME_LEN + 1] = {0}; while (numOfRows < rows) { pShow->pIter = mgmtGetNextSuperTable(pShow->pIter, &pTable); @@ -2148,7 +2148,7 @@ static int32_t mgmtRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows, continue; } - char tableName[TSDB_TABLE_NAME_LEN] = {0}; + char tableName[TSDB_TABLE_NAME_LEN + 1] = {0}; // pattern compare for table name mgmtExtractTableName(pTable->info.tableId, tableName); diff --git a/tests/pytest/table/boundary.py b/tests/pytest/table/boundary.py index b68671c61a8c3e8f36372a3692732cbaec0635a7..29fdd5c475b39a375071ab1d24b42ef098e901f3 100644 --- a/tests/pytest/table/boundary.py +++ b/tests/pytest/table/boundary.py @@ -10,7 +10,7 @@ from util.sql import * class TDTestCase: - def init(self, conn): + def init(self, conn, logSql): tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) @@ -95,18 +95,43 @@ class TDTestCase: maxTableNameLen = self.getLimitFromSourceCode('TSDB_TABLE_NAME_LEN') tdLog.notice("table name max length is %d" % maxTableNameLen) - name = self.generateString(maxTableNameLen - 1) - tdLog.info("table name is '%s'" % name) + # create a super table with name exceed max length + sname = self.generateString(maxTableNameLen + 1) + tdLog.info("create a super table with length %d" % len(sname)) + tdSql.error("create table %s (ts timestamp, value int) tags(id int)" % sname) - tdSql.execute("create table %s (ts timestamp, value int)" % name) - tdSql.execute("insert into %s values(now, 0)" % name) + # create a super table with name of max length + sname = self.generateString(maxTableNameLen) + tdLog.info("create a super table with length %d" % len(sname)) + tdSql.execute("create table %s (ts timestamp, value int) tags(id int)" % sname) + tdLog.info("check table count, should be one") + tdSql.query('show stables') + tdSql.checkRows(1) + + # create a child table with name exceed max length + name = self.generateString(maxTableNameLen + 1) + tdLog.info("create a child table with length %d" % len(name)) + tdSql.error("create table %s using %s tags(0)" % (name, sname)) + # create a child table with name of max length + name = self.generateString(maxTableNameLen) + tdLog.info("create a child table with length %d" % len(name)) + tdSql.execute("create table %s using %s tags(0)" % (name, sname)) tdSql.query('show tables') tdSql.checkRows(1) - tdSql.query('select * from %s' % name) + # insert one row + tdLog.info("insert one row of data") + tdSql.execute("insert into %s values(now, 0)" % name) + tdSql.query("select * from " + name) + tdSql.checkRows(1) + tdSql.query("select * from " + sname) tdSql.checkRows(1) + name = name[:len(name) - 1] + tdSql.error("select * from " + name) + tdSql.checkRows(0) + def checkRowBoundaries(self): tdLog.debug("checking row boundaries") tdSql.prepare() diff --git a/tests/pytest/util/sql.py b/tests/pytest/util/sql.py index 245e4b0945181762d0dc7994d3bcf0d2d46b1fd4..ec7ac117c07ee6c34ea91ffbb148729ab4c55119 100644 --- a/tests/pytest/util/sql.py +++ b/tests/pytest/util/sql.py @@ -58,6 +58,9 @@ class TDSql: "%s failed: sql:%s, expect error not occured" % (callerFilename, sql)) else: + self.queryRows = 0 + self.queryCols = 0 + self.queryResult = None tdLog.info("sql:%s, expect error occured" % (sql)) def query(self, sql):