Forum OpenACS Development: Postgres functions callbacks?

Collapse
Posted by Malte Sussdorff on
Does anyone know if there is a concept in postgres which allows us to use something like the callbacks in OpenACS in the procedures and functions (PL/pgsql)?

I'm asking because I have an application (]po[) which uses the stored procedures to do the inserting into multiple tables at once. Therefore the trigger on the DB table does not work as I would have to collect the data from multiple tables in order. And if the last table is acs_objects that would make the idea useless. Having something like a trigger on functions (before call, after call) or the callback mechanism in OpenACS would therefore be very handy.

Collapse
Posted by Dave Bauer on
Or simpler, wrap the plsql calls in a tcl procedure and add a callback on that.
Collapse
Posted by Malte Sussdorff on
Yes, obviously I would do that, but if you take a look at ]po[ that would mean to exchange it in nearly the whole code base. And if I were to go down that road (and Frank would allow that), I would use "xo::db::sql::im_project new" directly e.g. for the im_project__new function. The moment I use the xo::db functions I could use mixin classes or filters to achieve my goal.
Collapse
Posted by Tom Jackson on
I have an idea for postgres plpgsql: create a new pl function with the same name, but an additional param, a switch to do something else. You can write a new body to do whatever you want. Then you can use the old and new version anywhere.

If you use something like ttrace, you modify every call of the function.

Collapse
Posted by Dave Bauer on
The old site-wide-seach and acs-service package also implemented someting similar in pl/sql (oracle only). It was insanely complex though and wrote all the pl/sql dynamically if I recall correctly.

I like Tom's idea. Works great with postgresql.

Another option is to use an insert view and rule like the content repository. That probably doesn't really get you where you need to go. I think either Tcl with callbacks or an something with xotcl is the only maintianable solution.

Collapse
Posted by Tom Jackson on
Obviously not an expert in xotcl, but this should be exactly the application for it in Tcl. Do you end up with a different command after this in xotcl, or can you still access the previous command?
Collapse
Posted by Gustaf Neumann on
the original command (the method being called) is not altered. xotcl interceptors allow to perform some action before the intercepted call and after the intercepted call. The interceptors can be dynamically added and removed, and they can be stacked.