[ic] Set variable to query result at start-up?

Kevin Walsh kevin at cursor.biz
Thu Feb 14 18:59:19 EST 2008


Jeff Boes <jeff at endpoint.com> wrote:
> I'm curious if anyone's done this before, and if there are any clever or
> canned approaches:
> 
> I would like to initialize an Interchange variable to the result of a
> SQL query, at IC startup (because the query could be a bit costly to run
> per page or even per session). Specifically, I want to set:
> 
> UI_DATE_BEGIN
> 
> to the first year represented by transactions.order_date, e.g.,
> 
> select min(to_date(order_date,'YYYY')) from transactions;
> 
> The only approach I've thought up (which I haven't tried yet) would be
> to define a module with a BEGIN block[1], and "Require" it in the
> interchange.cfg or catalog.cfg. Are there other approaches?
> 
> [1] I'm not entirely sure this would run at the appropriate point, i.e.,
> after the database connection is established.
> 
I'm a sneaky little bugger, so I'd create a small Perl script that
pulls the value from the table and writes it to a file called
"UI_DATE_BEGIN" in a "DirConfig Variable" directory (you probably
already have one called "variables").

When the website is started or reconfigured, the file will be read
and the variable will be initialised with its content (a date in
this case).

You could either call the Perl script from within the Interchange
startup script, or you could put it in cron.  If it was in cron then
it could run every day, and could also be made to instruct Interchange
to reconfigure the website at the same time.

Don't write a CR at the end of the value, by the way, or it might cause
problems when that particular variable is used in the Vend::Form module.

-- 
   _/   _/  _/_/_/_/  _/    _/  _/_/_/  _/    _/
  _/_/_/   _/_/      _/    _/    _/    _/_/  _/   K e v i n   W a l s h
 _/ _/    _/          _/ _/     _/    _/  _/_/    kevin at cursor.biz
_/   _/  _/_/_/_/      _/    _/_/_/  _/    _/


More information about the interchange-users mailing list