queryLike.py 8.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
###################################################################
#           Copyright (c) 2016 by TAOS Technologies, Inc.
#                     All rights reserved.
#
#  This file is proprietary and confidential to TAOS Technologies.
#  No part of this file may be reproduced, stored, transmitted,
#  disclosed or used in any form or by any means other than as
#  expressly provided by the written permission from Jianhui Tao
#
###################################################################

# -*- coding: utf-8 -*-

import sys
import taos
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())

    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%'")
        tdSql.checkRows(0)

        tdSql.execute("create table test_cars(ts timestamp, c nchar(2)) tags(t1 nchar(20))")
        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(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)
        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(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(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 * 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.checkRows(1)
        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(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.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_")

        tdSql.execute("create table stb(ts timestamp, c0 int) tags(t0 nchar(64))")
        tdSql.execute("insert into tb1 using stb tags('测试ABCabc') values(now, 1)")
        tdSql.query("select * from tb1 where t0 like '%试AB%'")
        tdSql.checkRows(1)

        tdSql.query("select * from tb1 where t0 like '测试AB%'")
        tdSql.checkRows(1)

        tdSql.query("select * from tb1 where t0 like '%ABCabc'")
        tdSql.checkRows(1)

        os.system("rm -rf ./*.py.sql")

    def stop(self):
        tdSql.close()
        tdLog.success("%s successfully executed" % __file__)


tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())