From c33a13f2a8e4934b936730bf1bc45b370b971212 Mon Sep 17 00:00:00 2001 From: "cris.pei" Date: Wed, 9 Oct 2024 14:40:11 +0800 Subject: [PATCH] fix: no need to get meta info when tbname not bind --- taos/cinterface.py | 2 -- taos/statement2.py | 10 ++++++---- tests/test_stmt2.py | 34 +++++++++++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/taos/cinterface.py b/taos/cinterface.py index 0727bd39..6d65e56c 100644 --- a/taos/cinterface.py +++ b/taos/cinterface.py @@ -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) diff --git a/taos/statement2.py b/taos/statement2.py index f939fa1a..b1dbd4c1 100644 --- a/taos/statement2.py +++ b/taos/statement2.py @@ -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}") diff --git a/tests/test_stmt2.py b/tests/test_stmt2.py index f3b1dfbe..0157bd36 100644 --- a/tests/test_stmt2.py +++ b/tests/test_stmt2.py @@ -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): @@ -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): @@ -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: @@ -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