This commit is contained in:
yumoqing 2024-07-25 17:45:11 +08:00
parent 68d04054ca
commit a847c3faa7
2 changed files with 14 additions and 10 deletions

View File

@ -13,11 +13,11 @@ class CBObject:
async def handle(self,ws): async def handle(self,ws):
db = DBPools() db = DBPools()
info = None
async with db.sqlorContext(self.db) as sor: 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) 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 ] r = [ v for v in rec.values() if v is not None ]
if len(r) == 0: if len(r) == 0:
continue continue

View File

@ -609,8 +609,10 @@ class SQLor(object):
sql = 'insert into %s.%s (%s) values (%s)' % (self.dbname, tablename,fns,vfns) sql = 'insert into %s.%s (%s) values (%s)' % (self.dbname, tablename,fns,vfns)
rf = RegisterFunction() rf = RegisterFunction()
rfname = f'{self.dbname}:{tablename}:c:before' rfname = f'{self.dbname}:{tablename}:c:before'
ns = await rf.exe(rfname, ns) ret = await rf.exe(rfname, ns)
r = await self.runSQL({'sql_string':sql},ns,None) 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) await rf.exe(f'{self.dbname}:{tablename}:c:after', ns)
return r return r
@ -658,10 +660,10 @@ class SQLor(object):
sql = 'update %s.%s set %s where %s' % (self.dbname, tablename, sql = 'update %s.%s set %s where %s' % (self.dbname, tablename,
u_str,c_str) u_str,c_str)
rf = RegisterFunction() rf = RegisterFunction()
ns = await rf.exe(f'{self.dbname}:{tablename}:u:before',ns) ret = await rf.exe(f'{self.dbname}:{tablename}:u:before',ns)
if func: if isinstance(ret, dict):
ns = func(ns) ns.update(ret)
r = await self.runSQL({'sql_string':sql},ns,None) r = await self.runSQL({'sql_string':sql},ns.copy() ,None)
await rf.exe(f'{self.dbname}:{tablename}:u:after',ns) await rf.exe(f'{self.dbname}:{tablename}:u:after',ns)
return r return r
@ -673,7 +675,9 @@ class SQLor(object):
c_str = ' and '.join(c) c_str = ' and '.join(c)
sql = 'delete from %s.%s where %s' % (self.dbname, tablename,c_str) sql = 'delete from %s.%s where %s' % (self.dbname, tablename,c_str)
rf = RegisterFunction() 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) r = await self.runSQL({'sql_string':sql},ns,None)
ns = await rf.get(f'{self.dbname}:{tablename}:d:after', ns) ns = await rf.get(f'{self.dbname}:{tablename}:d:after', ns)
return r return r