Sample code/Python/SQLite

This page presents a Python program which displays the contents of an SQLite database.

The source
The source code for the SQLite example program (index.py) is presented here: from pysqlite2 import dbapi2 as sqlite

db = sqlite.connect('test.db') cur = db.cursor cur.execute('CREATE TABLE n (id INTEGER PRIMARY KEY, f TEXT, l TEXT)') db.commit cur.execute('INSERT INTO n (id, f, l) VALUES(NULL, "john", "smith")') db.commit cur.execute('SELECT * FROM n') print cur.fetchall

Enabling the lighttpd webserver for use with Python
See the Python Hello World example for information on how to configure lighttpd for Python.

Using index.py
Upload index.php to the gumstix folder /www/pages and change the permissions. (See the PHP Hello World page for the configuration information of lighttpd.)

chmod 755 /www/pages/index.py

With lighttpd running, navigate your browser to the gumstix ip address: http://ip_address:port/index.py/

i.e. http://192.168.167.16:82/index.py/

Or, equivalently: http://192.168.167.16:82/

The default port is 80 but that can be changed in lighttpd.conf.

You should see the following as an output: [(1, u'john', u'smith')]