1. Import Sqlite3 database module, from python2.5, sqlite3 become built-in module, do not need additional installation, only need to import.
import sqlite3
2. Create/Open Database
To open a database by using the Connect methodcon = sqlite3.connect(‘D:\test.db‘)
Not only can you create database files on your hard disk, but you can also create them in memory.
con = sqlite3.connect(‘:memory:‘)
3. Database Connection objects
The Con object is returned by the Connect method above. That is, the database object, which provides the following methods:
The cursor () method is used to create a cursor object
Commit () method for transaction commit
The rollback () method is used to rollback a transaction
The close () method is used to close a database connection
4. Use of Cursor objects
To create a Cursor object:cur = con.cursor()
Cursor methods
Execute () to execute the SQL statement
Executemany () to execute multiple SQL statements
Close () Closes the cursor object
Fetchone () is used to fetch a record from the result and point to the next record
Fetchmany () take more than one record
Fetch () Fetch all records
Sroll () for cursor scrolling
Python Operation SQLite