~ubuntu-branches/ubuntu/trusty/python3.4/trusty-proposed

« back to all changes in this revision

Viewing changes to Doc/includes/sqlite3/complete_statement.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-11-25 09:44:27 UTC
  • Revision ID: package-import@ubuntu.com-20131125094427-lzxj8ap5w01lmo7f
Tags: upstream-3.4~b1
ImportĀ upstreamĀ versionĀ 3.4~b1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# A minimal SQLite shell for experiments
 
2
 
 
3
import sqlite3
 
4
 
 
5
con = sqlite3.connect(":memory:")
 
6
con.isolation_level = None
 
7
cur = con.cursor()
 
8
 
 
9
buffer = ""
 
10
 
 
11
print("Enter your SQL commands to execute in sqlite3.")
 
12
print("Enter a blank line to exit.")
 
13
 
 
14
while True:
 
15
    line = 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 as e:
 
27
            print("An error occurred:", e.args[0])
 
28
        buffer = ""
 
29
 
 
30
con.close()