Python SQLite3使用
来源:互联网 发布:网页铃声制作软件 编辑:程序博客网 时间:2024/05/29 16:17
import sqlite3conn = sqlite3.connect('database.db')c = conn.cursor()c.execute('''create table people (id int primary key not null, name text not null, age int not null)''')c.execute("insert into people values(12341,'周驰',23)")c.execute("insert into people values(12522,'李名',22)")c.execute("insert into people values(12309,'大米',33)")c.execute("insert into people values(12301,'张红',13)")c.execute("insert into people values(?, ?, ?)", (12311,'张名',12))#fetch 取来cursor = c.execute('select * from people')print(cursor.fetchone()) #从查询中取一行,取一行tuple类型print(cursor.fetchmany(3)) #从查询中取三行,为List类型 cursor2 = cursor.fetchall()#从查询中取剩余,List类型,虽然只有一行print('cursor:',cursor) #sqlite3.Cursor类型print('cursor2:',cursor2) #list类型for row in cursor: print(row[1],' ******') #光标已经滑到最后,cousor中已无数据print()conn.commit()c.execute("delete from people where name = '周驰'")cursor = c.execute('select * from people')for row in cursor: print(row[1])print()c.execute("delete from people where name = '大米'")conn.rollback()print('回滚到上一次调用commit()时的数据库状态\n')cursor = c.execute('select * from people')for row in cursor: print(row[1])conn.close()
运行结果
阅读全文
0 0
- python 使用sqlite3
- python 使用sqlite3
- python 使用sqlite3
- python 使用sqlite3
- python 使用sqlite3
- python 使用sqlite3
- python使用sqlite3
- Python sqlite3库使用
- python 使用SQLITE3
- Python SQLite3使用
- python之sqlite3使用详解
- python之sqlite3使用详解
- python之sqlite3使用详解
- python之sqlite3使用详解
- python之sqlite3使用详解
- python之sqlite3使用详解
- python之sqlite3使用详解
- python之sqlite3使用详解
- 关于JS中的继承(二)
- 【3分钟带你学】JS对象继承
- AndroidStudio 升级到3.0后输入法中文状态下无法选词解决方案
- Android SVG 和 VectorDrawable 的基本知识
- 第9章 机器学习实战之树回归
- Python SQLite3使用
- Linux环境变量详解
- Android svg VectorDrawable 动画效果
- cuda
- 使用metasploit(MSF)对windows的ms12-020漏洞进行利用的过程
- Android VectorDrawable svg 命令详细综述
- GitHub与Git的区别与入门
- Vpn与ss/ssr的区别
- kafka必会的操作命令