Merge pull request #13533 from taosdata/test/chr/TD-14699
test:add testcase of python connector using Statement API
This commit is contained in:
commit
ffa098e224
|
@ -31,7 +31,7 @@ if $data[0][4] != ready then
|
||||||
goto check_dnode_ready
|
goto check_dnode_ready
|
||||||
endi
|
endi
|
||||||
|
|
||||||
#sql connect
|
sql connect
|
||||||
sql create dnode $hostname port 7200
|
sql create dnode $hostname port 7200
|
||||||
sql create dnode $hostname port 7300
|
sql create dnode $hostname port 7300
|
||||||
sql create dnode $hostname port 7400
|
sql create dnode $hostname port 7400
|
||||||
|
@ -71,7 +71,7 @@ sql create database db replica $replica vgroups $vgroups
|
||||||
$loop_cnt = 0
|
$loop_cnt = 0
|
||||||
check_db_ready:
|
check_db_ready:
|
||||||
$loop_cnt = $loop_cnt + 1
|
$loop_cnt = $loop_cnt + 1
|
||||||
sleep 200
|
sleep 20
|
||||||
if $loop_cnt == 10 then
|
if $loop_cnt == 10 then
|
||||||
print ====> db not ready!
|
print ====> db not ready!
|
||||||
return -1
|
return -1
|
||||||
|
@ -93,13 +93,12 @@ $loop_cnt = 0
|
||||||
check_vg_ready:
|
check_vg_ready:
|
||||||
$loop_cnt = $loop_cnt + 1
|
$loop_cnt = $loop_cnt + 1
|
||||||
sleep 200
|
sleep 200
|
||||||
if $loop_cnt == 10 then
|
if $loop_cnt == 300 then
|
||||||
print ====> vgroups not ready!
|
print ====> vgroups not ready!
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
sql show vgroups
|
sql show vgroups
|
||||||
print ===> rows: $rows
|
print ===> rows: $rows
|
||||||
print $data(2)[0] $data(2)[1] $data(2)[2] $data(2)[3] $data(2)[4] $data(2)[5] $data(2)[6] $data(2)[7] $data(2)[8] $data(2)[9] $data(2)[10] $data(2)[11] $data(2)[12] $data(2)[13]
|
|
||||||
print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] $data[0][7] $data[0][8] $data[0][9] $data[10][6] $data[0][11] $data[0][12] $data[0][13]
|
print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] $data[0][7] $data[0][8] $data[0][9] $data[10][6] $data[0][11] $data[0][12] $data[0][13]
|
||||||
if $rows != $vgroups then
|
if $rows != $vgroups then
|
||||||
return -1
|
return -1
|
||||||
|
@ -132,10 +131,12 @@ if $data[0][8] == leader then
|
||||||
goto check_vg_ready
|
goto check_vg_ready
|
||||||
endi
|
endi
|
||||||
print ---- vgroup $data[0][0] leader locate on dnode $data[0][7]
|
print ---- vgroup $data[0][0] leader locate on dnode $data[0][7]
|
||||||
goto vg_ready
|
goto vg_ready
|
||||||
|
else
|
||||||
|
goto check_vg_ready
|
||||||
endi
|
endi
|
||||||
vg_ready:
|
|
||||||
|
|
||||||
|
vg_ready:
|
||||||
print ====> create stable/child table
|
print ====> create stable/child table
|
||||||
sql create table stb (ts timestamp, c1 int, c2 float, c3 binary(10)) tags (t1 int)
|
sql create table stb (ts timestamp, c1 int, c2 float, c3 binary(10)) tags (t1 int)
|
||||||
|
|
||||||
|
@ -156,27 +157,13 @@ while $i < $tbNum
|
||||||
sql create table $ctb using stb tags( $i )
|
sql create table $ctb using stb tags( $i )
|
||||||
$ntb = $ntbPrefix . $i
|
$ntb = $ntbPrefix . $i
|
||||||
sql create table $ntb (ts timestamp, c1 int, c2 float, c3 binary(10))
|
sql create table $ntb (ts timestamp, c1 int, c2 float, c3 binary(10))
|
||||||
|
|
||||||
# $x = 0
|
|
||||||
# while $x < $rowNum
|
|
||||||
# $binary = ' . binary
|
|
||||||
# $binary = $binary . $i
|
|
||||||
# $binary = $binary . '
|
|
||||||
#
|
|
||||||
# sql insert into $ctb values ($tstart , $i , $x , $binary )
|
|
||||||
# sql insert into $ntb values ($tstart , 999 , 999 , 'binary-ntb' )
|
|
||||||
# $tstart = $tstart + 1
|
|
||||||
# $x = $x + 1
|
|
||||||
# endw
|
|
||||||
|
|
||||||
# print ====> insert rows: $rowNum into $ctb and $ntb
|
|
||||||
|
|
||||||
$i = $i + 1
|
$i = $i + 1
|
||||||
# $tstart = 1640966400000
|
|
||||||
endw
|
endw
|
||||||
|
|
||||||
$totalTblNum = $tbNum * 2
|
$totalTblNum = $tbNum * 2
|
||||||
|
sleep 1000
|
||||||
sql show tables
|
sql show tables
|
||||||
|
print ====> expect $totalTblNum and infinsert $rows in fact
|
||||||
if $rows != $totalTblNum then
|
if $rows != $totalTblNum then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
@ -185,7 +172,7 @@ print ====> create a normal table for interaction between main and back threads
|
||||||
sql create table interaction (ts timestamp, flag binary(10), childrows int, stbrows int)
|
sql create table interaction (ts timestamp, flag binary(10), childrows int, stbrows int)
|
||||||
|
|
||||||
print ====> start to run_back to insert data
|
print ====> start to run_back to insert data
|
||||||
run_back tsim/tmq/insertDataByRunBack.sim
|
run_back tsim/sync/insertDataByRunBack.sim
|
||||||
|
|
||||||
|
|
||||||
print ====> waiting insert thread starting insert data
|
print ====> waiting insert thread starting insert data
|
||||||
|
@ -222,12 +209,15 @@ endi
|
||||||
$dnodeId = dnode . $dnodeId
|
$dnodeId = dnode . $dnodeId
|
||||||
print ====> stop $dnodeId
|
print ====> stop $dnodeId
|
||||||
system sh/exec.sh -n $dnodeId -s stop -x SIGINT
|
system sh/exec.sh -n $dnodeId -s stop -x SIGINT
|
||||||
|
sleep 1000
|
||||||
|
print ====> start $dnodeId
|
||||||
|
system sh/exec.sh -n $dnodeId -s start
|
||||||
|
|
||||||
$loop_cnt = 0
|
$loop_cnt = 0
|
||||||
check_vg_ready_2:
|
check_vg_ready_2:
|
||||||
$loop_cnt = $loop_cnt + 1
|
$loop_cnt = $loop_cnt + 1
|
||||||
sleep 200
|
sleep 200
|
||||||
if $loop_cnt == 10 then
|
if $loop_cnt == 300 then
|
||||||
print ====> vgroups switch fail!!!
|
print ====> vgroups switch fail!!!
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
@ -242,38 +232,38 @@ if $data[0][4] == leader then
|
||||||
if $data[0][6] != NULL then
|
if $data[0][6] != NULL then
|
||||||
goto check_vg_ready_2
|
goto check_vg_ready_2
|
||||||
endi
|
endi
|
||||||
if $data[0][8] != NULL then
|
if $data[0][8] != FOLLOWER then
|
||||||
goto check_vg_ready_2
|
goto check_vg_ready_2
|
||||||
endi
|
endi
|
||||||
print ---- vgroup $data[0][0] leader switch to dnode $data[0][3]
|
print ---- vgroup $dnodeId leader switch to dnode $data[0][3]
|
||||||
goto vg_ready_2
|
goto vg_ready_2
|
||||||
endi
|
endi
|
||||||
if $data[0][6] == leader then
|
if $data[0][6] == leader then
|
||||||
if $data[0][4] != NULL then
|
if $data[0][4] != NULL then
|
||||||
goto check_vg_ready_2
|
goto check_vg_ready_2
|
||||||
endi
|
endi
|
||||||
if $data[0][8] != NULL then
|
if $data[0][8] != FOLLOWER then
|
||||||
goto check_vg_ready_2
|
goto check_vg_ready_2
|
||||||
endi
|
endi
|
||||||
print ---- vgroup $data[0][0] leader switch to dnode $data[0][5]
|
print ---- vgroup $dnodeId leader switch to dnode $data[0][5]
|
||||||
goto vg_ready_2
|
goto vg_ready_2
|
||||||
endi
|
endi
|
||||||
if $data[0][8] == leader then
|
if $data[0][8] == leader then
|
||||||
if $data[0][4] != NULL then
|
if $data[0][4] != NULL then
|
||||||
goto check_vg_ready_2
|
goto check_vg_ready_2
|
||||||
endi
|
endi
|
||||||
if $data[0][6] != NULL then
|
if $data[0][6] != FOLLOWER then
|
||||||
goto check_vg_ready_2
|
goto check_vg_ready_2
|
||||||
endi
|
endi
|
||||||
print ---- vgroup $data[0][0] leader switch to dnode $data[0][7]
|
print ---- vgroup $dnodeId leader switch to dnode $data[0][7]
|
||||||
goto vg_ready_2
|
goto vg_ready_2
|
||||||
|
else
|
||||||
|
goto check_vg_ready_2
|
||||||
endi
|
endi
|
||||||
vg_ready_2:
|
vg_ready_2:
|
||||||
|
|
||||||
$switch_loop_cnt = $switch_loop_cnt + 1
|
$switch_loop_cnt = $switch_loop_cnt + 1
|
||||||
if $switch_loop_cnt < 3 then
|
if $switch_loop_cnt < 3 then
|
||||||
print ====> start $dnodeId
|
|
||||||
system sh/exec.sh -n $dnodeId -s start
|
|
||||||
goto switch_leader_loop
|
goto switch_leader_loop
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
@ -347,7 +337,7 @@ if $data[0][4] == leader then
|
||||||
if $data[0][6] != NULL then
|
if $data[0][6] != NULL then
|
||||||
goto check_vg_ready_1
|
goto check_vg_ready_1
|
||||||
endi
|
endi
|
||||||
if $data[0][8] != NULL then
|
if $data[0][8] != FOLLOWER then
|
||||||
goto check_vg_ready_1
|
goto check_vg_ready_1
|
||||||
endi
|
endi
|
||||||
goto vg_ready_1
|
goto vg_ready_1
|
||||||
|
@ -356,7 +346,7 @@ if $data[0][6] == leader then
|
||||||
if $data[0][4] != NULL then
|
if $data[0][4] != NULL then
|
||||||
goto check_vg_ready_1
|
goto check_vg_ready_1
|
||||||
endi
|
endi
|
||||||
if $data[0][8] != NULL then
|
if $data[0][8] != FOLLOWER then
|
||||||
goto check_vg_ready_1
|
goto check_vg_ready_1
|
||||||
endi
|
endi
|
||||||
goto vg_ready_1
|
goto vg_ready_1
|
||||||
|
@ -365,7 +355,7 @@ if $data[0][8] == leader then
|
||||||
if $data[0][4] != NULL then
|
if $data[0][4] != NULL then
|
||||||
goto check_vg_ready_1
|
goto check_vg_ready_1
|
||||||
endi
|
endi
|
||||||
if $data[0][6] != NULL then
|
if $data[0][6] != FOLLOWER then
|
||||||
goto check_vg_ready_1
|
goto check_vg_ready_1
|
||||||
endi
|
endi
|
||||||
goto vg_ready_1
|
goto vg_ready_1
|
||||||
|
@ -394,6 +384,73 @@ if $data[0][0] != $totalRowsOfStb then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
print ====> once stop one dnode by loop, and do query every time
|
||||||
|
$i = 2
|
||||||
|
loop_stop_dnode:
|
||||||
|
$dnodeId = dnode . $i
|
||||||
|
print ====> stop $dnodeId
|
||||||
|
system sh/exec.sh -n $dnodeId -s stop -x SIGINT
|
||||||
|
|
||||||
|
check_vg_ready_3:
|
||||||
|
sql show vgroups
|
||||||
|
print $data(2)[0] $data(2)[1] $data(2)[2] $data(2)[3] $data(2)[4] $data(2)[5] $data(2)[6] $data(2)[7] $data(2)[8] $data(2)[9] $data(2)[10] $data(2)[11] $data(2)[12] $data(2)[13]
|
||||||
|
if $data[0][4] == LEADER then
|
||||||
|
if $data[0][6] == LEADER then
|
||||||
|
goto check_vg_ready_3
|
||||||
|
endi
|
||||||
|
if $data[0][8] == LEADER then
|
||||||
|
goto check_vg_ready_3
|
||||||
|
endi
|
||||||
|
print ---- vgroup $data[0][0] leader locating dnode $data[0][5]
|
||||||
|
elif $data[0][6] == LEADER then
|
||||||
|
if $data[0][4] == LEADER then
|
||||||
|
goto check_vg_ready_3
|
||||||
|
endi
|
||||||
|
if $data[0][8] == LEADER then
|
||||||
|
goto check_vg_ready_3
|
||||||
|
endi
|
||||||
|
print ---- vgroup $data[0][0] leader locating dnode $data[0][7]
|
||||||
|
elif $data[0][8] == LEADER then
|
||||||
|
if $data[0][4] == LEADER then
|
||||||
|
goto check_vg_ready_3
|
||||||
|
endi
|
||||||
|
if $data[0][6] == LEADER then
|
||||||
|
goto check_vg_ready_3
|
||||||
|
endi
|
||||||
|
print ---- vgroup $data[0][0] leader locating dnode $data[0][9]
|
||||||
|
else
|
||||||
|
print ====> no leader vnode!!!
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
sql select count(*) from ntb0
|
||||||
|
print rows: $rows
|
||||||
|
print $data[0][0] $data[0][1]
|
||||||
|
if $data[0][0] != $totalRowsOfCtb then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
sql select count(*) from ctb0
|
||||||
|
print rows: $rows
|
||||||
|
print $data[0][0] $data[0][1]
|
||||||
|
if $data[0][0] != $totalRowsOfCtb then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
sql select count(*) from stb
|
||||||
|
print rows: $rows
|
||||||
|
print $data[0][0] $data[0][1]
|
||||||
|
if $data[0][0] != $totalRowsOfStb then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
$i = $i + 1
|
||||||
|
if $i <= 4 then
|
||||||
|
print ====> start $dnodeId
|
||||||
|
system sh/exec.sh -n $dnodeId -s start
|
||||||
|
goto loop_stop_dnode
|
||||||
|
endi
|
||||||
|
|
||||||
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
||||||
system sh/exec.sh -n dnode2 -s stop -x SIGINT
|
system sh/exec.sh -n dnode2 -s stop -x SIGINT
|
||||||
system sh/exec.sh -n dnode3 -s stop -x SIGINT
|
system sh/exec.sh -n dnode3 -s stop -x SIGINT
|
||||||
|
|
|
@ -80,93 +80,9 @@ class TDTestCase:
|
||||||
con=taos.connect(host=host, user=user, password=password, config=cfg ,port=port)
|
con=taos.connect(host=host, user=user, password=password, config=cfg ,port=port)
|
||||||
print(con)
|
print(con)
|
||||||
return con
|
return con
|
||||||
|
|
||||||
def test_stmt_insert_multi(self,conn):
|
|
||||||
# type: (TaosConnection) -> None
|
|
||||||
|
|
||||||
dbname = "pytest_taos_stmt_multi"
|
|
||||||
try:
|
|
||||||
conn.execute("drop database if exists %s" % dbname)
|
|
||||||
conn.execute("create database if not exists %s" % dbname)
|
|
||||||
conn.select_db(dbname)
|
|
||||||
|
|
||||||
conn.execute(
|
|
||||||
"create table if not exists log(ts timestamp, bo bool, nil tinyint, ti tinyint, si smallint, ii int,\
|
|
||||||
bi bigint, tu tinyint unsigned, su smallint unsigned, iu int unsigned, bu bigint unsigned, \
|
|
||||||
ff float, dd double, bb binary(100), nn nchar(100), tt timestamp)",
|
|
||||||
)
|
|
||||||
# conn.load_table_info("log")
|
|
||||||
|
|
||||||
start = datetime.now()
|
|
||||||
stmt = conn.statement("insert into log values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
|
||||||
|
|
||||||
params = new_multi_binds(16)
|
|
||||||
params[0].timestamp((1626861392589, 1626861392590, 1626861392591))
|
|
||||||
params[1].bool((True, None, False))
|
|
||||||
params[2].tinyint([-128, -128, None]) # -128 is tinyint null
|
|
||||||
params[3].tinyint([0, 127, None])
|
|
||||||
params[4].smallint([3, None, 2])
|
|
||||||
params[5].int([3, 4, None])
|
|
||||||
params[6].bigint([3, 4, None])
|
|
||||||
params[7].tinyint_unsigned([3, 4, None])
|
|
||||||
params[8].smallint_unsigned([3, 4, None])
|
|
||||||
params[9].int_unsigned([3, 4, None])
|
|
||||||
params[10].bigint_unsigned([3, 4, None])
|
|
||||||
params[11].float([3, None, 1])
|
|
||||||
params[12].double([3, None, 1.2])
|
|
||||||
params[13].binary(["abc", "dddafadfadfadfadfa", None])
|
|
||||||
params[14].nchar(["涛思数据", None, "a long string with 中文字符"])
|
|
||||||
params[15].timestamp([None, None, 1626861392591])
|
|
||||||
# print(type(stmt))
|
|
||||||
stmt.bind_param_batch(params)
|
|
||||||
stmt.execute()
|
|
||||||
end = datetime.now()
|
|
||||||
print("elapsed time: ", end - start)
|
|
||||||
assert stmt.affected_rows == 3
|
|
||||||
|
|
||||||
#query
|
|
||||||
querystmt=conn.statement("select ?,bu from log")
|
|
||||||
queryparam=new_bind_params(1)
|
|
||||||
print(type(queryparam))
|
|
||||||
queryparam[0].binary("ts")
|
|
||||||
querystmt.bind_param(queryparam)
|
|
||||||
querystmt.execute()
|
|
||||||
result=querystmt.use_result()
|
|
||||||
# rows=result.fetch_all()
|
|
||||||
# print( querystmt.use_result())
|
|
||||||
|
|
||||||
# result = conn.query("select * from log")
|
|
||||||
rows=result.fetch_all()
|
|
||||||
# rows=result.fetch_all()
|
|
||||||
print(rows)
|
|
||||||
assert rows[1][0] == "ts"
|
|
||||||
assert rows[0][1] == 3
|
|
||||||
|
|
||||||
#query
|
|
||||||
querystmt1=conn.statement("select * from log where bu < ?")
|
|
||||||
queryparam1=new_bind_params(1)
|
|
||||||
print(type(queryparam1))
|
|
||||||
queryparam1[0].int(4)
|
|
||||||
querystmt1.bind_param(queryparam1)
|
|
||||||
querystmt1.execute()
|
|
||||||
result1=querystmt1.use_result()
|
|
||||||
rows1=result1.fetch_all()
|
|
||||||
assert str(rows1[0][0]) == "2021-07-21 17:56:32.589000"
|
|
||||||
assert rows1[0][10] == 3
|
|
||||||
|
|
||||||
|
|
||||||
stmt.close()
|
|
||||||
|
|
||||||
# conn.execute("drop database if exists %s" % dbname)
|
|
||||||
conn.close()
|
|
||||||
|
|
||||||
except Exception as err:
|
|
||||||
# conn.execute("drop database if exists %s" % dbname)
|
|
||||||
conn.close()
|
|
||||||
raise err
|
|
||||||
|
|
||||||
def test_stmt_set_tbname_tag(self,conn):
|
def test_stmt_set_tbname_tag(self,conn):
|
||||||
dbname = "pytest_taos_stmt_set_tbname_tag"
|
dbname = "stmt_set_tbname_tag"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
conn.execute("drop database if exists %s" % dbname)
|
conn.execute("drop database if exists %s" % dbname)
|
||||||
|
@ -174,16 +90,16 @@ class TDTestCase:
|
||||||
conn.select_db(dbname)
|
conn.select_db(dbname)
|
||||||
conn.execute("create table if not exists log(ts timestamp, bo bool, nil tinyint, ti tinyint, si smallint, ii int,\
|
conn.execute("create table if not exists log(ts timestamp, bo bool, nil tinyint, ti tinyint, si smallint, ii int,\
|
||||||
bi bigint, tu tinyint unsigned, su smallint unsigned, iu int unsigned, bu bigint unsigned, \
|
bi bigint, tu tinyint unsigned, su smallint unsigned, iu int unsigned, bu bigint unsigned, \
|
||||||
ff float, dd double, bb binary(100), nn nchar(100), tt timestamp) tags (t1 timestamp, t2 bool,\
|
ff float, dd double, bb binary(100), nn nchar(100), tt timestamp , vc varchar(100)) tags (t1 timestamp, t2 bool,\
|
||||||
t3 tinyint, t4 tinyint, t5 smallint, t6 int, t7 bigint, t8 tinyint unsigned, t9 smallint unsigned, \
|
t3 tinyint, t4 tinyint, t5 smallint, t6 int, t7 bigint, t8 tinyint unsigned, t9 smallint unsigned, \
|
||||||
t10 int unsigned, t11 bigint unsigned, t12 float, t13 double, t14 binary(100), t15 nchar(100), t16 timestamp)")
|
t10 int unsigned, t11 bigint unsigned, t12 float, t13 double, t14 binary(100), t15 nchar(100), t16 timestamp)")
|
||||||
|
|
||||||
stmt = conn.statement("insert into ? using log tags (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) \
|
stmt = conn.statement("insert into ? using log tags (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) \
|
||||||
values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
|
values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
|
||||||
tags = new_bind_params(16)
|
tags = new_bind_params(16)
|
||||||
tags[0].timestamp(1626861392589123, PrecisionEnum.Microseconds)
|
tags[0].timestamp(1626861392589123, PrecisionEnum.Microseconds)
|
||||||
tags[1].bool(True)
|
tags[1].bool(True)
|
||||||
tags[2].null()
|
tags[2].bool(False)
|
||||||
tags[3].tinyint(2)
|
tags[3].tinyint(2)
|
||||||
tags[4].smallint(3)
|
tags[4].smallint(3)
|
||||||
tags[5].int(4)
|
tags[5].int(4)
|
||||||
|
@ -198,7 +114,7 @@ class TDTestCase:
|
||||||
tags[14].nchar("stmt")
|
tags[14].nchar("stmt")
|
||||||
tags[15].timestamp(1626861392589, PrecisionEnum.Milliseconds)
|
tags[15].timestamp(1626861392589, PrecisionEnum.Milliseconds)
|
||||||
stmt.set_tbname_tags("tb1", tags)
|
stmt.set_tbname_tags("tb1", tags)
|
||||||
params = new_multi_binds(16)
|
params = new_multi_binds(17)
|
||||||
params[0].timestamp((1626861392589111, 1626861392590111, 1626861392591111))
|
params[0].timestamp((1626861392589111, 1626861392590111, 1626861392591111))
|
||||||
params[1].bool((True, None, False))
|
params[1].bool((True, None, False))
|
||||||
params[2].tinyint([-128, -128, None]) # -128 is tinyint null
|
params[2].tinyint([-128, -128, None]) # -128 is tinyint null
|
||||||
|
@ -213,25 +129,32 @@ class TDTestCase:
|
||||||
params[11].float([3, None, 1])
|
params[11].float([3, None, 1])
|
||||||
params[12].double([3, None, 1.2])
|
params[12].double([3, None, 1.2])
|
||||||
params[13].binary(["abc", "dddafadfadfadfadfa", None])
|
params[13].binary(["abc", "dddafadfadfadfadfa", None])
|
||||||
params[14].nchar(["涛思数据", None, "a? long string with 中文字符"])
|
params[14].nchar(["涛思数据", None, "a long string with 中文字符"])
|
||||||
params[15].timestamp([None, None, 1626861392591])
|
params[15].timestamp([None, None, 1626861392591])
|
||||||
|
params[16].binary(["涛思数据16", None, "a long string with 中文-字符"])
|
||||||
|
|
||||||
stmt.bind_param_batch(params)
|
stmt.bind_param_batch(params)
|
||||||
stmt.execute()
|
stmt.execute()
|
||||||
|
|
||||||
assert stmt.affected_rows == 3
|
assert stmt.affected_rows == 3
|
||||||
|
|
||||||
#query
|
#query all
|
||||||
querystmt1=conn.statement("select * from log where bu < ?")
|
querystmt1=conn.statement("select * from log where bu < ?")
|
||||||
queryparam1=new_bind_params(1)
|
queryparam1=new_bind_params(1)
|
||||||
print(type(queryparam1))
|
print(type(queryparam1))
|
||||||
queryparam1[0].int(5)
|
queryparam1[0].int(10)
|
||||||
querystmt1.bind_param(queryparam1)
|
querystmt1.bind_param(queryparam1)
|
||||||
querystmt1.execute()
|
querystmt1.execute()
|
||||||
result1=querystmt1.use_result()
|
result1=querystmt1.use_result()
|
||||||
rows1=result1.fetch_all()
|
rows1=result1.fetch_all()
|
||||||
print("1",rows1)
|
print(rows1[0])
|
||||||
|
print(rows1[1])
|
||||||
|
print(rows1[2])
|
||||||
|
assert str(rows1[0][0]) == "2021-07-21 17:56:32.589111"
|
||||||
|
assert rows1[0][10] == 3
|
||||||
|
assert rows1[1][10] == 4
|
||||||
|
|
||||||
|
#query: Numeric Functions
|
||||||
querystmt2=conn.statement("select abs(?) from log where bu < ?")
|
querystmt2=conn.statement("select abs(?) from log where bu < ?")
|
||||||
queryparam2=new_bind_params(2)
|
queryparam2=new_bind_params(2)
|
||||||
print(type(queryparam2))
|
print(type(queryparam2))
|
||||||
|
@ -242,6 +165,11 @@ class TDTestCase:
|
||||||
result2=querystmt2.use_result()
|
result2=querystmt2.use_result()
|
||||||
rows2=result2.fetch_all()
|
rows2=result2.fetch_all()
|
||||||
print("2",rows2)
|
print("2",rows2)
|
||||||
|
assert rows2[0][0] == 5
|
||||||
|
assert rows2[1][0] == 5
|
||||||
|
|
||||||
|
|
||||||
|
#query: Numeric Functions and escapes
|
||||||
|
|
||||||
querystmt3=conn.statement("select abs(?) from log where nn= 'a? long string with 中文字符' ")
|
querystmt3=conn.statement("select abs(?) from log where nn= 'a? long string with 中文字符' ")
|
||||||
queryparam3=new_bind_params(1)
|
queryparam3=new_bind_params(1)
|
||||||
|
@ -252,9 +180,63 @@ class TDTestCase:
|
||||||
result3=querystmt3.use_result()
|
result3=querystmt3.use_result()
|
||||||
rows3=result3.fetch_all()
|
rows3=result3.fetch_all()
|
||||||
print("3",rows3)
|
print("3",rows3)
|
||||||
# assert str(rows1[0][0]) == "2021-07-21 17:56:32.589111"
|
assert rows3 == []
|
||||||
# assert rows1[0][10] == 3
|
|
||||||
# assert rows1[1][10] == 4
|
#query: string Functions
|
||||||
|
|
||||||
|
querystmt3=conn.statement("select CHAR_LENGTH(?) from log ")
|
||||||
|
queryparam3=new_bind_params(1)
|
||||||
|
print(type(queryparam3))
|
||||||
|
queryparam3[0].binary('中文字符')
|
||||||
|
querystmt3.bind_param(queryparam3)
|
||||||
|
querystmt3.execute()
|
||||||
|
result3=querystmt3.use_result()
|
||||||
|
rows3=result3.fetch_all()
|
||||||
|
print("4",rows3)
|
||||||
|
assert rows3[0][0] == 12, 'fourth case is failed'
|
||||||
|
assert rows3[1][0] == 12, 'fourth case is failed'
|
||||||
|
|
||||||
|
# #query: conversion Functions
|
||||||
|
|
||||||
|
# querystmt4=conn.statement("select cast( ? as bigint) from log ")
|
||||||
|
# queryparam4=new_bind_params(1)
|
||||||
|
# print(type(queryparam4))
|
||||||
|
# queryparam4[0].binary('1232a')
|
||||||
|
# querystmt4.bind_param(queryparam4)
|
||||||
|
# querystmt4.execute()
|
||||||
|
# result4=querystmt4.use_result()
|
||||||
|
# rows4=result4.fetch_all()
|
||||||
|
# print("5",rows4)
|
||||||
|
# assert rows4[0][0] == 1232
|
||||||
|
# assert rows4[1][0] == 1232
|
||||||
|
|
||||||
|
# querystmt4=conn.statement("select cast( ? as binary(10)) from log ")
|
||||||
|
# queryparam4=new_bind_params(1)
|
||||||
|
# print(type(queryparam4))
|
||||||
|
# queryparam4[0].int(123)
|
||||||
|
# querystmt4.bind_param(queryparam4)
|
||||||
|
# querystmt4.execute()
|
||||||
|
# result4=querystmt4.use_result()
|
||||||
|
# rows4=result4.fetch_all()
|
||||||
|
# print("6",rows4)
|
||||||
|
# assert rows4[0][0] == '123'
|
||||||
|
# assert rows4[1][0] == '123'
|
||||||
|
|
||||||
|
# #query: datatime Functions
|
||||||
|
|
||||||
|
# querystmt4=conn.statement(" select timediff('2021-07-21 17:56:32.590111',?,1s) from log ")
|
||||||
|
# queryparam4=new_bind_params(1)
|
||||||
|
# print(type(queryparam4))
|
||||||
|
# queryparam4[0].timestamp(1626861392591111)
|
||||||
|
# querystmt4.bind_param(queryparam4)
|
||||||
|
# querystmt4.execute()
|
||||||
|
# result4=querystmt4.use_result()
|
||||||
|
# rows4=result4.fetch_all()
|
||||||
|
# print("7",rows4)
|
||||||
|
# assert rows4[0][0] == 1, 'seventh case is failed'
|
||||||
|
# assert rows4[1][0] == 1, 'seventh case is failed'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# conn.execute("drop database if exists %s" % dbname)
|
# conn.execute("drop database if exists %s" % dbname)
|
||||||
conn.close()
|
conn.close()
|
||||||
|
@ -269,8 +251,6 @@ class TDTestCase:
|
||||||
config = buildPath+ "../sim/dnode1/cfg/"
|
config = buildPath+ "../sim/dnode1/cfg/"
|
||||||
host="localhost"
|
host="localhost"
|
||||||
connectstmt=self.newcon(host,config)
|
connectstmt=self.newcon(host,config)
|
||||||
self.test_stmt_insert_multi(connectstmt)
|
|
||||||
connectstmt=self.newcon(host,config)
|
|
||||||
self.test_stmt_set_tbname_tag(connectstmt)
|
self.test_stmt_set_tbname_tag(connectstmt)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -124,7 +124,7 @@ class TDTestCase:
|
||||||
print("elapsed time: ", end - start)
|
print("elapsed time: ", end - start)
|
||||||
assert stmt.affected_rows == 3
|
assert stmt.affected_rows == 3
|
||||||
|
|
||||||
#query
|
#query 1
|
||||||
querystmt=conn.statement("select ?,bu from log")
|
querystmt=conn.statement("select ?,bu from log")
|
||||||
queryparam=new_bind_params(1)
|
queryparam=new_bind_params(1)
|
||||||
print(type(queryparam))
|
print(type(queryparam))
|
||||||
|
@ -141,8 +141,9 @@ class TDTestCase:
|
||||||
print(rows)
|
print(rows)
|
||||||
assert rows[1][0] == "ts"
|
assert rows[1][0] == "ts"
|
||||||
assert rows[0][1] == 3
|
assert rows[0][1] == 3
|
||||||
|
assert rows[2][1] == None
|
||||||
|
|
||||||
#query
|
#query 2
|
||||||
querystmt1=conn.statement("select * from log where bu < ?")
|
querystmt1=conn.statement("select * from log where bu < ?")
|
||||||
queryparam1=new_bind_params(1)
|
queryparam1=new_bind_params(1)
|
||||||
print(type(queryparam1))
|
print(type(queryparam1))
|
||||||
|
|
|
@ -82,7 +82,7 @@ class TDTestCase:
|
||||||
return con
|
return con
|
||||||
|
|
||||||
def test_stmt_set_tbname_tag(self,conn):
|
def test_stmt_set_tbname_tag(self,conn):
|
||||||
dbname = "pytest_taos_stmt_set_tbname_tag"
|
dbname = "stmt_set_tbname_tag"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
conn.execute("drop database if exists %s" % dbname)
|
conn.execute("drop database if exists %s" % dbname)
|
||||||
|
@ -99,7 +99,7 @@ class TDTestCase:
|
||||||
tags = new_bind_params(16)
|
tags = new_bind_params(16)
|
||||||
tags[0].timestamp(1626861392589123, PrecisionEnum.Microseconds)
|
tags[0].timestamp(1626861392589123, PrecisionEnum.Microseconds)
|
||||||
tags[1].bool(True)
|
tags[1].bool(True)
|
||||||
tags[2].null()
|
tags[2].bool(False)
|
||||||
tags[3].tinyint(2)
|
tags[3].tinyint(2)
|
||||||
tags[4].smallint(3)
|
tags[4].smallint(3)
|
||||||
tags[5].int(4)
|
tags[5].int(4)
|
||||||
|
@ -114,7 +114,7 @@ class TDTestCase:
|
||||||
tags[14].nchar("stmt")
|
tags[14].nchar("stmt")
|
||||||
tags[15].timestamp(1626861392589, PrecisionEnum.Milliseconds)
|
tags[15].timestamp(1626861392589, PrecisionEnum.Milliseconds)
|
||||||
stmt.set_tbname_tags("tb1", tags)
|
stmt.set_tbname_tags("tb1", tags)
|
||||||
params = new_multi_binds(16)
|
params = new_multi_binds(17)
|
||||||
params[0].timestamp((1626861392589111, 1626861392590111, 1626861392591111))
|
params[0].timestamp((1626861392589111, 1626861392590111, 1626861392591111))
|
||||||
params[1].bool((True, None, False))
|
params[1].bool((True, None, False))
|
||||||
params[2].tinyint([-128, -128, None]) # -128 is tinyint null
|
params[2].tinyint([-128, -128, None]) # -128 is tinyint null
|
||||||
|
@ -129,28 +129,153 @@ class TDTestCase:
|
||||||
params[11].float([3, None, 1])
|
params[11].float([3, None, 1])
|
||||||
params[12].double([3, None, 1.2])
|
params[12].double([3, None, 1.2])
|
||||||
params[13].binary(["abc", "dddafadfadfadfadfa", None])
|
params[13].binary(["abc", "dddafadfadfadfadfa", None])
|
||||||
params[14].nchar(["涛思数据", None, "a long string with 中文字符"])
|
params[14].nchar(["涛思数据", None, "a long string with 中文?字符"])
|
||||||
params[15].timestamp([None, None, 1626861392591])
|
params[15].timestamp([None, None, 1626861392591])
|
||||||
params[16].binary(["涛思数据16", None, "a long string with 中文-字符"])
|
params[16].binary(["涛思数据16", None, None])
|
||||||
|
|
||||||
stmt.bind_param_batch(params)
|
stmt.bind_param_batch(params)
|
||||||
stmt.execute()
|
stmt.execute()
|
||||||
|
|
||||||
assert stmt.affected_rows == 3
|
assert stmt.affected_rows == 3
|
||||||
|
|
||||||
#query
|
#query all
|
||||||
querystmt1=conn.statement("select * from log where bu < ?")
|
querystmt1=conn.statement("select * from log where bu < ?")
|
||||||
queryparam1=new_bind_params(1)
|
queryparam1=new_bind_params(1)
|
||||||
print(type(queryparam1))
|
print(type(queryparam1))
|
||||||
queryparam1[0].int(5)
|
queryparam1[0].int(10)
|
||||||
querystmt1.bind_param(queryparam1)
|
querystmt1.bind_param(queryparam1)
|
||||||
querystmt1.execute()
|
querystmt1.execute()
|
||||||
result1=querystmt1.use_result()
|
result1=querystmt1.use_result()
|
||||||
rows1=result1.fetch_all()
|
rows1=result1.fetch_all()
|
||||||
print(rows1)
|
print(rows1[0])
|
||||||
# assert str(rows1[0][0]) == "2021-07-21 17:56:32.589111"
|
print(rows1[1])
|
||||||
# assert rows1[0][10] == 3
|
print(rows1[2])
|
||||||
# assert rows1[1][10] == 4
|
assert str(rows1[0][0]) == "2021-07-21 17:56:32.589111"
|
||||||
|
assert rows1[0][10] == 3
|
||||||
|
assert rows1[1][10] == 4
|
||||||
|
|
||||||
|
#query: Numeric Functions
|
||||||
|
querystmt2=conn.statement("select abs(?) from log where bu < ?")
|
||||||
|
queryparam2=new_bind_params(2)
|
||||||
|
print(type(queryparam2))
|
||||||
|
queryparam2[0].int(5)
|
||||||
|
queryparam2[1].int(5)
|
||||||
|
querystmt2.bind_param(queryparam2)
|
||||||
|
querystmt2.execute()
|
||||||
|
result2=querystmt2.use_result()
|
||||||
|
rows2=result2.fetch_all()
|
||||||
|
print("2",rows2)
|
||||||
|
assert rows2[0][0] == 5
|
||||||
|
assert rows2[1][0] == 5
|
||||||
|
|
||||||
|
|
||||||
|
#query: Numeric Functions and escapes
|
||||||
|
|
||||||
|
querystmt3=conn.statement("select abs(?) from log where nn= 'a? long string with 中文字符' ")
|
||||||
|
queryparam3=new_bind_params(1)
|
||||||
|
print(type(queryparam3))
|
||||||
|
queryparam3[0].int(5)
|
||||||
|
querystmt3.bind_param(queryparam3)
|
||||||
|
querystmt3.execute()
|
||||||
|
result3=querystmt3.use_result()
|
||||||
|
rows3=result3.fetch_all()
|
||||||
|
print("3",rows3)
|
||||||
|
assert rows3 == []
|
||||||
|
|
||||||
|
# #query: string Functions
|
||||||
|
|
||||||
|
# querystmt3=conn.statement("select CHAR_LENGTH(?) from log ")
|
||||||
|
# queryparam3=new_bind_params(1)
|
||||||
|
# print(type(queryparam3))
|
||||||
|
# queryparam3[0].binary('中文字符')
|
||||||
|
# querystmt3.bind_param(queryparam3)
|
||||||
|
# querystmt3.execute()
|
||||||
|
# result3=querystmt3.use_result()
|
||||||
|
# rows3=result3.fetch_all()
|
||||||
|
# print("4",rows3)
|
||||||
|
# assert rows3[0][0] == 12, 'fourth case is failed'
|
||||||
|
# assert rows3[1][0] == 12, 'fourth case is failed'
|
||||||
|
|
||||||
|
# #query: conversion Functions
|
||||||
|
|
||||||
|
# querystmt4=conn.statement("select cast( ? as bigint) from log ")
|
||||||
|
# queryparam4=new_bind_params(1)
|
||||||
|
# print(type(queryparam4))
|
||||||
|
# queryparam4[0].binary('1232a')
|
||||||
|
# querystmt4.bind_param(queryparam4)
|
||||||
|
# querystmt4.execute()
|
||||||
|
# result4=querystmt4.use_result()
|
||||||
|
# rows4=result4.fetch_all()
|
||||||
|
# print("5",rows4)
|
||||||
|
# assert rows4[0][0] == 1232
|
||||||
|
# assert rows4[1][0] == 1232
|
||||||
|
|
||||||
|
# querystmt4=conn.statement("select cast( ? as binary(10)) from log ")
|
||||||
|
# queryparam4=new_bind_params(1)
|
||||||
|
# print(type(queryparam4))
|
||||||
|
# queryparam4[0].int(123)
|
||||||
|
# querystmt4.bind_param(queryparam4)
|
||||||
|
# querystmt4.execute()
|
||||||
|
# result4=querystmt4.use_result()
|
||||||
|
# rows4=result4.fetch_all()
|
||||||
|
# print("6",rows4)
|
||||||
|
# assert rows4[0][0] == '123'
|
||||||
|
# assert rows4[1][0] == '123'
|
||||||
|
|
||||||
|
# #query: datatime Functions
|
||||||
|
|
||||||
|
# querystmt4=conn.statement(" select timediff('2021-07-21 17:56:32.590111',?,1s) from log ")
|
||||||
|
# queryparam4=new_bind_params(1)
|
||||||
|
# print(type(queryparam4))
|
||||||
|
# queryparam4[0].timestamp(1626861392591111)
|
||||||
|
# querystmt4.bind_param(queryparam4)
|
||||||
|
# querystmt4.execute()
|
||||||
|
# result4=querystmt4.use_result()
|
||||||
|
# rows4=result4.fetch_all()
|
||||||
|
# print("7",rows4)
|
||||||
|
# assert rows4[0][0] == 1, 'seventh case is failed'
|
||||||
|
# assert rows4[1][0] == 1, 'seventh case is failed'
|
||||||
|
|
||||||
|
#query: aggregate Functions
|
||||||
|
|
||||||
|
querystmt4=conn.statement(" select count(?) from log ")
|
||||||
|
queryparam4=new_bind_params(1)
|
||||||
|
print(type(queryparam4))
|
||||||
|
queryparam4[0].int(123)
|
||||||
|
querystmt4.bind_param(queryparam4)
|
||||||
|
querystmt4.execute()
|
||||||
|
result4=querystmt4.use_result()
|
||||||
|
rows4=result4.fetch_all()
|
||||||
|
print("8",rows4)
|
||||||
|
assert rows4[0][0] == 3, ' 8 case is failed'
|
||||||
|
|
||||||
|
#query: selector Functions 9
|
||||||
|
|
||||||
|
querystmt4=conn.statement(" select bottom(bu,?) from log group by bu ; ")
|
||||||
|
queryparam4=new_bind_params(1)
|
||||||
|
print(type(queryparam4))
|
||||||
|
queryparam4[0].int(2)
|
||||||
|
querystmt4.bind_param(queryparam4)
|
||||||
|
querystmt4.execute()
|
||||||
|
result4=querystmt4.use_result()
|
||||||
|
rows4=result4.fetch_all()
|
||||||
|
print("9",rows4)
|
||||||
|
assert rows4[0][0] == 4, ' 9 case is failed'
|
||||||
|
assert rows4[1][0] == 3, ' 9 case is failed'
|
||||||
|
|
||||||
|
# #query: time-series specific Functions 10
|
||||||
|
|
||||||
|
querystmt4=conn.statement(" select twa(?) from log; ")
|
||||||
|
queryparam4=new_bind_params(1)
|
||||||
|
print(type(queryparam4))
|
||||||
|
queryparam4[0].int(15)
|
||||||
|
querystmt4.bind_param(queryparam4)
|
||||||
|
querystmt4.execute()
|
||||||
|
result4=querystmt4.use_result()
|
||||||
|
rows4=result4.fetch_all()
|
||||||
|
print("10",rows4)
|
||||||
|
assert rows4[0][0] == 15, ' 10 case is failed'
|
||||||
|
|
||||||
|
|
||||||
# conn.execute("drop database if exists %s" % dbname)
|
# conn.execute("drop database if exists %s" % dbname)
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
Loading…
Reference in New Issue