sql.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:pwtools 作者: elcorto 项目源码 文件源码
def find_sqltype(val):
    """
    Find sqlite data type which matches the type of `val`.

    Parameters
    ----------
    val : any python type

    Returns
    -------
    sqltype : str
        String with sql type which can be used to set up a sqlile table
    """        
    mapping = {\
        types.NoneType:    'NULL',
        types.IntType:     'INTEGER',
        types.LongType:    'INTEGER',
        types.FloatType:   'REAL',  # 'FLOAT' also works
        types.StringTypes: 'TEXT',  # StringType + UnicodeType
        types.BufferType:  'BLOB'}
    for typ in mapping.keys():
        if isinstance(val, typ):
            return mapping[typ]
    raise StandardError("type '%s' unknown, cannot find mapping "
        "to sqlite3 type" %str(type(val)))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号