Forum OpenACS Development: xotcl and xql files

Collapse
Posted by Matthew Dodwell on
I'm doing a test project using xotcl-note as a basis and was wanting to put my sql in an xql file but this doesn't seem to work as the xql is not found. Embedding the sql everything works;

Works;
CrQuote ad_instproc getOneQuote {
    {-quotename:required}
    {-quoteauthor:required}
} {
    Get a random quote from the database
} {
    upvar 1 $quotename name
    upvar 1 $quoteauthor quote_author

    db_1row get_random_quote "select quote_author, name from xotcl_cr_ea_quotesx order by random() limit 1 "

    return
}

but changing
db_1row get_random_quote "select quote_author, name from xotcl_cr_ea_quotesx order by random() limit 1 "
to
db_1row get_random_quote {}

with the following xql

<?xml version="1.0"?>
<queryset>

    <fullquery name="get_random_quote">
        <querytext>
            select quote_author, name
            from  xotcl_cr_ea_quotesx
            order by random limit 1
        </querytext>
    </fullquery>

</queryset>

fails with statement not found.

Does ad_instproc interfere with the xql mechanism?

cheers
  Matthew

Collapse
2: Re: xotcl and xql files (response to 1)
Posted by Gustaf Neumann on
the xql naming is not object orientation aware. xql was designed and implemented based with functions/procs, not with methods. if you want to use xql for now, the easiest thing is to use a small "classic oacs" ad_proc layer. It might also be possible to use manually constructed fully qualified query names (i.e. starting with "dbqd.").

btw., the upvar statements do not look like good oo style to me. From an oo point of view, one would create an quote object in memory with the appropriate instance variables bound to the returned variables from SQL.