cinterface.py 19.4 KB
Newer Older
S
slguan 已提交
1 2 3 4 5 6
import ctypes
from .constants import FieldType
from .error import *
import math
import datetime

7

S
slguan 已提交
8
def _convert_millisecond_to_datetime(milli):
9 10
    return datetime.datetime.fromtimestamp(milli / 1000.0)

S
slguan 已提交
11 12

def _convert_microsecond_to_datetime(micro):
13 14
    return datetime.datetime.fromtimestamp(micro / 1000000.0)

S
slguan 已提交
15 16 17 18

def _crow_timestamp_to_python(data, num_of_rows, nbytes=None, micro=False):
    """Function to convert C bool row to python row
    """
weixin_48148422's avatar
weixin_48148422 已提交
19
    _timestamp_converter = _convert_millisecond_to_datetime
S
slguan 已提交
20
    if micro:
weixin_48148422's avatar
weixin_48148422 已提交
21
        _timestamp_converter = _convert_microsecond_to_datetime
S
slguan 已提交
22 23

    if num_of_rows > 0:
24 25
        return list(map(_timestamp_converter, ctypes.cast(
            data, ctypes.POINTER(ctypes.c_longlong))[:abs(num_of_rows)]))
S
slguan 已提交
26
    else:
27 28 29
        return list(map(_timestamp_converter, ctypes.cast(
            data, ctypes.POINTER(ctypes.c_longlong))[:abs(num_of_rows)]))

S
slguan 已提交
30 31 32 33 34

def _crow_bool_to_python(data, num_of_rows, nbytes=None, micro=False):
    """Function to convert C bool row to python row
    """
    if num_of_rows > 0:
35 36 37 38 39
        return [
            None if ele == FieldType.C_BOOL_NULL else bool(ele) for ele in ctypes.cast(
                data, ctypes.POINTER(
                    ctypes.c_byte))[
                :abs(num_of_rows)]]
S
slguan 已提交
40
    else:
41 42 43 44 45 46
        return [
            None if ele == FieldType.C_BOOL_NULL else bool(ele) for ele in ctypes.cast(
                data, ctypes.POINTER(
                    ctypes.c_bool))[
                :abs(num_of_rows)]]

S
slguan 已提交
47 48 49 50 51

def _crow_tinyint_to_python(data, num_of_rows, nbytes=None, micro=False):
    """Function to convert C tinyint row to python row
    """
    if num_of_rows > 0:
52 53
        return [None if ele == FieldType.C_TINYINT_NULL else ele for ele in ctypes.cast(
            data, ctypes.POINTER(ctypes.c_byte))[:abs(num_of_rows)]]
S
slguan 已提交
54
    else:
55 56 57 58
        return [None if ele == FieldType.C_TINYINT_NULL else ele for ele in ctypes.cast(
            data, ctypes.POINTER(ctypes.c_byte))[:abs(num_of_rows)]]


S
slguan 已提交
59 60 61 62
def _crow_smallint_to_python(data, num_of_rows, nbytes=None, micro=False):
    """Function to convert C smallint row to python row
    """
    if num_of_rows > 0:
63 64 65 66 67
        return [
            None if ele == FieldType.C_SMALLINT_NULL else ele for ele in ctypes.cast(
                data, ctypes.POINTER(
                    ctypes.c_short))[
                :abs(num_of_rows)]]
S
slguan 已提交
68
    else:
69 70 71 72 73 74
        return [
            None if ele == FieldType.C_SMALLINT_NULL else ele for ele in ctypes.cast(
                data, ctypes.POINTER(
                    ctypes.c_short))[
                :abs(num_of_rows)]]

S
slguan 已提交
75 76 77 78 79

def _crow_int_to_python(data, num_of_rows, nbytes=None, micro=False):
    """Function to convert C int row to python row
    """
    if num_of_rows > 0:
80 81
        return [None if ele == FieldType.C_INT_NULL else ele for ele in ctypes.cast(
            data, ctypes.POINTER(ctypes.c_int))[:abs(num_of_rows)]]
S
slguan 已提交
82
    else:
83 84 85
        return [None if ele == FieldType.C_INT_NULL else ele for ele in ctypes.cast(
            data, ctypes.POINTER(ctypes.c_int))[:abs(num_of_rows)]]

