From 992665f9ec123338cff19736674af75eed539fcf Mon Sep 17 00:00:00 2001 From: yumoqing Date: Tue, 15 Nov 2022 08:31:11 +0800 Subject: [PATCH] fix connect arguments for sqlite3 --- sqlor/dbpools.py | 5 ++++- test/sqilit3_sql.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 test/sqilit3_sql.py diff --git a/sqlor/dbpools.py b/sqlor/dbpools.py index 5c3447a..abe2fbc 100755 --- a/sqlor/dbpools.py +++ b/sqlor/dbpools.py @@ -234,7 +234,10 @@ class DBPools: conn = None cur = None if self.isAsyncDriver(dbname): - conn = await driver.connect(**dbdesc['kwargs']) + if dbdesc['driver'] == 'sqlite3': + conn = await driver.connect(dbdesc['kwargs']['dbname']) + else: + conn = await driver.connect(**dbdesc['kwargs']) cur = await conn.cursor() return True,conn,cur else: diff --git a/test/sqilit3_sql.py b/test/sqilit3_sql.py new file mode 100644 index 0000000..306baf0 --- /dev/null +++ b/test/sqilit3_sql.py @@ -0,0 +1,36 @@ + +import sys +import os +import asyncio +from sqlor.dbpools import DBPools + +async def exesqls(sqllines): + sqls = txt.split(';') + async with DBpools.sqlorContext('db') as sor: + for sql in sqls: + await sor.sqlExe(sql, {}) + +async def main(): + with codecs.open(sys.argv[2],'r', 'utf-8') as f: + txt = f.read() + await exesql(txt) + +dbs = { + "db":{ + "driver":"sqlite3", + "kwargs":{ + "dbname":sys.argv[1] + } + } +} + +if __name__ == '__main__': + if len(sys.argv) < 3: + print(f'Usage:{sys.argv[0]} sqlite3_db_file sqlfile') + sys.exit(1) + + DBPools(dbs) + loop = asyncio.get_event_loop() + loop.run_until_complete(main()) + +