db相关
时间:2021-07-01 10:21:17
帮助过:5人阅读
sqlite3
conn=sqlite3.connect(
‘D:/test.db‘)
c=
conn.cursor()
sql=
‘‘‘create table if not exists basic_info
(id int,
label text)‘‘‘
sql1=
‘‘‘
insert into basic_info values (1,‘A‘);
insert into basic_info values (2,‘B‘)‘‘‘
c.execute(sql)
c.executescript(sql1)
c.executemany(‘insert into basic_info values (?,?)‘,[(3,
‘C‘)])
for value
in [(4,
‘D‘)]:
c.execute(‘insert into basic_info values (?,?)‘,value)
conn.commit()
rows=c.execute(
‘select * from basic_info‘)
for row
in rows:
print row
rows=c.execute(
‘select * from basic_info‘)
for row
in rows.fetchall():
print row
rows=c.execute(
‘select * from basic_info‘)
for row
in rows.fetchone():
print row
rows=c.execute(
‘select * from basic_info‘)
for row
in rows.fetchmany():
print row
c.close()
conn.close()
结果 #注释自己写上去的
db相关
标签: