sqlite3

python 笔记 sqlite3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import sqlite3
conn=sqlite3,connect('test.db')
c=conn.cursor()
#执行sql命令
c.execute("insert into book values(1,1,'kitchen')")
c.execute("insert into book values(?,?,?)",[(2,2,'computer')])
#插入多行
books=[(1,1,'cookRecipe',3,12,1),
(2,3,'python inero',17.5,2),
(3,2,'OS intero',13.6,2),
]
c.executemany('insert into book values(?,?,?,?,?)',books)
conn.commit()
#查询数据
c.execute('select name from book order by id ')
print(c.fetchone())
print(c.fetchall())
#查询多行
for row in c.execute('select * from book order by id ')
print(row)
conn.close()

Comments