taosdata/taos-connector-python

增加api进行时间戳转换控制

kaybinwong opened this issue · 0 comments

部分系统数据流转用的是时间戳,需要增加api控制是否进行时间戳转换。

目前是有入侵式地使用,2.2.1版本升级到2.3.5后有不兼容问题。

def _crow_timestamp_to_python(data, num_of_rows, nbytes=None, precision=FieldType.C_TIMESTAMP_UNKNOWN):
    """Function to convert C bool row to python row"""
    
    if precision == FieldType.C_TIMESTAMP_MILLI:
        _divide = 1e+3
    elif precision == FieldType.C_TIMESTAMP_MICRO:
        _divide = 1e+6
    elif precision == FieldType.C_TIMESTAMP_NANO:
        _divide = 1e+9
    else:
        raise DatabaseError("Unknown precision returned from database")

    return [
        None if ele == FieldType.C_BIGINT_NULL else ele / _divide
        for ele in ctypes.cast(data, ctypes.POINTER(ctypes.c_int64))[: abs(num_of_rows)]
    ]