From a847c3faa7822acc31157afbb6db7341283a5437 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 25 Jul 2024 17:45:11 +0800 Subject: [PATCH] bugfix --- dataloader/dataloader.py | 6 +++--- sqlor/sor.py | 18 +++++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/dataloader/dataloader.py b/dataloader/dataloader.py index 04e0cc5..f072f15 100755 --- a/dataloader/dataloader.py +++ b/dataloader/dataloader.py @@ -13,11 +13,11 @@ class CBObject: async def handle(self,ws): db = DBPools() + info = None async with db.sqlorContext(self.db) as sor: - delete_sql = "TRUNCATE TABLE %s" % self.tbl - await sor.sqlExe(delete_sql, {}) info = await sor.I(self.tbl) - for rec in getRecord(ws): + for rec in getRecord(ws): + async with db.sqlorContext(self.db) as sor: r = [ v for v in rec.values() if v is not None ] if len(r) == 0: continue diff --git a/sqlor/sor.py b/sqlor/sor.py index 717c495..c3ff810 100755 --- a/sqlor/sor.py +++ b/sqlor/sor.py @@ -609,8 +609,10 @@ class SQLor(object): sql = 'insert into %s.%s (%s) values (%s)' % (self.dbname, tablename,fns,vfns) rf = RegisterFunction() rfname = f'{self.dbname}:{tablename}:c:before' - ns = await rf.exe(rfname, ns) - r = await self.runSQL({'sql_string':sql},ns,None) + ret = await rf.exe(rfname, ns) + if isinstance(ret, dict): + ns.update(ret) + r = await self.runSQL({'sql_string':sql},ns.copy(), None) await rf.exe(f'{self.dbname}:{tablename}:c:after', ns) return r @@ -658,10 +660,10 @@ class SQLor(object): sql = 'update %s.%s set %s where %s' % (self.dbname, tablename, u_str,c_str) rf = RegisterFunction() - ns = await rf.exe(f'{self.dbname}:{tablename}:u:before',ns) - if func: - ns = func(ns) - r = await self.runSQL({'sql_string':sql},ns,None) + ret = await rf.exe(f'{self.dbname}:{tablename}:u:before',ns) + if isinstance(ret, dict): + ns.update(ret) + r = await self.runSQL({'sql_string':sql},ns.copy() ,None) await rf.exe(f'{self.dbname}:{tablename}:u:after',ns) return r @@ -673,7 +675,9 @@ class SQLor(object): c_str = ' and '.join(c) sql = 'delete from %s.%s where %s' % (self.dbname, tablename,c_str) rf = RegisterFunction() - ns = await rf.exe(f'{self.dbname}:{tablename}:d:before', ns) + ret = await rf.exe(f'{self.dbname}:{tablename}:d:before', ns) + if isinstance(ret, dict): + ns.update(ret) r = await self.runSQL({'sql_string':sql},ns,None) ns = await rf.get(f'{self.dbname}:{tablename}:d:after', ns) return r