Article From:https://www.cnblogs.com/nori/p/9967716.html
 SQLite is an embedded database whose database is a file. Because SQLite itself is written in C and small in size, it is often integrated into various applications, even in iOS and Andro.It can be integrated in App with ID.
Python has built-in SQLite 3, so you don't need to install anything to use it directly in Python.
table is a collection of relational data stored in the database. A database usually contains many tables, such as student's table, class's table, school's table, and so on. Tables and tables are associated by foreign keys.
To operate a relational database, you first need to connect to the database, a database connection is called Connection.
Python defines a set of API interfaces to operate the database. To connect any database to Python, you only need to provide a Python-compliant database driver.
Because the driver of SQLite is built into the Python standard library, we can directly operate the SQLite database.
 1 #Import database driver
 2 import sqlite3
 3 
 4 #Connect to database
 5 #The database file is "test. db"
 6 #If the database does not exist, a database will be created automatically.
 7 conn = sqlite3.connect("test.db")
 8 
 9 #Create a cursor curson
10 cursor = conn.cursor()
11 
12 #Execute a statement to create a user table
13 # sql = "create table login (id varchar(20) primary key, name varchar(30), password varchar(30))"
14 # cursor.execute(sql)
15 
16 
17 #Insert a record
18 #sql = "insert into login (name, password) values (\'love\', \'520520')"
19 #cursor.execute(sql)
20 
21 
22 #Query a record:
23 # sql = "select * from login"
24 # cursor.execute(sql)
25 # sql = "select * from login where id=?"
26 # cursor.execute(sql, ("2",))
27 
28 
29 #Get the query result:
30 # values = cursor.fetchall()
31 #
32 # print(values)
33 
34 
35 # Get the number of rows inserted through rowcount:
36 #cursor.rowcount()
37 
38 #Close cursor:
39 cursor.close()
40 
41 #Submission of things
42 conn.commit()
43 
44 #Close connection
45 conn.close()

 

"
Link of this Article: Python’s simple use of SQLite 3

Leave a Reply

Your email address will not be published. Required fields are marked *