S
slguan 已提交
86 87 88 89 90

def _crow_bigint_to_python(data, num_of_rows, nbytes=None, micro=False):
    """Function to convert C bigint row to python row
    """
    if num_of_rows > 0:
91 92
        return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast(
            data, ctypes.POINTER(ctypes.c_longlong))[:abs(num_of_rows)]]
S
slguan 已提交
93
    else:
94 95 96
        return [None if ele == FieldType.C_BIGINT_NULL else ele for ele in ctypes.cast(
            data, ctypes.POINTER(ctypes.c_longlong))[:abs(num_of_rows)]]

S
slguan 已提交
97 98 99 100 101

def _crow_float_to_python(data, num_of_rows, nbytes=None, micro=False):
    """Function to convert C float row to python row
    """
    if num_of_rows > 0:
102 103
        return [None if math.isnan(ele) else ele for ele in ctypes.cast(
            data, ctypes.POINTER(ctypes.c_float))[:abs(num_of_rows)]]
S
slguan 已提交
104
    else:
105 106 107
        return [None if math.isnan(ele) else ele for ele in ctypes.cast(
            data, ctypes.POINTER(ctypes.c_float))[:abs(num_of_rows)]]

S
slguan 已提交
108 109 110 111 112

def _crow_double_to_python(data, num_of_rows, nbytes=None, micro=False):
    """Function to convert C double row to python row
    """
    if num_of_rows > 0:
113 114
        return [None if math.isnan(ele) else ele for ele in ctypes.cast(
            data, ctypes.POINTER(ctypes.c_double))[:abs(num_of_rows)]]
S
slguan 已提交
115
    else:
116 117 118
        return [None if math.isnan(ele) else ele for ele in ctypes.cast(
            data, ctypes.POINTER(ctypes.c_double))[:abs(num_of_rows)]]

S
slguan 已提交
119 120 121 122

def _crow_binary_to_python(data, num_of_rows, nbytes=None, micro=False):
    """Function to convert C binary row to python row
    """
123
    assert(nbytes is not None)
S
slguan 已提交
124
    if num_of_rows > 0:
125 126
        return [None if ele.value[0:1] == FieldType.C_BINARY_NULL else ele.value.decode(
            'utf-8') for ele in (ctypes.cast(data, ctypes.POINTER(ctypes.c_char * nbytes)))[:abs(num_of_rows)]]
S
slguan 已提交
127
    else:
128 129 130
        return [None if ele.value[0:1] == FieldType.C_BINARY_NULL else ele.value.decode(
            'utf-8') for ele in (ctypes.cast(data, ctypes.POINTER(ctypes.c_char * nbytes)))[:abs(num_of_rows)]]

S
slguan 已提交
131 132 133 134 135

def _crow_nchar_to_python(data, num_of_rows, nbytes=None, micro=False):
    """Function to convert C nchar row to python row
    """
    assert(nbytes is not None)
136
    res = []
S
slguan 已提交
137 138 139
    for i in range(abs(num_of_rows)):
        try:
            if num_of_rows >= 0:
140
                tmpstr = ctypes.c_char_p(data)
141
                res.append(tmpstr.value.decode())
S
slguan 已提交
142
            else:
