diff --git a/tests/pytest/query/queryLike.py b/tests/pytest/query/queryLike.py index 3c3b030f8f718371867f323f2496fb17b6b962e1..e771d7c68ff865e0af46ab79666066d50714c3da 100644 --- a/tests/pytest/query/queryLike.py +++ b/tests/pytest/query/queryLike.py @@ -25,7 +25,8 @@ class TDTestCase: def run(self): tdSql.prepare() - + tdSql.execute("drop database db ") + tdSql.execute("create database if not exists db ") tdSql.execute("create table cars(ts timestamp, c nchar(2)) tags(t1 nchar(2))") tdSql.execute("insert into car0 using cars tags('aa') values(now, 'bb');") tdSql.query("select count(*) from cars where t1 like '%50 90 30 04 00 00%'") @@ -35,6 +36,132 @@ class TDTestCase: tdSql.execute("insert into car1 using test_cars tags('150 90 30 04 00 002') values(now, 'bb');") tdSql.query("select * from test_cars where t1 like '%50 90 30 04 00 00%'") tdSql.checkRows(1) + + tdSql.execute("create stable st (ts timestamp , id int , name binary(20), data double ) tags (ind int , tagg binary(20)) ") + + # check escape about tbname by show tables like + + tdSql.execute("create table tb_ using st tags (1 , 'tag_' ) ") + tdSql.execute("insert into tb_ values( now , 1 , 'tbname_' , 1.0)") + tdSql.execute("create table tba using st tags (1 , 'taga' ) ") + tdSql.execute("insert into tba values( now , 1 , 'tbnamea' , 1.0)") + tdSql.query("show tables like 'tb_'") + tdSql.checkRows(2) + tdSql.query("show tables like 'tb\_'") + tdSql.checkRows(1) + + # check escape about tbname by show tables like + tdSql.query("select * from st where tbname like 'tb\_'") + tdSql.checkRows(1) + + # check escape about regular cols + tdSql.query("select * from st where name like 'tbname\_';") + tdSql.checkRows(1) + + # check escape about tags + tdSql.query("select * from st where tagg like 'tag\_';") + tdSql.checkRows(1) + + # ======================= check multi escape =================== + + tdSql.execute("create table tb_1 using st tags (1 , 'tag_1' ) ") + tdSql.execute("insert into tb_1 values( now , 1 , 'tbname_1' , 1.0)") + tdSql.execute("create table tb_2 using st tags (2 , 'tag_2' )") + tdSql.execute("insert into tb_2 values( now , 2 , 'tbname_2' , 2.0)") + tdSql.execute("create table tb__ using st tags (3 , 'tag__' )") + tdSql.execute("insert into tb__ values( now , 3 , 'tbname__' , 2.0)") + tdSql.execute("create table tb__1 using st tags (3 , 'tag__1' )") + tdSql.execute("insert into tb__1 values( now , 1 , 'tbname__1' , 1.0)") + tdSql.execute("create table tb__2 using st tags (4 , 'tag__2' )") + tdSql.execute("create table tb___ using st tags (5 , 'tag___' )") + tdSql.execute("insert into tb___ values( now , 1 , 'tbname___' , 1.0)") + tdSql.execute("create table tb_d_ using st tags (5 , 'tag_d_' )") + tdSql.execute("insert into tb_d_ values( now , 1 , 'tbname_d_' , 1.0)") + + tdSql.execute("create table tb_d__ using st tags (5 , 'tag_d__' )") + tdSql.execute("insert into tb_d__ values( now , 1 , 'tbname_d__' , 1.0)") + tdSql.execute("create table tb____ using st tags (5 , 'tag____' )") + tdSql.execute("insert into tb____ values( now , 1 , 'tbname____' , 1.0)") + tdSql.execute("create table tb__a_ using st tags (5 , 'tag__a_' )") + tdSql.execute("insert into tb__a_ values( now , 1 , 'tbname__a_' , 1.0)") + tdSql.execute("create table tb__ab__ using st tags (5 , 'tag__ab__' )") + tdSql.execute("insert into tb__ab__ values( now , 1 , 'tbname__ab__' , 1.0)") + + # check escape about tbname by show tables like + tdSql.query("select * from st where tbname like 'tb__'") + tdSql.checkRows(3) + tdSql.query("select * from st where tbname like 'tb_\_'") + tdSql.checkRows(1) + tdSql.query("select * from st where tbname like 'tb___'") + tdSql.checkRows(4) + tdSql.query("select * from st where tbname like 'tb_\__'") + tdSql.checkRows(3) + tdSql.query("select * from st where tbname like 'tb_\_\_'") + tdSql.checkRows(1) + tdSql.query("select * from st where tbname like 'tb\__\_'") + tdSql.checkRows(1) + tdSql.query("select * from st where tbname like 'tb\__\__'") + tdSql.checkRows(2) + tdSql.query("select * from st where tbname like 'tb\__\_\_'") + tdSql.checkRows(2) + tdSql.query("select * from st where tbname like 'tb\____'") + tdSql.checkRows(3) + tdSql.query("select * from st where tbname like 'tb\_\__\_'") + tdSql.checkRows(2) + tdSql.query("select * from st where tbname like 'tb\_\_\_\_'") + tdSql.checkRows(1) + + # check escape about regular cols + tdSql.query("select * from st where name like 'tbname\_\_';") + tdSql.checkRows(1) + tdSql.query("select * from st where name like 'tbname\__';") + tdSql.checkRows(3) + tdSql.query("select * from st where name like 'tbname___';") + tdSql.checkRows(4) + tdSql.query("select * from st where name like 'tbname_\__';") + tdSql.checkRows(3) + tdSql.query("select * from st where name like 'tbname_\_\_';") + tdSql.checkRows(1) + tdSql.query("select * from st where name like 'tbname\_\__';") + tdSql.checkRows(2) + tdSql.query("select * from st where name like 'tbname____';") + tdSql.checkRows(3) + tdSql.query("select * from st where name like 'tbname\_\___';") + tdSql.checkRows(2) + tdSql.query("select * from st where name like 'tbname\_\_\__';") + tdSql.checkRows(1) + tdSql.query("select * from st where name like 'tbname\_\__\_';") + tdSql.checkRows(2) + tdSql.query("select name from st where name like 'tbname\_\_\__';") + tdSql.checkData(0,0 "tbname____") + + # check escape about tags + tdSql.query("select * from st where tagg like 'tag\_';") + tdSql.checkRows(1) + tdSql.query("select * from st where tagg like 'tag\_\_';") + tdSql.checkRows(1) + tdSql.query("select * from st where tagg like 'tag\__';") + tdSql.checkRows(3) + tdSql.query("select * from st where tagg like 'tag___';") + tdSql.checkRows(4) + tdSql.query("select * from st where tagg like 'tag_\__';") + tdSql.checkRows(3) + tdSql.query("select * from st where tagg like 'tag_\_\_';") + tdSql.checkRows(1) + tdSql.query("select * from st where tagg like 'tag\_\__';") + tdSql.checkRows(2) + tdSql.query("select * from st where tagg like 'tag____';") + tdSql.checkRows(3) + tdSql.query("select * from st where tagg like 'tag\_\___';") + tdSql.checkRows(2) + tdSql.query("select * from st where tagg like 'tag\_\_\__';") + tdSql.checkRows(1) + tdSql.query("select * from st where tagg like 'tag\_\__\_';") + tdSql.checkRows(2) + tdSql.query("select * from st where tagg like 'tag\_\__\_';") + tdSql.checkData(0,0 "tag__a_") + + os.system("rm -rf ./*.py.sql") def stop(self): tdSql.close()