Python 官方文档:入门教程 => 点击学习
sqlite是一个轻量级的数据库,类似于Access.一、 安装python 2.5开始提供了对sqlite的支持,带有sqlite3库.没有sqli
python 2.5开始提供了对sqlite的支持,带有sqlite3库.
没有sqlite的版本需要去PySqlite主页上下载安装包.
import sqlite3 #导入模块
cx = sqlite3.connect("d:\\test.db")
cu = cx.cursor()#这样定义了一个游标。
游标对象有以下的操作:
import sqlite3 #导入模块
cx = sqlite3.connect("d:\\test.db")
cu=cx.cursor()
cu.execute("""create table catalog ( id integer primary key, pid integer, name varchar(10) UNIQUE )""")
cu.execute("insert into catalog values(0, 0, 'name1')")
cu.execute("insert into catalog values(1, 0, 'hello')")
cx.commit()
cu.execute("select * from catalog")
print cu.fetchall()
cu.execute("select * from catalog where id = 1")
print cu.fetchone()
cu.execute("update catalog set name='name2' where id = 0")
cx.commit()
cu.execute("select * from catalog")
print cu.fetchone()
cu.execute("delete from catalog where id = 1")
cx.commit()
cu.execute("select * from catalog")
cu.fetchall()
#cu.close()
#cx.close()
--结束END--
本文标题: python 使用sqlite3
本文链接: https://www.lsjlt.com/news/191664.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0