tbNameCaseSensitive.py 4.6 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
###################################################################
#           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 *
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):

        # table/stable
        tdSql.execute("create database test")
        tdSql.execute("create database `Test`")
        tdSql.execute("use test")
        tdSql.execute("create table tb(ts timestamp, c1 int)")

        tdSql.query("show tables")
        tdSql.checkRows(1)
        tdSql.query("show create table tb")
        tdSql.checkRows(1)
P
Ping Xiao 已提交
35
        tdSql.checkData(0, 1, "CREATE TABLE `tb` (`ts` TIMESTAMP,`c1` INT)")
36 37 38 39 40 41 42 43

        tdSql.error("create table Tb(ts timestamp, c1 int)") 
        tdSql.execute("create table `TB`(ts timestamp, c1 int)")

        tdSql.query("show tables")
        tdSql.checkRows(2)
        tdSql.query("show create table `TB`")
        tdSql.checkRows(1)
P
Ping Xiao 已提交
44
        tdSql.checkData(0, 1, "CREATE TABLE `TB` (`ts` TIMESTAMP,`c1` INT)")
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

        tdSql.query("describe tb")
        tdSql.checkRows(2)

        tdSql.query("describe `TB`")
        tdSql.checkRows(2)

        tdSql.execute("insert into tb values(now, 1)")
        tdSql.error("select * from `Test`.tb")
        tdSql.query("select * from test.tb")
        tdSql.checkRows(1)

        tdSql.execute("insert into `TB` values(now, 1)")
        tdSql.error("select * from `Test`.`TB`")
        tdSql.query("select * from test.`TB`")
        tdSql.checkRows(1)         

        tdSql.execute("create stable stb(ts timestamp, c1 int) tags(t1 int)")
        tdSql.query("show stables")
        tdSql.checkRows(1)

P
Ping Xiao 已提交
66
        tdSql.error("crate stable STb(ts timestamp, c1 int) tags(t1 int)")
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
        tdSql.error("create stable `stb`(ts timestamp, c1 int) tags(t1 int)")
        tdSql.execute("create stable `STB`(ts timestamp, c1 int) tags(t1 int)")
        tdSql.query("show stables")
        tdSql.checkRows(2)

        tdSql.query("describe stb")
        tdSql.checkRows(3)

        tdSql.query("describe `STB`")
        tdSql.checkRows(3)

        tdSql.execute("insert into t1 using stb tags(1) values(now, 1)")
        tdSql.query("select * from stb")
        tdSql.checkRows(1)

        tdSql.execute("insert into t2 using `STB` tags(1) values(now, 1)")
        tdSql.query("select * from `STB`")
        tdSql.checkRows(1)

86
        tdSql.execute("insert into `T2` using `STB` tags(1) values(now + 1s, 1)")
87 88 89 90 91 92
        tdSql.query("select * from `STB`")
        tdSql.checkRows(2)

        tdSql.query("select tbname from `STB`")
        tdSql.checkRows(2)

P
Ping Xiao 已提交
93
        tdSql.execute("alter table stb add column c2 int")        
94 95 96 97 98
        tdSql.execute("alter table stb add tag t2 int")
        tdSql.execute("alter table `STB` add column c2 int")
        tdSql.execute("alter table `STB` add tag t2 int")
        tdSql.execute("alter table `TB` add column c2 int")

P
Ping Xiao 已提交
99 100 101
        tdSql.query("show create table `STB`")
        tdSql.checkData(0, 1, "CREATE TABLE `STB` (`ts` TIMESTAMP,`c1` INT,`c2` INT) TAGS (`t1` INT,`t2` INT)")

102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
        # corner cases
        tdSql.execute("create table `超级表`(ts timestamp, c1 int) tags(t1 int)")
        tdSql.execute("create table `子表一` using `超级表` tags(1)")
        tdSql.execute("insert into `子表二` using `超级表` tags(1) values(now, 1)")

        tdSql.query("select * from `超级表`")
        tdSql.checkRows(1)
        tdSql.query("select * from `子表二`")
        tdSql.checkRows(1)
        tdSql.query("show tables")
        tdSql.checkRows(7)

        tdSql.execute("create table `普通表` (ts timestamp, c1 int)")
        tdSql.execute("insert into `普通表` values(now, 2)")
        tdSql.query("select * from `普通表`")
        tdSql.checkRows(1)
        tdSql.query("show tables")
P
Ping Xiao 已提交
119 120 121
        tdSql.checkRows(8)
        tdSql.query("show create table `普通表`")
        tdSql.checkData(0, 0, "CREATE TABLE `普通表` (`ts` TIMESTAMP,`c1` INT)")        
122 123 124 125 126 127 128

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

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