Skip to content

Instantly share code, notes, and snippets.

@tedheich
Created October 21, 2009 13:18
Show Gist options
  • Save tedheich/215100 to your computer and use it in GitHub Desktop.
Save tedheich/215100 to your computer and use it in GitHub Desktop.
script to create the sqlite db for todo.py
#-*- coding: ISO-8859-1 -*-
# filename: todosqlite-createdb.py
# author: ted heich
#
# This program is the first part of the todosqlite app, this program handles
# the creation of the table. If todo.sqlite does not exist on the file system.
# Everytime you run this code, the table todo will be dropped and recreated--so be warned.
# it is created automatically.
#
from pysqlite2 import dbapi2 as sqlite
def main():
sql1 = "DROP TABLE IF EXISTS todo"
sql2 = "CREATE TABLE todo(id INTEGER PRIMARY KEY AUTOINCREMENT, task VARCHAR(300), status INT)"
try:
conn = sqlite.connect("todo.sqlite")
cursor = conn.cursor()
cursor.execute(sql1)
cursor.execute(sql2)
print "Affected: %d", cursor.rowcount
except sqlite.Error, e:
print "Error ocurred: ", e.args[0]
if __name__ == "__main__"
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment