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)))
评论列表
文章目录