PageRenderTime 52ms CodeModel.GetById 46ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/Doc/includes/sqlite3/complete_statement.py

http://unladen-swallow.googlecode.com/
Python | 30 lines | 26 code | 3 blank | 1 comment | 1 complexity | 87174aa8953ab6ea610c25466c415d48 MD5 | raw file
 1# A minimal SQLite shell for experiments
 2
 3import sqlite3
 4
 5con = sqlite3.connect(":memory:")
 6con.isolation_level = None
 7cur = con.cursor()
 8
 9buffer = ""
10
11print "Enter your SQL commands to execute in sqlite3."
12print "Enter a blank line to exit."
13
14while True:
15    line = raw_input()
16    if line == "":
17        break
18    buffer += line
19    if sqlite3.complete_statement(buffer):
20        try:
21            buffer = buffer.strip()
22            cur.execute(buffer)
23
24            if buffer.lstrip().upper().startswith("SELECT"):
25                print cur.fetchall()
26        except sqlite3.Error, e:
27            print "An error occurred:", e.args[0]
28        buffer = ""
29
30con.close()