test_lines.py 1.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
from taos.error import OperationalError
from taos import connect, new_bind_params, PrecisionEnum
from taos import *

from ctypes import *
import taos
import pytest


@pytest.fixture
def conn():
    # type: () -> taos.TaosConnection
    return connect()


16
def test_schemaless_insert(conn):
17 18
    # type: (TaosConnection) -> None

19
    dbname = "pytest_taos_schemaless_insert"
20 21 22 23 24 25 26 27 28 29
    try:
        conn.execute("drop database if exists %s" % dbname)
        conn.execute("create database if not exists %s precision 'us'" % dbname)
        conn.select_db(dbname)

        lines = [
            'st,t1=3i64,t2=4f64,t3="t3" c1=3i64,c3=L"passit",c2=false,c4=4f64 1626006833639000000ns',
            'st,t1=4i64,t3="t4",t2=5f64,t4=5f64 c1=3i64,c3=L"passitagin",c2=true,c4=5f64,c5=5f64,c6=7u64 1626006933640000000ns',
            'stf,t1=4i64,t3="t4",t2=5f64,t4=5f64 c1=3i64,c3=L"passitagin_stf",c2=false,c5=5f64,c6=7u64 1626006933641000000ns',
        ]
30
        conn.schemaless_insert(lines, 0)
31 32 33 34 35
        print("inserted")

        lines = [
            'stf,t1=5i64,t3="t4",t2=5f64,t4=5f64 c1=3i64,c3=L"passitagin_stf",c2=false,c5=5f64,c6=7u64 1626006933641000000ns',
        ]
36
        conn.schemaless_insert(lines, 0)
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
        print("inserted")
        result = conn.query("select * from st")
        print(*result.fields)
        all = result.rows_iter()
        for row in all:
            print(row)
        result.close()
        print(result.row_count)

        conn.execute("drop database if exists %s" % dbname)
        conn.close()

    except Exception as err:
        conn.execute("drop database if exists %s" % dbname)
        conn.close()
        print(err)
        raise err


if __name__ == "__main__":
57
    test_schemaless_insert(connect())