Skip to content

Instantly share code, notes, and snippets.

@nmcv
Created June 9, 2014 17:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmcv/1b61a77b136565333f08 to your computer and use it in GitHub Desktop.
Save nmcv/1b61a77b136565333f08 to your computer and use it in GitHub Desktop.
Minimal SQLite shell from Python docs
# A minimal SQLite shell for experiments
import sqlite3
con = sqlite3.connect(":memory:")
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 = input()
if line == "":
break
buffer += line
if sqlite3.complete_statement(buffer):
try:
buffer = buffer.strip()
cur.execute(buffer)
if buffer.lstrip().upper().startswith("SELECT"):
print(cur.fetchall())
except sqlite3.Error as e:
print("An error occurred:", e.args[0])
buffer = ""
con.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment