From f75c6f72f440cab5d2d7509facebdc4cb62040f9 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 16 Nov 2022 01:30:31 +0800 Subject: [PATCH] fix bug in ddl template fro ddl --- sqlor/dbpools.py | 11 +++++++---- sqlor/ddl_template_sqlite3.py | 4 ++-- test/sqilit3_sql.py | 36 ----------------------------------- 3 files changed, 9 insertions(+), 42 deletions(-) delete mode 100644 test/sqilit3_sql.py diff --git a/sqlor/dbpools.py b/sqlor/dbpools.py index abe2fbc..f206b6d 100755 --- a/sqlor/dbpools.py +++ b/sqlor/dbpools.py @@ -235,13 +235,16 @@ class DBPools: cur = None if self.isAsyncDriver(dbname): if dbdesc['driver'] == 'sqlite3': - conn = await driver.connect(dbdesc['kwargs']['dbname']) - else: - conn = await driver.connect(**dbdesc['kwargs']) + conn = await driver.connect(dbdesc['kwargs']['dbname']) + else: + conn = await driver.connect(**dbdesc['kwargs']) cur = await conn.cursor() return True,conn,cur else: - conn = driver.connect(**dbdesc.kwargs) + if dbdesc['driver'] == 'sqlite3': + conn = driver.connect(dbdesc['kwargs']['dbname']) + else: + conn = driver.connect(**dbdesc['kwargs']) cur = conn.cursor() return False,conn,cur diff --git a/sqlor/ddl_template_sqlite3.py b/sqlor/ddl_template_sqlite3.py index 2102217..6d6eca6 100755 --- a/sqlor/ddl_template_sqlite3.py +++ b/sqlor/ddl_template_sqlite3.py @@ -1,4 +1,4 @@ -sqlite_ddl_tmpl = """{% macro typeStr(type,len,dec) %} +sqlite3_ddl_tmpl = """{% macro typeStr(type,len,dec) %} {%- if type in ['str', 'char', 'date', 'time', 'datetime', 'timestamp'] -%} TEXT {%- elif type in ['long', 'int', 'short', 'longlong' ] -%} @@ -23,7 +23,7 @@ drop table if exists {{summary[0].name}}; CREATE TABLE {{summary[0].name}} ( {% for field in fields %} - `{{field.name}}` {{typeStr(field.type,field.length,field.dec)}} {{nullStr(field.nullable)}} {%if field.title -%} -- {{field.title}}{%- endif %}{%- if not loop.last -%},{%- endif -%} + `{{field.name}}` {{typeStr(field.type,field.length,field.dec)}} {{nullStr(field.nullable)}}{%- if not loop.last -%},{%- endif -%} {%if field.title -%} -- {{field.title}}{%- endif %} {% endfor %} {% if summary[0].primary and len(summary[0].primary)>0 %} {{primary()}} diff --git a/test/sqilit3_sql.py b/test/sqilit3_sql.py deleted file mode 100644 index 306baf0..0000000 --- a/test/sqilit3_sql.py +++ /dev/null @@ -1,36 +0,0 @@ - -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()) - -