forked from adafruit/Adafruit-Raspberry-Pi-Python-Code
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsql.py
More file actions
33 lines (25 loc) · 730 Bytes
/
sql.py
File metadata and controls
33 lines (25 loc) · 730 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/python
# A minimal SQLite shell for experiments
import sqlite3
con = sqlite3.connect("data/samples.db")
con.isolation_level = None
cur = con.cursor()
buffer = ""
print "Enter your SQL commands to execute in sqlite3."
print "Enter a blank line to exit."
while True:
line = raw_input()
if line == "":
break
buffer += line
if sqlite3.complete_statement(buffer):
try:
buffer = buffer.strip()
cur.execute(buffer)
print cur.fetchall()
if buffer.lstrip().upper().startswith("SELECT"):
print cur.fetchall()
except sqlite3.Error as e:
print "An error occurred:", e.args[0]
buffer = ""
con.close()