Skip to content

Commit

Permalink
Merge pull request #267 from taosdata/fix/td-32456
Browse files Browse the repository at this point in the history
fix: no need to get meta info when tbname not bind
  • Loading branch information
DuanKuanJun authored Oct 10, 2024
2 parents b4ee650 + c33a13f commit aa49565
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
2 changes: 0 additions & 2 deletions taos/cinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -1169,8 +1169,6 @@ def taos_stmt2_exec(stmt):
_check_if_supported()
affected_rows = ctypes.c_int(0)
res = _libtaos.taos_stmt2_exec(stmt, ctypes.byref(affected_rows))

# 检查执行结果
if res != 0:
error_msg = taos_stmt2_error(stmt)
raise StatementError(msg=error_msg, errno=res)
Expand Down
10 changes: 6 additions & 4 deletions taos/statement2.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,12 @@ def bind_param(self, tbnames, tags, datas):

# obtain schema if insert
if self.is_insert():
bindv = createBindV(self, tbnames, None, None)
if bindv == None:
raise StatementError("create stmt2 bindV failed.")
taos_stmt2_bind_param(self._stmt2, bindv.get_address(), -1)
if tbnames is not None:
bindv = createBindV(self, tbnames, None, None)
if bindv == None:
raise StatementError("create stmt2 bindV failed.")
taos_stmt2_bind_param(self._stmt2, bindv.get_address(), -1)

if obtainSchema(self) is False:
raise StatementError(f"obtain schema failed. tbnames={tbnames}")

Expand Down
34 changes: 33 additions & 1 deletion tests/test_stmt2.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ def prepare(conn, dbname, stbname):
# normal table
sql = f"create table if not exists {dbname}.ntb (ts timestamp, name varbinary(32), sex bool, score float, geo geometry(128))"
conn.execute(sql)
sql = f"create table if not exists {dbname}.ntb2 (ts timestamp, name varbinary(32), sex bool, score float, geo geometry(128))"
conn.execute(sql)


# performace is high
def insert_bind_param(conn, stmt2, dbname, stbname):
Expand Down Expand Up @@ -156,6 +159,27 @@ def insert_bind_param(conn, stmt2, dbname, stbname):
checkResultCorrects(conn, dbname, stbname, tbanmes, tags, datas)


def insert_bind_param_normal_tables(conn, stmt2, dbname):
tbnames = None
tags = None
datas = [
# table 1
[
# student
[1601481600000,1601481600004,"2024-09-19 10:00:00", "2024-09-19 10:00:01.123", datetime(2024,9,20,10,11,12,456)],
[b"Mary", b"tom", b"Jack", b"Jane", None ],
[0, 3.14, True, 0, 1 ],
[98, 99.87, 60, 100, 99 ],
[None, b"POINT(121.213 31.234)", b"POINT(122.22 32.222)", None, b"POINT(124.22 34.222)"]
]
]

stmt2.bind_param(tbnames, tags, datas)
stmt2.execute()

# check correct
checkResultCorrects(conn, dbname, None, ["ntb2"], [None], datas)


# insert with single table (performance is lower)
def insert_bind_param_with_tables(conn, stmt2, dbname, stbname):
Expand Down Expand Up @@ -320,6 +344,12 @@ def test_stmt2_insert(conn):

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

stmt2 = conn.statement2(f"insert into {dbname}.ntb2 values(?,?,?,?,?)")
insert_bind_param_normal_tables(conn, stmt2, dbname)
print("insert bind param normal tables ............... ok\n")
stmt2.close()

conn.close()
print("test_stmt2_insert ............................. [passed]\n")
except Exception as err:
Expand Down Expand Up @@ -445,9 +475,11 @@ def test_stmt2_query(conn):

if __name__ == "__main__":
print("start stmt2 test case...\n")


taos.log.setting(True, True, True, True, True, False)

# insert
# insert
test_stmt2_insert(taos.connect())

# query
Expand Down

0 comments on commit aa49565

Please sign in to comment.