From 3fd2e51e062afc4f3259c1913fb7428557a5ac35 Mon Sep 17 00:00:00 2001 From: kailixu Date: Fri, 20 Sep 2024 09:46:37 +0800 Subject: [PATCH] enh: cannot drop table of system db --- source/libs/parser/src/parTranslater.c | 11 ++++++++++- tests/system-test/1-insert/drop.py | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index fd33a088a1..7d991bce23 100755 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -14570,7 +14570,11 @@ static int32_t rewriteDropTableWithOpt(STranslateContext* pCxt, SQuery* pQuery) char pTableName[TSDB_TABLE_NAME_LEN] = {0}; FOREACH(pNode, pStmt->pTables) { SDropTableClause* pClause = (SDropTableClause*)pNode; - SName name = {0}; + if (IS_SYS_DBNAME(pClause->dbName)) { + return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_TSC_INVALID_OPERATION, + "Cannot drop table of system database: '%s.%s'", pClause->dbName, pClause->tableName); + } + SName name = {0}; toName(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, &name); int32_t code = getTargetName(pCxt, &name, pTableName); if (TSDB_CODE_SUCCESS != code) { @@ -14680,6 +14684,11 @@ static int32_t rewriteDropSuperTablewithOpt(STranslateContext* pCxt, SQuery* pQu if (!pStmt->withOpt) return code; pCxt->withOpt = true; + if (IS_SYS_DBNAME(pStmt->dbName)) { + return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_TSC_INVALID_OPERATION, + "Cannot drop table of system database: '%s.%s'", pStmt->dbName, pStmt->tableName); + } + char pTableName[TSDB_TABLE_NAME_LEN] = {0}; SName name = {0}; toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name); diff --git a/tests/system-test/1-insert/drop.py b/tests/system-test/1-insert/drop.py index 6cbf9501d8..ed892e83d1 100644 --- a/tests/system-test/1-insert/drop.py +++ b/tests/system-test/1-insert/drop.py @@ -172,6 +172,8 @@ class TDTestCase: tdSql.checkRows(0) tdSql.query(f'select * from information_schema.ins_tables where db_name like "dbtest_%"') tdSql.checkRows(8) + tdSql.error(f'drop stable with information_schema.`ins_tables`;') + tdSql.error(f'drop stable with performance_schema.`perf_connections`;') self.drop_table_check_end() def drop_table_with_check(self): self.drop_table_check_init() @@ -194,6 +196,8 @@ class TDTestCase: tdSql.checkRows(0) tdSql.query(f'select * from information_schema.ins_stables where db_name like "dbtest_%"') tdSql.checkRows(2) + tdSql.error(f'drop table with information_schema.`ins_tables`;') + tdSql.error(f'drop table with performance_schema.`perf_connections`;') self.drop_table_check_end() def drop_topic_check(self): tdSql.execute(f'create database {self.dbname} replica {self.replicaVar} wal_retention_period 3600')