????SQLite???????????????????????????????????????SQLite??????Cд????????????С????????????????????????ó????У???????IOS??Android??APP?ж???????ɡ?
????Python??????SQLite3?????????Python?????SQLite???????????κζ??????????á?
?????????SQLite???????????????????????
??????????????д??????????????????????????????????????????????????????????У???????????????????????????
??????????????????????????????????????????????Connection??
?????????????????????α?????Cursor?????Cursor???SQL???????????н????
????????????????
????import sqlite3
????#???????
????db_name = "test.db"
????#????
????table_name = "catalog"
????conn = sqlite3.connect(db_name)
???????????α?
????rs = conn.cursor()
????????????
????sql = 'create table ' + table_name + ' (id varchar(20) primary key?? pid integer?? name varchar(10))'
????try:
????rs.execute(sql)
????print("??????")
????except:
????print("???????")
??????????????????????
# ???????????????
sql = "Insert into " + table_name + " values ('001'?? 1?? '????')"
try:
rs.execute(sql)
#??????
conn.commit()
print("??????")
except:
print("???????")
sql = "Insert into " + table_name + " values ('002'?? 2?? '????')"
try:
rs.execute(sql)
#??????
conn.commit()
print("??????")
except:
print("???????")
sql = "Insert into " + table_name + " values ('003'?? 3?? '????')"
try:
rs.execute(sql)
#??????
conn.commit()
print("??????")
except:
print("???????")
# ??????pid????3????
sql = "Delete from " + table_name + " where pid = 3"
try:
rs.execute(sql)
conn.commit()
print("??????")
except:
print("??????")
# ?????pid????2??????pid???1
sql = "Update " + table_name + " set pid = 1 where pid = 2"
try:
rs.execute(sql)
conn.commit()
print("?????")
except:
print("??????")
# ??
# ?????????????б???
sql = "Select name From sqlite_master where type = 'table'"
res = rs.execute(sql)
print(res.fetchall())
# ??????????м??
sql = "Select * from " + table_name
try:
res = rs.execute(sql)
print(res.fetchall())
except:
print([])
?????塢????α?
????rs.close()
????????????????????
????conn.close()