Import sqlite3# Query def load (table): #连接数据库 con = sqlite3.connect ("e:/datebase/sqlitestudio/park.db") # Get cursor cur = con.cursor () #查询整个表 cur.execute (' select *from ' +table) lists = [' name ', ' password '] if Table = = ' Login ': #将数据库列名存入字典 colnames = {desc[0] for desc in cur.description} stores the dictionary and database data in a list and obtains a record dictionary C11/>rowdicts = [Dict (Zip (lists, row)) for row in Cur.fetchall ()] else: rowdicts = [] for row in cur: Rowdicts.append (Row) con.commit () cur.close () return rowdicts# insert Data def insert_data (Id,name,money): con = sqlite3.connect ("e:/datebase/sqlitestudio/park.db") cur = con.cursor () #使用SQL语句插入 Cur.execute (' INSERT into Charge values (?,?,?) ', (Id,name, Money)) #插入后进行整表查询 to see if Cur.execute was successfully inserted (' SELECT * From Charge ') print (Cur.fetchall ()) con.commit () cur.close ()
Python joins SQLite and operates