Using table.super() in hooks
When using the table.super() function within hooks, developers should be aware that recursive calls may occur if the standard logic subsequently updates the same table.
To prevent this, it is recommended to declare the mode argument as optional and retrieve it dynamically using the get.long.arg() function. This pattern ensures compatibility with both DAL_NEW and DAL_UPDATE modes, while avoiding recursion or fatal errors during standard background updates.
Note: Declare all variables in this function as static to retain their values across recursive or repeated calls, avoid unintended side effects, and ensure stable behavior during hook execution.
Example:
function extern long after.save.object(...)
{
static long mode
static long ret
mode = 0
ret = 0
if get.argc() >= 1 then
mode = get.long.arg(1)
endif
table.super()
on case mode
case DAL_NEW:
break
case DAL_UPDATE:
with.old.object.values.do(get.old.values)
if tcmcs004.cdf_city <> old.city then
ret = txcomdll0001.log.city.change(old.city, tcmcs004.cdf_city)
if ret < 0 then
dal.set.error.message("@Error during logging city change")
return(DALHOOKERROR)
endif
endif
endcase
return(0)
}
This approach helps maintain stable behavior when the standard Data Access Layer logic re-triggers table updates internally.