Lecture code examples from Week 4, should be runnable on Bluehost sqlite database command log: Create a new people.db: # sqlite3 people.db SQLite version 3.6.20 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> create table users(name varchar(100) primary key, age integer); sqlite> .quit # ls -l people.db -rw-r--r-- 1 pgbovine pgbovine 2048 Sep 22 20:20 people.db # sqlite3 people.db SQLite version 3.6.20 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> insert into users values('Philip', 30); sqlite> insert into users values('John', 25); sqlite> insert into users values('Jane', 40); sqlite> select * from users; Philip|30 John|25 Jane|40 sqlite> select * from users order by name; Jane|40 John|25 Philip|30 sqlite> select * from users order by age; John|25 Philip|30 Jane|40 sqlite> select * from users where age < 35; Philip|30 John|25 sqlite> select * from users where age < 35 order by name; John|25 Philip|30 Using sqlite from Python cgi-bin/hello.py: #!/usr/bin/python # Philip Guo - CSC 210 # put in public_html/cgi-bin/ and set the proper execute permissions import cgi import datetime # to facilitate debugging import cgitb cgitb.enable() import sqlite3 form = cgi.FieldStorage() name = form['my_name'].value age = form['my_age'].value conn = sqlite3.connect('people.db') c = conn.cursor() try: c.execute('insert into users values(?,?);', (name, int(age))) conn.commit() except sqlite3.IntegrityError: pass print "Content-type: text/html" # don't forget the extra newline! print print "" print "My webpage" print "" print "

Hello world

" print "

The time is: " + str(datetime.datetime.now()) + "

" print "

Your name is: " + name + "

" print "

Your age is: " + age + "

" print "
"

for row in c.execute('select * from users where age > 10 order by age'):
    print 'Name:', row[0], '| Age:', row[1]

print "
" print "" print ""