queryTbnameUpperLower.py 3.7 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
###################################################################
#           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 -*-
from util.log import tdLog
from util.cases import tdCases
from util.sql import tdSql
from util.common import tdCom

class TDTestCase:
    def init(self, conn, logSql):
        tdLog.debug("start to execute %s" % __file__)
        tdSql.init(conn.cursor(), logSql)

    def checkStbWhereIn(self):
        '''
            where in ---> upper lower mixed
        '''
        tdCom.cleanTb()
        table_name = tdCom.getLongName(8, "letters_mixed")
29 30
        while table_name.islower():
            table_name = tdCom.getLongName(8, "letters_mixed")
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
        table_name_sub = f'{table_name}_sub'
        tb_name_lower = table_name_sub.lower()
        tb_name_upper = table_name_sub.upper()

        ## create stb and tb
        tdSql.execute(f'CREATE TABLE {table_name} (ts timestamp, id int, bi1 binary(20)) tags (si1 binary(20))')
        tdSql.execute(f'create table {table_name_sub}1 using {table_name} tags ("{table_name_sub}1")')
        tdSql.execute(f'create table {tb_name_lower}2 using {table_name} tags ("{tb_name_lower}2")')
        tdSql.execute(f'create table {tb_name_upper}3 using {table_name} tags ("{tb_name_upper}3")')

        ## insert values
        tdSql.execute(f'insert into {table_name_sub}1 values (now-1s, 1, "{table_name_sub}1")')
        tdSql.execute(f'insert into {tb_name_lower}2 values (now-2s, 2, "{tb_name_lower}21")')
        tdSql.execute(f'insert into {tb_name_lower}2 values (now-3s, 3, "{tb_name_lower}22")')
        tdSql.execute(f'insert into {tb_name_upper}3 values (now-4s, 4, "{tb_name_upper}31")')
        tdSql.execute(f'insert into {tb_name_upper}3 values (now-5s, 5, "{tb_name_upper}32")')
        tdSql.execute(f'insert into {tb_name_upper}3 values (now-6s, 6, "{tb_name_upper}33")')

        ## query where tbname in single
        tdSql.query(f'select * from {table_name} where tbname in ("{table_name_sub}1")')
D
dapan1121 已提交
51
        tdSql.checkRows(0)
52
        tdSql.query(f'select * from {table_name} where tbname in ("{table_name_sub.upper()}1")')
D
dapan1121 已提交
53
        tdSql.checkRows(0)
54 55 56 57 58
        tdSql.query(f'select * from {table_name} where tbname in ("{table_name_sub.lower()}1")')
        tdSql.checkRows(1)
        tdSql.query(f'select * from {table_name} where tbname in ("{tb_name_lower}2")')
        tdSql.checkRows(2)
        tdSql.query(f'select * from {table_name} where tbname in ("{tb_name_lower.upper()}2")')
D
dapan1121 已提交
59
        tdSql.checkRows(0)
60
        tdSql.query(f'select * from {table_name} where tbname in ("{tb_name_upper}3")')
D
dapan1121 已提交
61
        tdSql.checkRows(0)
62 63 64 65 66 67 68
        tdSql.query(f'select * from {table_name} where tbname in ("{tb_name_upper.lower()}3")')
        tdSql.checkRows(3)
        
        ## query where tbname in multi
        tdSql.query(f'select * from {table_name} where id=5 and tbname in ("{table_name_sub}1", "{tb_name_lower.upper()}2", "{tb_name_upper.lower()}3")')
        tdSql.checkRows(1)
        tdSql.query(f'select * from {table_name} where tbname in ("{table_name_sub}1", "{tb_name_lower.upper()}2", "{tb_name_upper.lower()}3")')
D
dapan1121 已提交
69
        tdSql.checkRows(3)
70 71 72 73 74 75 76 77 78 79

    def run(self):
        tdSql.prepare()
        self.checkStbWhereIn()

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

tdCases.addWindows(__file__, TDTestCase())
D
dapan1121 已提交
80
tdCases.addLinux(__file__, TDTestCase())