· 8 years ago · Mar 14, 2018, 03:46 PM
1#-*- coding: ISO-8859-1 -*-
2# filename: todosqlite-createdb.py
3# author: ted heich
4#
5# This program is the first part of the todosqlite app, this program handles
6# the creation of the table. If todo.sqlite does not exist on the file system.
7# Everytime you run this code, the table todo will be dropped and recreated--so be warned.
8# it is created automatically.
9#
10
11
12
13from pysqlite2 import dbapi2 as sqlite
14
15def main():
16
17 sql1 = "DROP TABLE IF EXISTS todo"
18 sql2 = "CREATE TABLE todo(id INTEGER PRIMARY KEY AUTOINCREMENT, task VARCHAR(300), status INT)"
19
20 try:
21 conn = sqlite.connect("todo.sqlite")
22 cursor = conn.cursor()
23 cursor.execute(sql1)
24 cursor.execute(sql2)
25
26 print "Affected: %d", cursor.rowcount
27
28 except sqlite.Error, e:
29 print "Error ocurred: ", e.args[0]
30
31if __name__ == "__main__"
32main()