fix connect arguments for sqlite3

This commit is contained in:
yumoqing 2022-11-15 08:31:11 +08:00
parent aac61c2bb3
commit 992665f9ec
2 changed files with 40 additions and 1 deletions

View File

@ -234,6 +234,9 @@ class DBPools:
conn = None
cur = None
if self.isAsyncDriver(dbname):
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

36
test/sqilit3_sql.py Normal file
View File

@ -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())