'''
Created on 2019年3月6日
@author: Administrator
'''
import sqlite3
import numpy as np
import json
conn = sqlite3.connect('sample_database.db', isolation_level=None)
'''
参数isolation_level是同Conection.isolation_level的属性意义一样
'''
x = np.arange(12).reshape(2, 6)
cursor = conn.cursor()
cursor.execute("DROP TABLE test2")
cursor.execute("create table test2 (arr BLOB)")
cursor.execute("insert into test2 (arr) values (?)", (json.dumps(x.tolist()),))
conn.commit()
cursor.execute("select arr from test2")
data = cursor.fetchall()
print(data)
print(type(data))
my_list = json.loads(data[0][0])
temp = np.array(my_list)
print(temp)
print(type(temp))
cursor.close()
conn.close()