Mercurial > cpython-lru_cache-weakref
annotate Doc/lib/sqlite3/complete_statement.py @ 39042:c02fa187e0f4 legacy-trunk
Part of SF patch #1484695. This removes dead code. The chksum was
already verified in .frombuf() on the lines above. If there was
a problem an exception is raised, so there was no way this condition
could have been true.
| author | Neal Norwitz <nnorwitz@gmail.com> |
|---|---|
| date | Mon, 10 Jul 2006 00:23:17 +0000 |
| parents | cf19a123a5d9 |
| children | 0de9d71444f6 |
| 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: |
|
cf19a123a5d9
Further integration of the documentation for the sqlite3 module. There's still
Gerhard Häring <gh@ghaering.de>
parents:
diff
changeset
|
27 print "An error occured:", e.args[0] |
|
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() |
