Skip to content

Commit

Permalink
Merge pull request #274 from taosdata/fix/td-32561
Browse files Browse the repository at this point in the history
fix: bind_param method adds type check for the iterated type of tbnames
  • Loading branch information
YamingPei authored Oct 18, 2024
2 parents a7680ee + 7150171 commit 7076ab1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
5 changes: 4 additions & 1 deletion taos/statement2.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, reqid: int=None, single_stb_insert: bool=False, single_table_
reqid = utils.gen_req_id()
else:
if type(reqid) is not int:
raise StatementError(f"reqid type error, expected int type but get {type(reqid)}.")
raise StatementError(f"reqid type error, expected int type but got {type(reqid)}.")

self.reqid = reqid
self.single_stb_insert = single_stb_insert
Expand Down Expand Up @@ -186,6 +186,9 @@ def createBindV(statement2, tbnames, tags, datas):
raise StatementError("params tbnames some is None, some is not None, this is error.")
else:
# not found none
if type(tbnames) not in [list, tuple]:
raise StatementError(f"tbnames type error, expected list or tuple type but got {type(tbnames)}.")

bindNames = tbnames
count = len(tbnames)

Expand Down
34 changes: 34 additions & 0 deletions tests/test_stmt2.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,40 @@ def test_stmt2_prepare_empty_sql(conn):
conn.close()


def test_bind_invalid_tbnames_type():
if not IS_V3:
print(" test_bind_invalid_tbnames_type not support TDengine 2.X version.")
return

dbname = "stmt2"
stbname = "stmt2_stable"
subtbname = "stmt2_subtable"

try:
conn = taos.connect()
conn.execute(f"drop database if exists {dbname}")
conn.execute(f"create database {dbname}")
conn.select_db(dbname)
conn.execute(f"create stable {stbname} (ts timestamp, a int) tags (b int);")
conn.execute(f"create table {subtbname} using {stbname} tags(0);")

stmt2 = conn.statement2(f"insert into ? using {dbname}.{stbname} tags(?) values(?,?)")

tags = [[1]]
datas = [[[1626861392589], [1]]]

stmt2.bind_param(subtbname, tags, datas)

# should not run here
conn.close()
print("bind invalid tbnames type ..................... failed\n")
assert False

except StatementError as err:
print("bind invalid tbnames type ..................... ok\n")
conn.close()


#
# insert
#
Expand Down

0 comments on commit 7076ab1

Please sign in to comment.