day14_SQLite Python操作

久未见 提交于 2020-02-13 00:49:03

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()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!