From 36e26330f530ab97d1889f59c99eadc102e87894 Mon Sep 17 00:00:00 2001 From: liu0x54 Date: Fri, 8 May 2020 11:24:39 +0000 Subject: [PATCH] [TD251]fix python connector to process NCHAR --- src/connector/python/linux/python2/taos/cinterface.py | 3 ++- src/connector/python/linux/python3/taos/cinterface.py | 3 ++- src/connector/python/windows/python2/taos/cinterface.py | 3 ++- src/connector/python/windows/python3/taos/cinterface.py | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/connector/python/linux/python2/taos/cinterface.py b/src/connector/python/linux/python2/taos/cinterface.py index 6d792fa92f..98a2103c09 100644 --- a/src/connector/python/linux/python2/taos/cinterface.py +++ b/src/connector/python/linux/python2/taos/cinterface.py @@ -96,7 +96,8 @@ def _crow_nchar_to_python(data, num_of_rows, nbytes=None, micro=False): for i in range(abs(num_of_rows)): try: if num_of_rows >= 0: - res.append( (ctypes.cast(data+nbytes*(abs(num_of_rows - i -1)), ctypes.POINTER(ctypes.c_char * (nbytes//4))))[0].value ) + tmpstr = ctypes.c_char_p(data) + res.append( tmpstr.value.decode() ) else: res.append( (ctypes.cast(data+nbytes*i, ctypes.POINTER(ctypes.c_wchar * (nbytes//4))))[0].value ) except ValueError: diff --git a/src/connector/python/linux/python3/taos/cinterface.py b/src/connector/python/linux/python3/taos/cinterface.py index 49dd5d00e3..d516aad5a7 100644 --- a/src/connector/python/linux/python3/taos/cinterface.py +++ b/src/connector/python/linux/python3/taos/cinterface.py @@ -96,7 +96,8 @@ def _crow_nchar_to_python(data, num_of_rows, nbytes=None, micro=False): for i in range(abs(num_of_rows)): try: if num_of_rows >= 0: - res.append( (ctypes.cast(data+nbytes*(abs(num_of_rows - i -1)), ctypes.POINTER(ctypes.c_char * (nbytes//4))))[0].value ) + tmpstr = ctypes.c_char_p(data) + res.append( tmpstr.value.decode() ) else: res.append( (ctypes.cast(data+nbytes*i, ctypes.POINTER(ctypes.c_wchar * (nbytes//4))))[0].value ) except ValueError: diff --git a/src/connector/python/windows/python2/taos/cinterface.py b/src/connector/python/windows/python2/taos/cinterface.py index a62ac2801c..28130d5cb3 100644 --- a/src/connector/python/windows/python2/taos/cinterface.py +++ b/src/connector/python/windows/python2/taos/cinterface.py @@ -96,7 +96,8 @@ def _crow_nchar_to_python(data, num_of_rows, nbytes=None, micro=False): for i in range(abs(num_of_rows)): try: if num_of_rows >= 0: - res.append( (ctypes.cast(data+nbytes*(abs(num_of_rows - i -1)), ctypes.POINTER(ctypes.c_char * (nbytes//4))))[0].value ) + tmpstr = ctypes.c_char_p(data) + res.append( tmpstr.value.decode() ) else: res.append( (ctypes.cast(data+nbytes*i, ctypes.POINTER(ctypes.c_wchar * (nbytes//4))))[0].value ) except ValueError: diff --git a/src/connector/python/windows/python3/taos/cinterface.py b/src/connector/python/windows/python3/taos/cinterface.py index 4d009f0be0..f683537661 100644 --- a/src/connector/python/windows/python3/taos/cinterface.py +++ b/src/connector/python/windows/python3/taos/cinterface.py @@ -96,7 +96,8 @@ def _crow_nchar_to_python(data, num_of_rows, nbytes=None, micro=False): for i in range(abs(num_of_rows)): try: if num_of_rows >= 0: - res.append( (ctypes.cast(data+nbytes*(abs(num_of_rows - i -1)), ctypes.POINTER(ctypes.c_char * (nbytes//4))))[0].value ) + tmpstr = ctypes.c_char_p(data) + res.append( tmpstr.value.decode() ) else: res.append( (ctypes.cast(data+nbytes*i, ctypes.POINTER(ctypes.c_wchar * (nbytes//4))))[0].value ) except ValueError: -- GitLab