本篇文章主要介绍了"python对sqlite数据库的增删查改操作",主要涉及到SQLite数据库,sqlite方面的内容,对于SQLite感兴趣的同学可以参考一下:
db.py内容如下:#导入Python SQLITE数据库模块(Python2.5之后,已内置了SQLite3)import sqlite3#创建/打开...
db.py内容如下:
#导入Python SQLITE数据库模块(Python2.5之后,已内置了SQLite3)
import sqlite3
#创建/打开数据库
cx = sqlite3.connect("/Users/lijie/pythonworkspace/webpy/db/sqlite.db")
#con = sqlite3.connect(":memory:")
cu=cx.cursor()
#创建表
#cu.execute("create table catalog (id integer primary key,pid integer,name varchar(10) UNIQUE,nickname text NULL)")
#插入数据
for t in[(0,10,'abc','Yu'),(1,20,'cba','Xu')]:
cx.execute("insert into catalog values (?,?,?,?)", t)
cx.commit()
#查询
cu.execute("select * from catalog")
#提取查询到的数据
for item in cu.fetchall()
for element in item:
print element,
print
#修改
cu.execute("update catalog set name='Boy' where id = 0")
cx.commit()
#删除
cu.execute("delete from catalog where id = 1")
cx.commit()
参考:
http://www.cnblogs.com/yuxc/archive/2011/08/18/2143606.html
以上就介绍了python对sqlite数据库的增删查改操作,包括了SQLite数据库,sqlite方面的内容,希望对SQLite有兴趣的朋友有所帮助。
本文网址链接:http://www.codes51.com/article/detail_566297.html