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

View File

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