November 2018
Beginner
304 pages
7h 35m
English
To use the SQLite database, you simply import it like any other library. Once imported, you have to make a connection to it; this creates the database file. A cursor is the object within SQLite that performs most of the functions you will be doing with the DB.
The following code listing demonstrates the creation of a SQLite database:
# tools_db.py (part 1)1 import sqlite32 3 connection = sqlite3.connect("Tools.db") # The .db extension is optional4 cursor = connection.cursor() # Executes SQL queries56 # Create the table to hold entries7 cursor.execute("""8 CREATE TABLE Tools9 (id INTEGER PRIMARY KEY,10 name TEXT,11 size TEXT,12 price INTEGER)13 """)
The sqlite3 library is imported in line 1. Lines 2 and 3 create ...
Read now
Unlock full access