From 566717092f6ca221e991ef712b7dd521ee1a70d9 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Wed, 22 Sep 2021 10:39:44 +0800 Subject: [PATCH] TD-6129 add python test case --- src/connector/python/taos/bind.py | 20 ++++++++++++++++++++ src/connector/python/taos/cursor.py | 3 +++ 2 files changed, 23 insertions(+) diff --git a/src/connector/python/taos/bind.py b/src/connector/python/taos/bind.py index 083ddc99ae..05659714ef 100644 --- a/src/connector/python/taos/bind.py +++ b/src/connector/python/taos/bind.py @@ -124,6 +124,21 @@ class TaosBind(ctypes.Structure): self.buffer_length = length self.length = pointer(c_size_t(self.buffer_length)) + def json(self, value): + buffer = None + length = 0 + if isinstance(value, str): + bytes = value.encode("utf-8") + buffer = create_string_buffer(bytes) + length = len(bytes) + else: + buffer = value + length = len(value) + self.buffer_type = FieldType.C_JSON + self.buffer = cast(buffer, c_void_p) + self.buffer_length = length + self.length = pointer(c_size_t(self.buffer_length)) + def tinyint_unsigned(self, value): self.buffer_type = FieldType.C_TINYINT_UNSIGNED self.buffer = cast(pointer(c_uint8(value)), c_void_p) @@ -356,6 +371,11 @@ class TaosMultiBind(ctypes.Structure): self.buffer_type = FieldType.C_NCHAR self._str_to_buffer(values) + def json(self, values): + # type: (list[str]) -> None + self.buffer_type = FieldType.C_JSON + self._str_to_buffer(values) + def tinyint_unsigned(self, values): self.buffer_type = FieldType.C_TINYINT_UNSIGNED self.buffer_length = sizeof(c_uint8) diff --git a/src/connector/python/taos/cursor.py b/src/connector/python/taos/cursor.py index 5d21ff95af..a8d82bea2e 100644 --- a/src/connector/python/taos/cursor.py +++ b/src/connector/python/taos/cursor.py @@ -188,6 +188,9 @@ class TaosCursor(object): if dataType.upper() == "NCHAR": if self._description[col][1] == FieldType.C_NCHAR: return True + if dataType.upper() == "JSON": + if self._description[col][1] == FieldType.C_JSON: + return True return False -- GitLab