Forum OpenACS Development: Templating query porting questions

Collapse
Posted by Dave Bauer on
In porting the template::query calls in the clickthrough module I am
having a little problem.
<p>
I have named the queries and created the xql files. <p>
It looks like the sql is not making it to db_exec but I am not sure
why, template::query is getting it.
<p>
I get the following errors when I attempt to load the admin pages:

<pre>
Request Error
no value given for parameter "pre_sql" to "db_exec"
    while executing
"db_exec select nsdb0 dbqd.acs-templating.tcl.query-
procs.template::query.by_local_url  "
    invoked from within
"set __row [db_exec select nsdb0 dbqd.acs-templating.tcl.query-
procs.template::query.by_local_url  ]"
    ("uplevel" body line 1)
    invoked from within
"uplevel "set __row [db_exec select $db $full_statement_name $sql]""
    (procedure "template::query::multirow" line 7)
    invoked from within
"template::query::$type $statement_name $db $result_name  "
    invoked from within
"set ret_code [template::query::$type $statement_name $db
$result_name
                    $sql] "
    ("uplevel" body line 2)
    invoked from within
"uplevel 1 $code_block "
    invoked from within
"db_with_handle db {
      set ret_code [template::query::$type $statement_name $db
$result_name
                    $sql]
  }"
    (procedure "template::query" line 24)
    invoked from within
"template::query by_local_url urls multirow "
    select distinct local_url, foreign_url
      from clickthrough_log
    where package_id = :parent_p..."
    ("uplevel" body line 21)
    invoked from within
"uplevel {
          # www/admin/by-local-url.tcl

ad_page_contract {

    @author Philip Greenspun (mailto:philg@mit.edu)
    @creation-date 1997
    @cvs-id $I..."
    (procedure "code::tcl::/web/openacs-
4/packages/clickthrough/www/admin/by..." line 2)
    invoked from within
"code::tcl::$__adp_stub"
    invoked from within
"if { [file exists $__adp_stub.tcl] } {

      # ensure that data source preparation procedure exists and is
up-to-date
      adp_init tcl $__adp_stub
..."
    ("uplevel" body line 3)
    invoked from within
"uplevel {

    if { [file exists $__adp_stub.tcl] } {

      # ensure that data source preparation procedure exists and is
up-to-date
      adp_init t..."
    (procedure "adp_prepare" line 3)
    invoked from within
"adp_prepare "
    (procedure "template::adp_parse" line 31)
    invoked from within
"template::adp_parse [file root [ad_conn file]] {}"
    (procedure "adp_parse_ad_conn_file" line 7)
    invoked from within
"$handler"
    ("uplevel" body line 2)
    invoked from within
"uplevel $code"
    invoked from within
"ad_try {
    $handler
      } ad_script_abort val {
    # do nothing
      }"
    invoked from within
"rp_serve_concrete_file [ad_conn file]"
    (procedure "rp_serve_abstract_file" line 60)
    invoked from within
"rp_serve_abstract_file "$root/$path""
    ("uplevel" body line 2)
    invoked from within
"uplevel $code"
    invoked from within
"ad_try {
    rp_serve_abstract_file "$root/$path"
    set tcl_url2file([ad_conn url]) [ad_conn file]
    set tcl_url2path_info([ad_conn url]) [ad_conn path_inf..."

</pre>

Here is the query:
<pre>

template::query by_local_url urls multirow "
    select distinct local_url, foreign_url
      from clickthrough_log
    where package_id = :parent_package_id
    order by local_url"
</pre>

and the xql:

<pre>

&lt;?xml version="1.0"?&gt;
&lt;queryset&gt;
&lt;fullquery name="by_local_url"&gt;
        &lt;querytext&gt;

    select distinct local_url, foreign_url
      from clickthrough_log
    where package_id = :parent_package_id
    order by local_url

        &lt;/querytext&gt;
&lt;/fullquery&gt;
&lt;/queryset&gt;

</pre>

Collapse
Posted by Dan Wickstrom on
It looks like you have an old version of the template::query proc.  Have you done a cvs update lately?

Also, I just made a slight change to the wimpypoint presentation regarding the porting template db queries.  If a db call is made from within a proc, you need to make sure the proc is declared with ad_proc, or the query dispatcher won't work correctly.

This advice applies to any proc that uses the standard db api as well, but the templating queries seem to occur quite frequently in procs that were not declared using ad_proc.

Collapse
Posted by Dave Bauer on
That's what I thought too, so I did a cvs update and it didn't seem to help. I'll check more into it, and reread the porting information.
Collapse
Posted by Dan Wickstrom on
I'm sure that your backtrace shows an old version of template::query, so maybe something is hosed with your cvs setup.

Try doing a fresh checkout and compare your existing version of .../acs-templating/tcl/query-procs.tcl to the new checked-out version.

Collapse
Posted by Dave Bauer on
Surprise! I installed pgdriver-2.0 and it works now.

Apparently there is something in the new one that is not needed to install OpenACS, but is needed for those pages, because the rest of my installation went fine.

Collapse
Posted by Dan Wickstrom on
I've uploaded a new version of the query-extractor that handles templating db queries correctly.