From 5a60c34cf8d486c1c2a27c51350e868b3ee82a4d Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 22 Jul 2021 11:11:02 +0800 Subject: [PATCH] bugfix --- sqlor/runsql.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 sqlor/runsql.py diff --git a/sqlor/runsql.py b/sqlor/runsql.py new file mode 100644 index 0000000..93b98d1 --- /dev/null +++ b/sqlor/runsql.py @@ -0,0 +1,35 @@ +#!/usr/bin/python3 +import sys +import codecs +from sqlor.dbpools import runSQL +import asyncio + +def appinit(): + if len(sys.argv) < 4: + print(f'usage:\n {sys.argv[0]} path dbname sqlfile [k=v ...] \n') + sys.exit(1) + p = ProgramPath() + if len(sys.argv) > 1: + p = sys.argv[1] + config = getConfig(p) + DBPools(config.databases) + + +async def run(ns): + with codecs.open(sys.argv[3], 'r', 'utf-8') as f: + sql = f.read() + await runSQL(sys.argv[2], sql, ns) + +if __name__ == '__main__': + ns = {} + for x in sys.argv[3:]: + try: + k,v = x.split('=') + ns.update({k:v}) + except Exception as e: + print(x, 'key-value pair expected') + print(e) + + appinit() + loop = asyncio.get_event_loop() + loop.run_until_complete(run(ns))