July 2018
Intermediate to advanced
462 pages
12h 2m
English
To work with database tables, you need to get a cursor object and pass the SQL statements to the cursor object to execute them. The following statement creates a cursor object called cur:
cur = conn.cursor()
Using the cursor object, cur, you can execute SQL statements. For example, the following set of statements creates a Users table consisting of three columns, id, EmailAddress, and Password:
# Get a cursor objectcur = conn.cursor()cur.execute('''CREATE TABLE Users(id INTEGER PRIMARY KEY, EmailAddress TEXT, Password TEXT)''')conn.commit()
Remember, you need to commit the changes to the database by invoking the commit() method on the connection object, otherwise all the changes made to the database will be lost. ...
Read now
Unlock full access