This commit is contained in:
yumoqing 2020-05-15 21:11:45 +08:00
parent 2f89d1e4b9
commit d5a53f2e53
2 changed files with 19 additions and 12 deletions

View File

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

View File

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