posted on: 2008-09-05 07:52:28
This is the simplest...raw_input() based terminal, but I use it.

>I included a check for the ';' at the end to make me feel more like I am doing sql, but of course this terminal doesn't have all of the nifty sql terminal features such as scroll back.

A good reference is found at

#!/usr/bin/env python
from pysqlite2 import dbapi2 as sqlite
import sys

This is a small version of a program I use.  I have more macros
def no(onecurse):
	return 0
def ShowTables(onecurse):
	onecurse.execute('SELECT name FROM SQLITE_MASTER where type=?',('table',))
	data = onecurse.fetchall()
	for item in data:
		print repr(item)

macros = {"t":ShowTables}
conn = sqlite.connect(sys.argv[1])
Cursed = conn.cursor()
test = 'start'
while test!='q':
		if test[-1]==';':
			data = Cursed.fetchall()
			for item in data:
				print repr(item)
		print sys.exc_info()
	test = raw_input('>>')

I've included a show tables macro since it is a bit more obscure than the standard. Note if the command line argument does not exist, it will create that table. I will probably create another post with usefull ... simple examples.

Such as


Can be used here as

PRAGMA table_info([TABLENAME]);


2008-09-08 08:59:58
Here is the command for making it work like a terminal: <pre> import readline </pre> If you are in windows: <pre> import pyreadline </pre>