Created
June 9, 2014 17:19
-
-
Save nmcv/1b61a77b136565333f08 to your computer and use it in GitHub Desktop.
Minimal SQLite shell from Python docs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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