First, let us take some time to familiarize with the steps necessary to create a new database from Python.
Enter the following code and run it (It is also available as taskdb1.py
).
Chapter4/taskdb1.py
import sqlite3 database=':memory:' connection = sqlite3.connect(database) cursor=connection.executescript(''' create table if not exists task ( task_id integer primary key autoincrement, description, duedate, completed, user_id ); ''') connection.commit() sql = '''insert into task (description,duedate,completed,user_id) values(?,?,?,?)''' cursor.execute(sql,('work' ,'2010-01-01',None,'alice')) cursor.execute(sql,('more work' ,'2010-02-01',None,'alice')) cursor.execute(sql,('work' ,'2010-03-01',None,'john')) cursor.execute(sql,('even more work','2010-04-01',None,'john')) connection.commit() connection.close()
It will create a temporary database in memory and defines a task table. It also populates this table with...