diff options
author | William Carroll <wpcarro@gmail.com> | 2022-03-01T22·05-0800 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2022-03-01T22·08+0000 |
commit | 0e76f30c5b33c8cd9a086123d5919f743c5bce71 (patch) | |
tree | 77381357c7d0beb874b160b2e6190884cadb3b26 | |
parent | 9eefa2e4842d5678f7829c7af45e38d30be617d8 (diff) |
feat(wpcarro/simple-select): Execute SQL query on database r/3887
Connect REPL to SQLite for further integration testing. Change-Id: Ie48a68eedf227dcf67d0262dd4672d53bbc6ec86 Reviewed-on: https://cl.tvl.fyi/c/depot/+/5345 Reviewed-by: wpcarro <wpcarro@gmail.com> Autosubmit: wpcarro <wpcarro@gmail.com> Tested-by: BuildkiteCI
-rw-r--r-- | users/wpcarro/scratch/simple-select/main.py | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/users/wpcarro/scratch/simple-select/main.py b/users/wpcarro/scratch/simple-select/main.py index eb674b79134e..45a96681c209 100644 --- a/users/wpcarro/scratch/simple-select/main.py +++ b/users/wpcarro/scratch/simple-select/main.py @@ -1,3 +1,4 @@ +import sqlite3 import string from scanner import Scanner from parser import Parser @@ -204,19 +205,25 @@ def compile_query(negate, query): # Main ################################################################################ +debug = False + def main(): + # TODO(wpcarro): Read path from command-line. + con = sqlite3.connect('/depot/users/wpcarro/todo-lists/imdb/db.sqlite3') + cur = con.cursor() + # TODO(wpcarro): Read columns from CSV. + columns = ["year", "rating", "haveWatched", "director", "isCartoon", "requiresSubtitles"] + while True: x = input("> ") - print("tokens:\t{}".format(tokenize(x))) - print("AST:\t{}".format(parse(x))) - # TODO(wpcarro): Read columns from CSV. - print("query:\t\"{}\"".format(compile(x, "Movies", [ - "year", - "rating", - "haveWatched", - "director", - "isCartoon", - "requiresSubtitles", - ]))) + + if debug: + print("tokens:\t{}".format(tokenize(x))) + print("AST:\t{}".format(parse(x))) + print("query:\t\"{}\"".format(compile(x, "Movies", columns))) + + for row in cur.execute(compile(x, "Movies", columns)): + print("\t".join(str(cell) for cell in row)) + if __name__ == "__main__": main() |