Python connects to sqlite and operations, and python connects to sqlite

Source: Internet
Author: User

Python connects to sqlite and operations, and python connects to sqlite

Import sqlite3 # query def load (table): # connect to the database con = sqlite3.connect ("E:/Datebase/SQLiteStudio/Park. db ") # obtain the cursor cur = con. cursor () # query the entire table cur.exe cute ('select * from' + table) lists = ['name', 'Password'] if table = 'login ': # store the database column name in the dictionary colnames = {desc [0] for desc in cur. description} saves the dictionary and database data to the list and obtains the record dictionary rowdicts = [dict (zip (lists, row) for row in cur. fetchall ()] else: rowdicts = [] for row in cur: row Dicts. 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 () # use an SQL statement to insert cur.exe cute ('insert into Charge values (?,?,?) ', (ID, name, money) # query the entire table after insertion to see if cur.exe cute ('select * from charge') print (cur. fetchall () con. commit () cur. close ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.