From d5a53f2e53eadeb8df3c3f23cf8a61189b72ebba Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 15 May 2020 21:11:45 +0800 Subject: [PATCH] bugfix --- sqlor/dbpools.py | 9 ++++++--- sqlor/sor.py | 22 +++++++++++++--------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/sqlor/dbpools.py b/sqlor/dbpools.py index f27ce24..f24beb3 100644 --- a/sqlor/dbpools.py +++ b/sqlor/dbpools.py @@ -1,5 +1,6 @@ import asyncio +from traceback import print_exc from functools import wraps import codecs @@ -198,12 +199,14 @@ class DBPools: sqlor = await self.getSqlor(name) try: yield sqlor - except: + except Exception as e: + print_exc() + print('Exeception=',e) if sqlor and sqlor.dataChanged: - sqlor.rollback() + await sqlor.rollback() finally: if sqlor and sqlor.dataChanged: - sqlor.commit() + await sqlor.commit() await self.freeSqlor(sqlor) async def _aquireConn(self,dbname): diff --git a/sqlor/sor.py b/sqlor/sor.py index 6728711..6f2569e 100644 --- a/sqlor/sor.py +++ b/sqlor/sor.py @@ -1,4 +1,5 @@ import os +from asyncio import coroutine os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8' import sys import codecs @@ -393,12 +394,9 @@ class SQLor(object): await self.execute(desc,NS,None) async def sqlExe(self,sql,ns): - desc = { - "sql_string":sql - } ret = [] - await self.execute(desc,ns, - callback=lambda(x):ret.append(DictObject(**x))) + await self.execute(sql,ns, + callback=lambda x:ret.append(DictObject(**x))) return ret async def tables(self): @@ -481,10 +479,16 @@ class SQLor(object): desc['validation'].append(idx) return desc - def rollback(self): - self.conn.rollback() + async def rollback(self): + if self.async_mode: + await self.conn.rollback() + else: + self.conn.rollback() self.dataChanged = False - def commit(self): - self.conn.commit() + async def commit(self): + if self.async_mode: + await self.conn.commit() + else: + self.conn.commit() self.datachanged = False