Forum OpenACS Development: Is the QD involved when db call is in an included file?

I encountered a template file in file-storage that uses the "include" tag. In this particular instance, the included file is a .tcl file (and its corresponding .adp template) that calls db_multirow. It seems to me that when a call to a db api is embedded in an included file, the QD is not involved. The actual code is more complicated, so I constructed a simpler case to illustrate QD's behavior (or my misunderstanding of it).

The main file, index.tcl, is very simple:

ad_return_template
So basically, it returns the template, index.adp. The template, index.adp, is also very simple, because it only sources a single file include.tcl:
<include src="include">
The include.tcl file contains a single call to db_string:
set a_date [db_string get_date "select sysdate() from dual"]
which is a very simple query (deliberately an oracle query). The corresponding template, include.adp, contains:
Date today is @a_date@.
which prints out the actual date. So how do we port the above query, contained in include.tcl, in postgresql? Well, I created the include- postgresql.xql file, which contains:
<?xml version="1.0"?>

<queryset>
   
<rdbms><type>postgresql</type><version>7.1<
/version></rdbms>

<fullquery name="get_date">
      <querytext>

       select now() from dual

      </querytext>

</fullquery>

</queryset>
However, loading the page index.tcl fails with an error that the query cannot be executed. Looking at the logs, it seems that the QD is not involved (or perhaps it is looking at the wrong file?). The only way I can make the error disappear is to put the postgresql query "select now() from dual" in the include.tcl file. The query in include-postgresql.xql seems unused.

Is this the right behavior of the QD? Or am I misunderstanding something here?

This looks a lot like a usage that wasn't expected when the QD was written.

For the heck of it, try putting the query in the index-postgresql.xql file and see if it finds it.  I bet it does, proving your theory ...

This is evil and something Ben will have to fix in his QD code.

I thought the include file included sub adp templates, not .tcl files. Are you sure this works at all? Here is the code for the include tag:

# Include another template in the current template

template_tag include { params } {

  set src [ns_set iget $params src]
  
  # pass additional arguments as key-value pairs

  set command "template::adp_parse"
  append command " [template::util::url_to_file "$src" "$__adp_stub"]"
  append command " [list"

  for { set i 0 } { $i < [ns_set size $params] } { incr i } {

    set key [ns_set key $params $i]
    if { [string equal $key src] } { continue }
    
    set value [ns_set value $params $i]

    append command " $key "$value"";	# is $value quoted sufficiently?
  }
  append command "]"

  template::adp_append_code "append __adp_output [$command]"
}


This is from acs-templating/tcl/tag-init.tcl

I just checked the source to file-storage and whoever wrote it certainly thinks it does ...
Argh.  QD actually works ok in my example above. The created include-postgresql.xql is read properly by QD, AFTER AOLSERVER IS RESTARTED (and I thought I did that!). Going out with friends and having some fun on a Friday night can do wonders to debugging. Sorry.  I feel like a moron now...
Oh ... sheesh.  That's good to hear!  When you're running with an existing set of package files you can "watch" tcl library and xql files and reload them either through the APM by hand or let  it do so automatically.

But the creation of new files ... hmmm ... you can find them and add them to your .info files but I don't think there's an option to source new tcl library or load new xql files.  I'll look into this, it would be useful.