16 May 2016

经典示例

import sqlite3

conn = sqlite3.connect("people.db")  # 若数据库不存在将会自动创建
# conn = sqlite3.connect(":memory:")  # 连接内存里的数据库
# conn.commit()  # 事务提交
# conn.rollback()  # 事务回滚
# conn.close()  # 关闭数据库连接
# conn.cursor()  # 创建游标
c = conn..cursor()  # 获取数据库游标
# c.execute()  # 执行 SQL 
# c.fetchone()  # 从结果中取一条记录,并将游标指向下一条记录
# c.fetchmany()  # 从结果中取多条记录
# c.fetchall()  # 从结果中取出所有记录
# c.scroll()  # 游标滚动

# 创建表
c.execute("create table if not exists people(id integer primary key, name text NULL)")

# 插入一组数据
name = u'LM'.decode('utf-8')
t = (1,name)
c.execute("insert into people values(?,?)',t)

# 查询
c.execute("select * from people")
c.
# 提交作业
conn.commit()



blog comments powered by Disqus