#-*- encoding:utf-8 -*- import sqlite3
打开数据库,如果文件不存在会自动创建
conn = sqlite3.connect("container.db")
数据库表是否已经存在
cur = conn.cursor() cur.execute("select count(*) from sqlite_master where type='table' and name='container'") cur.fetchone() conn.commit() conn.execute("create table container(container_name, account_id text)") conn.execute("insert into container values ('code.ideais.net', 'jilili')") conn.commit()
通过游标返回结果
cur = conn.cursor() cur.execute("select * from container") print cur.fetchall() cur.close() conn.close()