db.py 2.0 KB
Newer Older
P
plum-lihui 已提交
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
import taos
import sys
import datetime
import inspect

from util.log import *
from util.sql import *
from util.cases import *
import random


class TDTestCase:

    def init(self, conn, logSql):
        tdLog.debug(f"start to excute {__file__}")
        tdSql.init(conn.cursor(), False)

    def case1(self):
        tdSql.execute("create database if not exists dbms precision 'ms'")
        tdSql.execute("create database if not exists dbus precision 'us'")
        tdSql.execute("create database if not exists dbns precision 'ns'")

        tdSql.execute("create table dbms.ntb (ts timestamp, c1 int, c2 bigint)")
        tdSql.execute("create table dbus.ntb (ts timestamp, c1 int, c2 bigint)")
        tdSql.execute("create table dbns.ntb (ts timestamp, c1 int, c2 bigint)")
C
cpwu 已提交
26

P
plum-lihui 已提交
27 28
        tdSql.execute("insert into dbms.ntb values ('2022-01-01 08:00:00.001', 1, 2)")
        tdSql.execute("insert into dbms.ntb values ('2022-01-01 08:00:00.002', 3, 4)")
C
cpwu 已提交
29

P
plum-lihui 已提交
30 31
        tdSql.execute("insert into dbus.ntb values ('2022-01-01 08:00:00.000001', 1, 2)")
        tdSql.execute("insert into dbus.ntb values ('2022-01-01 08:00:00.000002', 3, 4)")
C
cpwu 已提交
32

P
plum-lihui 已提交
33 34
        tdSql.execute("insert into dbns.ntb values ('2022-01-01 08:00:00.000000001', 1, 2)")
        tdSql.execute("insert into dbns.ntb values ('2022-01-01 08:00:00.000000002', 3, 4)")
C
cpwu 已提交
35

P
plum-lihui 已提交
36 37
        tdSql.query("select count(c1) from dbms.ntb interval(1a)")
        tdSql.checkRows(2)
C
cpwu 已提交
38

P
plum-lihui 已提交
39 40
        tdSql.query("select count(c1) from dbus.ntb interval(1u)")
        tdSql.checkRows(2)
C
cpwu 已提交
41

P
plum-lihui 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
        tdSql.query("select count(c1) from dbns.ntb interval(1b)")
        tdSql.checkRows(2)

    def run(self):  # sourcery skip: extract-duplicate-method, remove-redundant-fstring
        tdSql.prepare()

        tdLog.printNoPrefix("==========start case1 run ...............")

        self.case1()

        tdLog.printNoPrefix("==========end case1 run ...............")

    def stop(self):
        tdSql.close()
        tdLog.success(f"{__file__} successfully executed")


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