Xmind 笔记:
今日内容:
conn = sqlite3.connect('addressbook.db')
c = conn.cursor()
sql = "select * from LinkMan"
result = c.execute(sql)
for row in result:
print(row)
# 增加:
sql = "insert into LinkMan values ('Mary','18933342222','1985-4-6',1)"
c.execute(sql)
conn.commit()
conn.close()
# 更新
sql = "update LinkMan set Mobile = '1893333222' where Name= 'Jason'"
c.execute(sql)
conn.commit()
# 删除
sql = "delete from LinkMan where Name='Mary'"
c.execute(sql)
conn.commit()
sql = "select * from LinkMan"
c.execute(sql)
list = c.fetchall()
row = c.fetchone()
result = c.fetchmany(2)
##update:用占位符的模式
name = ('Tom',)
sql = "select * from LinkMan where Name=?"
c.execute(sql,name)
c.fetchone()
# or
sql = "insert into LinkMan values(:Name,:Mobile,:Birthdate,:Isvalid)"
c.execute(sql,{'Name':'John','Mobile':'189335993','Birthdate':'1989-5-3','Isvalid':1})
conn.commit()
来源:CSDN
作者:m0_46181634
链接:https://blog.csdn.net/m0_46181634/article/details/104283255