Python sqlite 官方文档:
https://docs.python.org/2/library/sqlite3.html
1. 连接
#!/usr/bin/python3
import sqlite3
conn = sqlite3.connect("dababase.db")
2. 创建表
cursor = conn.cursor()
cursor.execute('''CREATE TABLE SENSOR
(ID INT PRIMARY KEY NOT NULL,
message BLOB NOT NULL
);''')
3. 插入数据
cursor.execute("INSERT INTO SERSOR VALUES (?, ?)",
key_index, "cccc")
4. 读取表里的数据
read_data = cursor.execute("SELECT ID message from SENSOR")