annotate Doc/lib/sqlite3/complete_statement.py @ 39496:352ffe77b71d legacy-trunk

Patch #1535500: fix segfault in BZ2File.writelines and make sure it raises the correct exceptions.
author Georg Brandl <georg@python.org>
date Mon, 14 Aug 2006 21:42:55 +0000
parents 0de9d71444f6
children 6b18a095c2e7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38069
cf19a123a5d9 Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
1 # A minimal SQLite shell for experiments
cf19a123a5d9 Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
2
cf19a123a5d9 Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
3 import sqlite3
cf19a123a5d9 Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
4
cf19a123a5d9 Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
5 con = sqlite3.connect(":memory:")
cf19a123a5d9 Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
6 con.isolation_level = None
cf19a123a5d9 Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
7 cur = con.cursor()
cf19a123a5d9 Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
8
cf19a123a5d9 Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
9 buffer = ""
cf19a123a5d9 Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
10
cf19a123a5d9 Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
11 print "Enter your SQL commands to execute in sqlite3."
cf19a123a5d9 Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
12 print "Enter a blank line to exit."
cf19a123a5d9 Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
13
cf19a123a5d9 Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
14 while True:
cf19a123a5d9 Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
15 line = raw_input()
cf19a123a5d9 Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
16 if line == "":
cf19a123a5d9 Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
17 break
cf19a123a5d9 Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
18 buffer += line
cf19a123a5d9 Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
19 if sqlite3.complete_statement(buffer):
cf19a123a5d9 Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
20 try:
cf19a123a5d9 Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
21 buffer = buffer.strip()
cf19a123a5d9 Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
22 cur.execute(buffer)
cf19a123a5d9 Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
23
cf19a123a5d9 Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
24 if buffer.lstrip().upper().startswith("SELECT"):
cf19a123a5d9 Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
25 print cur.fetchall()
cf19a123a5d9 Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
26 except sqlite3.Error, e:
39244
0de9d71444f6 Typo fix
Andrew M. Kuchling <amk@amk.ca>
parents: 38069
diff changeset
27 print "An error occurred:", e.args[0]
38069
cf19a123a5d9 Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
28 buffer = ""
cf19a123a5d9 Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
29
cf19a123a5d9 Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff changeset
30 con.close()