找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 16|回复: 0

Pysqlite(嵌入式数据库python api 接口)

[复制链接]

32万

主题

0

回帖

96万

积分

超级版主

积分
964681
发表于 2025-3-14 11:52:25 | 显示全部楼层 |阅读模式
软件标签:  pysqlite   python   数据库
py sqlitewindows是一款专为windows用户打造的api接口,旨在更好的帮助 sqlite 操作者工作,需要的朋友赶紧来绿色资源网下载吧
pysqlite windows版简介
pysqlite是一个sqlite 为 python 提供的 api 接口,它让一切对于 sqlite 的操作都变得异常简单。

sqlite,它是一个嵌入式数据库,没有服务器的概念,windows版的就是一个exe,自己把它放到一个合适的目录里,然后把这个目录加入系统的path变量.
pysqlite使用说明
在数据库建立中windows与linux也有不同

xp版本:sqlite3.exe test.db

linux版本:./sqlite3.bin test.db

目前针对不同的python版本,pysqlite有3个版本:2.5和2.6 、2.7,请根据自己的python版本选用.

3.然后就可以打开自己喜欢的编辑器,写一段测试代码了.

4.中文处理要注意的是sqlite默认以utf-8编码存储.

5.另外要注意sqlite仅支持文件锁,换句话说,它对并发的处理并不好,不推荐在网络环境使用,适合单机环境;

import pysqlite2.dbapi2 as sqlite

def runtest():

cx = sqlite.connect(“test.db“)

cu = cx.cursor()

#create

cu.execute(“““create table catalog(

id integer primary key,

pid integer,

name varchar(10) unique

)“““)

#insert

cu.execute(“insert into catalog values(0,0,"张小山")“)

cu.execute(“insert into catalog values(1,0,"hello")“)

cx.commit()

#select

cu.execute(“select * from catalog“)

print “1:“,

print cu.rowcount

rs = cu.fetchmany(1)

print “2:“,

print rs

rs = cu.fetchall()

print “3:“,

print rs

#delete

cu.execute(“delete from catalog where id = 1 “)

cx.commit()

cu.execute(“select * from catalog“)

rs = cu.fetchall()

print “4:“,

print rs

#select count

cu.execute("select count(*) from catalog")

rs = cu.fetchone()

print “5:“,

print rs

cu.execute("select * from catalog")

cu.execute(“drop table catalog“)

if __name__ == “__main__“:

runtest()
数据库操作
python的数据库模块都有统一的接口标准,所以数据库操作都基本上是统一的,基本上分成以下几步(假设数据库模块为db):

用db.connect()创建数据库连接,连接对象为conn。

如果不需要返回查询结果,就直接调用conn.execute()。

如果需要返回查询结果,则需要首先通过conn.cursor()创建游标对象cur,并使用cur.fetchone()等函数获取查询结果。

根据数据库隔离级别的不同,修改数据库后,可能需要使用conn.commit()手动提交事务。

调用相应的close()方法关闭cur及conn。


aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|ziyuan80.com

GMT+8, 2025-8-11 07:17 , Processed in 0.082413 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表