Created
January 26, 2020 06:01
-
-
Save tyabu12/ec5ed23d9c21ce7e9aeeb9639c00dc42 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import readline | |
import sqlite3 | |
def print_row(row): | |
print('(' + ', '.join(str(_) for _ in row) + ')') | |
conn = sqlite3.connect(':memory:') | |
c = conn.cursor() | |
while True: | |
q = '' | |
line = raw_input('query> ') | |
if line.strip() == 'exit': | |
break | |
while True: | |
q += line | |
if line[-1:] == ';': | |
break | |
line = raw_input('') | |
q = q.strip() | |
print('Execute: ' + q) | |
try: | |
c.execute(q) | |
for i, row in enumerate(c): | |
if i == 0: | |
print_row([desc[0] for desc in c.description]) | |
print_row(list(row)) | |
except sqlite3.Error as e: | |
print(e) | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment