yanfei 发表于 2016-11-30 11:17:32

Python操作sqlite数据库的一些记录

  Python 内置了sqlite的模块

import sqlite3
connection=sqlite3.connect('coachdata.sqlite')
cursor=connection.cursor();
'''cursor.execute("""create table athletes(id integer primary key autoincrement unique not null,
name text not null,
dob date not null
)""")'''
#创建表
#cursor.execute("insert into athletes(name,dob) values(?,?)",('zzc','1990-0210'));
#插入表
cursor.execute("select * from athletes")
#查询表
print cursor.fetchall()
connection.commit()
#一定要提交
connection.close()

  cursor.fetchone()返回下一个数据行
  cursor.fetchmany()返回多个数据行
  cursor.fetchall()返回所有数据
页: [1]
查看完整版本: Python操作sqlite数据库的一些记录