143 144
                res.append((ctypes.cast(data + nbytes * i,
                                        ctypes.POINTER(ctypes.c_wchar * (nbytes // 4))))[0].value)
S
slguan 已提交
145 146 147
        except ValueError:
            res.append(None)

148 149
    return res

150 151 152 153

def _crow_binary_to_python_block(data, num_of_rows, nbytes=None, micro=False):
    """Function to convert C binary row to python row
    """
154
    assert(nbytes is not None)
155
    res = []
156 157 158
    if num_of_rows > 0:
        for i in range(abs(num_of_rows)):
            try:
159 160 161 162 163 164 165
                rbyte = ctypes.cast(
                    data + nbytes * i,
                    ctypes.POINTER(
                        ctypes.c_short))[
                    :1].pop()
                tmpstr = ctypes.c_char_p(data + nbytes * i + 2)
                res.append(tmpstr.value.decode()[0:rbyte])
166 167 168 169 170
            except ValueError:
                res.append(None)
    else:
        for i in range(abs(num_of_rows)):
            try:
171 172 173 174 175 176 177
                rbyte = ctypes.cast(
                    data + nbytes * i,
                    ctypes.POINTER(
                        ctypes.c_short))[
                    :1].pop()
                tmpstr = ctypes.c_char_p(data + nbytes * i + 2)
                res.append(tmpstr.value.decode()[0:rbyte])
178 179 180 181
            except ValueError:
                res.append(None)
    return res

182

183 184 185 186
def _crow_nchar_to_python_block(data, num_of_rows, nbytes=None, micro=False):
    """Function to convert C nchar row to python row
    """
    assert(nbytes is not None)
187
    res = []
188 189 190
    if num_of_rows >= 0:
        for i in range(abs(num_of_rows)):
            try:
191 192
                tmpstr = ctypes.c_char_p(data + nbytes * i + 2)
                res.append(tmpstr.value.decode())
193 194 195 196 197
            except ValueError:
                res.append(None)
    else:
        for i in range(abs(num_of_rows)):
            try:
198 199
                res.append((ctypes.cast(data + nbytes * i + 2,
                                        ctypes.POINTER(ctypes.c_wchar * (nbytes // 4))))[0].value)
200 201
            except ValueError:
                res.append(None)
S
slguan 已提交
202 203
    return res

204

S
slguan 已提交
205 206
_CONVERT_FUNC = {
    FieldType.C_BOOL: _crow_bool_to_python,
207 208 209 210 211 212
    FieldType.C_TINYINT: _crow_tinyint_to_python,
    FieldType.C_SMALLINT: _crow_smallint_to_python,
    FieldType.C_INT: _crow_int_to_python,
    FieldType.C_BIGINT: _crow_bigint_to_python,
    FieldType.C_FLOAT: _crow_float_to_python,
    FieldType.C_DOUBLE: _crow_double_to_python,
S
slguan 已提交
213
    FieldType.C_BINARY: _crow_binary_to_python,
214 215
    FieldType.C_TIMESTAMP: _crow_timestamp_to_python,
    FieldType.C_NCHAR: _crow_nchar_to_python
S
slguan 已提交
216 217
}

218 219
_CONVERT_FUNC_BLOCK = {
    FieldType.C_BOOL: _crow_bool_to_python,
220 221 222 223 224 225
    FieldType.C_TINYINT: _crow_tinyint_to_python,
    FieldType.C_SMALLINT: _crow_smallint_to_python,
    FieldType.C_INT: _crow_int_to_python,
    FieldType.C_BIGINT: _crow_bigint_to_python,
    FieldType.C_FLOAT: _crow_float_to_python,
    FieldType.C_DOUBLE: _crow_double_to_python,
226
    FieldType.C_BINARY: _crow_binary_to_python_block,
227 228
    FieldType.C_TIMESTAMP: _crow_timestamp_to_python,
    FieldType.C_NCHAR: _crow_nchar_to_python_block
229 230
}

S
slguan 已提交
231
# Corresponding TAOS_FIELD structure in C
232 233


S
slguan 已提交
234
class TaosField(ctypes.Structure):
B
Bomin Zhang 已提交
235 236 237
    _fields_ = [('name', ctypes.c_char * 65),
                ('type', ctypes.c_char),
                ('bytes', ctypes.c_short)]
S
slguan 已提交
238 239

# C interface class
240 241


S
slguan 已提交
242 243 244 245 246 247 248
class CTaosInterface(object):

    libtaos = ctypes.windll.LoadLibrary('taos')

    libtaos.taos_fetch_fields.restype = ctypes.POINTER(TaosField)
    libtaos.taos_init.restype = None
    libtaos.taos_connect.restype = ctypes.c_void_p
249
    #libtaos.taos_use_result.restype = ctypes.c_void_p
S
slguan 已提交
250 251
    libtaos.taos_fetch_row.restype = ctypes.POINTER(ctypes.c_void_p)
    libtaos.taos_errstr.restype = ctypes.c_char_p
weixin_48148422's avatar
weixin_48148422 已提交
252 253
    libtaos.taos_subscribe.restype = ctypes.c_void_p
    libtaos.taos_consume.restype = ctypes.c_void_p
254
    libtaos.taos_fetch_lengths.restype = ctypes.c_void_p
255
    libtaos.taos_free_result.restype = None
T
Tao Liu 已提交
256
    libtaos.taos_errno.restype = ctypes.c_int
T
Tao Liu 已提交
257
    libtaos.taos_query.restype = ctypes.POINTER(ctypes.c_void_p)
S
slguan 已提交
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277

    def __init__(self, config=None):
        '''
        Function to initialize the class
        @host     : str, hostname to connect
        @user     : str, username to connect to server
        @password : str, password to connect to server
        @db       : str, default db to use when log in
        @config   : str, config directory

        @rtype    : None
        '''
        if config is None:
            self._config = ctypes.c_char_p(None)
        else:
            try:
                self._config = ctypes.c_char_p(config.encode('utf-8'))
            except AttributeError:
                raise AttributeError("config is expected as a str")

278
        if config is not None:
S
slguan 已提交
279 280 281 282 283 284 285 286 287 288
            CTaosInterface.libtaos.taos_options(3, self._config)

        CTaosInterface.libtaos.taos_init()

    @property
    def config(self):
        """ Get current config
        """
        return self._config

289 290 291 292 293 294 295
    def connect(
            self,
            host=None,
            user="root",
            password="taosdata",
            db=None,
            port=0):
S
slguan 已提交
296 297 298 299 300 301 302 303
        '''
        Function to connect to server

        @rtype: c_void_p, TDengine handle
        '''
        # host
        try:
            _host = ctypes.c_char_p(host.encode(
304
                "utf-8")) if host is not None else ctypes.c_char_p(None)
S
slguan 已提交
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
        except AttributeError:
            raise AttributeError("host is expected as a str")

        # user
        try:
            _user = ctypes.c_char_p(user.encode("utf-8"))
        except AttributeError:
            raise AttributeError("user is expected as a str")

        # password
        try:
            _password = ctypes.c_char_p(password.encode("utf-8"))
        except AttributeError:
            raise AttributeError("password is expected as a str")

        # db
        try:
            _db = ctypes.c_char_p(
323
                db.encode("utf-8")) if db is not None else ctypes.c_char_p(None)
S
slguan 已提交
324 325 326 327 328 329 330 331 332 333 334 335
        except AttributeError:
            raise AttributeError("db is expected as a str")

        # port
        try:
            _port = ctypes.c_int(port)
        except TypeError:
            raise TypeError("port is expected as an int")

        connection = ctypes.c_void_p(CTaosInterface.libtaos.taos_connect(
            _host, _user, _password, _db, _port))

336
        if connection.value is None:
S
slguan 已提交
337
            print('connect to TDengine failed')
338
            raise ConnectionError("connect to TDengine failed")
S
slguan 已提交
339
            # sys.exit(1)
340
        # else:
341
        #    print('connect to TDengine success')
S
slguan 已提交
342 343 344 345 346 347 348 349

        return connection

    @staticmethod
    def close(connection):
        '''Close the TDengine handle
        '''
        CTaosInterface.libtaos.taos_close(connection)
350
        #print('connection is closed')
S
slguan 已提交
351 352 353 354 355 356 357 358 359 360

    @staticmethod
    def query(connection, sql):
        '''Run SQL

        @sql: str, sql string to run

        @rtype: 0 on success and -1 on failure
        '''
        try:
361 362
            return CTaosInterface.libtaos.taos_query(
                connection, ctypes.c_char_p(sql.encode('utf-8')))
S
slguan 已提交
363 364
        except AttributeError:
            raise AttributeError("sql is expected as a string")
H
Hongze Cheng 已提交
365 366
        # finally:
        #     CTaosInterface.libtaos.close(connection)
367

S
slguan 已提交
368
    @staticmethod
369
    def affectedRows(result):
S
slguan 已提交
370 371
        """The affected rows after runing query
        """
372
        return CTaosInterface.libtaos.taos_affected_rows(result)
S
slguan 已提交
373

weixin_48148422's avatar
weixin_48148422 已提交
374 375 376
    @staticmethod
    def subscribe(connection, restart, topic, sql, interval):
        """Create a subscription
377
         @restart boolean,
weixin_48148422's avatar
weixin_48148422 已提交
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
         @sql string, sql statement for data query, must be a 'select' statement.
         @topic string, name of this subscription
        """
        return ctypes.c_void_p(CTaosInterface.libtaos.taos_subscribe(
            connection,
            1 if restart else 0,
            ctypes.c_char_p(topic.encode('utf-8')),
            ctypes.c_char_p(sql.encode('utf-8')),
            None,
            None,
            interval))

    @staticmethod
    def consume(sub):
        """Consume data of a subscription
        """
        result = ctypes.c_void_p(CTaosInterface.libtaos.taos_consume(sub))
        fields = []
        pfields = CTaosInterface.fetchFields(result)
        for i in range(CTaosInterface.libtaos.taos_num_fields(result)):
            fields.append({'name': pfields[i].name.decode('utf-8'),
                           'bytes': pfields[i].bytes,
                           'type': ord(pfields[i].type)})
        return result, fields

    @staticmethod
    def unsubscribe(sub, keepProgress):
        """Cancel a subscription
        """
        CTaosInterface.libtaos.taos_unsubscribe(sub, 1 if keepProgress else 0)

S
slguan 已提交
409
    @staticmethod
410
    def useResult(result):
S
slguan 已提交
411 412 413 414
        '''Use result after calling self.query
        '''
        fields = []
        pfields = CTaosInterface.fetchFields(result)
415
        for i in range(CTaosInterface.fieldsCount(result)):
S
slguan 已提交
416 417 418 419
            fields.append({'name': pfields[i].name.decode('utf-8'),
                           'bytes': pfields[i].bytes,
                           'type': ord(pfields[i].type)})

420
        return fields
S
slguan 已提交
421 422 423

    @staticmethod
    def fetchBlock(result, fields):
424 425 426 427 428
        pblock = ctypes.c_void_p(0)
        num_of_rows = CTaosInterface.libtaos.taos_fetch_block(
            result, ctypes.byref(pblock))
        if num_of_rows == 0:
            return None, 0
429 430
        isMicro = (CTaosInterface.libtaos.taos_result_precision(
            result) == FieldType.C_TIMESTAMP_MICRO)
431 432
        blocks = [None] * len(fields)
        fieldL = CTaosInterface.libtaos.taos_fetch_lengths(result)
433 434 435 436 437
        fieldLen = [
            ele for ele in ctypes.cast(
                fieldL, ctypes.POINTER(
                    ctypes.c_int))[
                :len(fields)]]
438 439 440 441
        for i in range(len(fields)):
            data = ctypes.cast(pblock, ctypes.POINTER(ctypes.c_void_p))[i]
            if fields[i]['type'] not in _CONVERT_FUNC_BLOCK:
                raise DatabaseError("Invalid data type returned from database")
442 443
            blocks[i] = _CONVERT_FUNC_BLOCK[fields[i]['type']](
                data, num_of_rows, fieldLen[i], isMicro)
444 445

        return blocks, abs(num_of_rows)
446

447 448
    @staticmethod
    def fetchRow(result, fields):
S
slguan 已提交
449
        pblock = ctypes.c_void_p(0)
450 451
        pblock = CTaosInterface.libtaos.taos_fetch_row(result)
        if pblock:
L
liuyq-617 已提交
452
            num_of_rows = 1
453 454
            isMicro = (CTaosInterface.libtaos.taos_result_precision(
                result) == FieldType.C_TIMESTAMP_MICRO)
L
liuyq-617 已提交
455 456
            blocks = [None] * len(fields)
            fieldL = CTaosInterface.libtaos.taos_fetch_lengths(result)
457 458 459 460 461
            fieldLen = [
                ele for ele in ctypes.cast(
                    fieldL, ctypes.POINTER(
                        ctypes.c_int))[
                    :len(fields)]]
L
liuyq-617 已提交
462 463 464
            for i in range(len(fields)):
                data = ctypes.cast(pblock, ctypes.POINTER(ctypes.c_void_p))[i]
                if fields[i]['type'] not in _CONVERT_FUNC:
465 466
                    raise DatabaseError(
                        "Invalid data type returned from database")
L
liuyq-617 已提交
467 468 469
                if data is None:
                    blocks[i] = [None]
                else:
470 471
                    blocks[i] = _CONVERT_FUNC[fields[i]['type']](
                        data, num_of_rows, fieldLen[i], isMicro)
L
liuyq-617 已提交
472
        else:
S
slguan 已提交
473 474 475 476 477 478 479 480 481
            return None, 0
        return blocks, abs(num_of_rows)

    @staticmethod
    def freeResult(result):
        CTaosInterface.libtaos.taos_free_result(result)
        result.value = None

    @staticmethod
482 483
    def fieldsCount(result):
        return CTaosInterface.libtaos.taos_field_count(result)
S
slguan 已提交
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530

    @staticmethod
    def fetchFields(result):
        return CTaosInterface.libtaos.taos_fetch_fields(result)

    # @staticmethod
    # def fetchRow(result, fields):
    #     l = []
    #     row = CTaosInterface.libtaos.taos_fetch_row(result)
    #     if not row:
    #         return None

    #     for i in range(len(fields)):
    #         l.append(CTaosInterface.getDataValue(
    #             row[i], fields[i]['type'], fields[i]['bytes']))

    #     return tuple(l)

    # @staticmethod
    # def getDataValue(data, dtype, byte):
    #     '''
    #     '''
    #     if not data:
    #         return None

    #     if (dtype == CTaosInterface.TSDB_DATA_TYPE_BOOL):
    #         return ctypes.cast(data,  ctypes.POINTER(ctypes.c_bool))[0]
    #     elif (dtype == CTaosInterface.TSDB_DATA_TYPE_TINYINT):
    #         return ctypes.cast(data,  ctypes.POINTER(ctypes.c_byte))[0]
    #     elif (dtype == CTaosInterface.TSDB_DATA_TYPE_SMALLINT):
    #         return ctypes.cast(data,  ctypes.POINTER(ctypes.c_short))[0]
    #     elif (dtype == CTaosInterface.TSDB_DATA_TYPE_INT):
    #         return ctypes.cast(data,  ctypes.POINTER(ctypes.c_int))[0]
    #     elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BIGINT):
    #         return ctypes.cast(data,  ctypes.POINTER(ctypes.c_long))[0]
    #     elif (dtype == CTaosInterface.TSDB_DATA_TYPE_FLOAT):
    #         return ctypes.cast(data,  ctypes.POINTER(ctypes.c_float))[0]
    #     elif (dtype == CTaosInterface.TSDB_DATA_TYPE_DOUBLE):
    #         return ctypes.cast(data,  ctypes.POINTER(ctypes.c_double))[0]
    #     elif (dtype == CTaosInterface.TSDB_DATA_TYPE_BINARY):
    #         return (ctypes.cast(data,  ctypes.POINTER(ctypes.c_char))[0:byte]).rstrip('\x00')
    #     elif (dtype == CTaosInterface.TSDB_DATA_TYPE_TIMESTAMP):
    #         return ctypes.cast(data,  ctypes.POINTER(ctypes.c_long))[0]
    #     elif (dtype == CTaosInterface.TSDB_DATA_TYPE_NCHAR):
    #         return (ctypes.cast(data,  ctypes.c_char_p).value).rstrip('\x00')

    @staticmethod
531
    def errno(result):
S
slguan 已提交
532 533
        """Return the error number.
        """
534
        return CTaosInterface.libtaos.taos_errno(result)
S
slguan 已提交
535 536

    @staticmethod
537
    def errStr(result):
S
slguan 已提交
538 539
        """Return the error styring
        """
540
        return CTaosInterface.libtaos.taos_errstr(result).decode('utf-8')
weixin_48148422's avatar
weixin_48148422 已提交
541 542 543 544 545


if __name__ == '__main__':
    cinter = CTaosInterface()
    conn = cinter.connect()
546
    result = cinter.query(conn, 'show databases')
weixin_48148422's avatar
weixin_48148422 已提交
547

548
    print('Query Affected rows: {}'.format(cinter.affectedRows(result)))
weixin_48148422's avatar
weixin_48148422 已提交
549

550
    fields = CTaosInterface.useResult(result)
weixin_48148422's avatar
weixin_48148422 已提交
551

552
    data, num_of_rows = CTaosInterface.fetchBlock(result, fields)
weixin_48148422's avatar
weixin_48148422 已提交
553 554 555

    print(data)

T
Tao Liu 已提交
556
    cinter.freeResult(result)
557
    cinter.close(conn)