Forum OpenACS Development: Re: Res: Major revision of the XOTcl interface to the Content Repository and to ACS objects and ACS Object Types in general

So the recommended "solution" would be to only define the function_args for the largest function, as we usually (always?) only add more parameters and not have two equally named functions where one had other attributes than the other?

Oracle's plsql interface is very nice and friendly when you want to create an object layer like these. It handles multiple functions of the same name, different defaults for the arguments, and the argument order is not important. That means that usually the developer doesn't have to go back and look at the signature, Oracle will decide which proc to use. How does it do this? The function calls include the names of the attributes along with the value. In postgres it is like a Tcl call. So the only thing you need to mimic the behavior for postgres is the name of the arguments, their position in each function (the function signature), and any defaults for optional attributes, plus a way of choosing which function to call given the information.

By a strange fluke, code exists in OpenACS which does exactly this. A tiny subset of query-writer is in the cronjob package, just a few procedures, with examples for setup and use. It doesn't use the database. I wrote this code to specifically aid porting from Oracle to Postgres. Here is an example of the original oracle, and the postgres:


begin
  cronjob.set_attrs(
    cronjob_id => :cronjob_id,
    description => :description,
    approved_p => :approved_p,
    disabled_p => :disabled_p,
    minute => :minute,
    hr => :hr,
    mon => :mon,
    day => :day,
    dayofweek => :dayofweek,
    run_sql => :run_sql,
    run_tcl => :run_tcl,
    email => :email);
end;
select [qd_write_query_select cronjob__set_attrs {
  cronjob_id => :cronjob_id
  description => :description
  approved_p => :approved_p
  disabled_p => :disabled_p
  minute => :minute
  hr => :hr
  mon => :mon
  day => :day
  dayofweek => :dayofweek
  run_sql => :run_sql
  run_tcl => :run_tcl
  email => :email } ]

The current version of the code in cronjob is here:

http://rmadilo.com/files/cronjob/cronjob/tcl/

Usage is in the www/admin directory. Mostly current code is also in CVS.

It is important to point out that you can submit a subset of the arguments as long as you provide all the params which don't have defaults, for instance, when creating a new object, the object_id has a default of null, meaning that the function will create a new acs_object first, so you don't have to look at the function signatures before writing a query. This is exactly similar to Oracle. Also, each function can have different parameter defaults, different from the same attribute in other functions of the same name.