# Collection of code snippets by Arne Vajhøj 
# (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
import sqlite3

# open database
con = sqlite3.connect('msgs.db')
# write message to database
c = con.cursor()
c.execute('INSERT INTO msgs (msg) VALUES (?)', ('Hi from Python!', ))
con.commit()
# dump all messages in database
c = con.cursor()
c.execute('SELECT msg FROM msgs')
for row in c.fetchall():
    print('|' + row[0] + '|')
# close database
con.close()
