diff --git a/src/connector/python/taos/bind.py b/src/connector/python/taos/bind.py index 083ddc99aea8dc6f39b1f22ac5f77d2584a2fe69..05659714ef86da3bda383bfe7d7b25403848637f 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 5d21ff95af5d81367e7143d001cc688d90877b67..a8d82bea2ea188f8a08d6603dd33735ea0a0a5af 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