Re: db:execute context

[email protected] Tue, 14 Nov 2006 11:02:16 +0000 (GMT)
Newsgroups gmane.text.xml.o-xml
Message-ID <[email protected]>
Hi Tomasz,

I'll try give a quick answer to this -

With the o:XML db extensions, all local and type variables (ie all variables!) are out-of-scope within the result template of a SQL query. Only the db result set values are available, as variables. This is by design, in order to avoid conflicts. Otherwise local variables and type variables may be accidentally reassigned, which could get very confusing. If you think this is not the way it should be, pls advice as to your preferred solution!

The workaround you've found is not a bad one, though you can make it a little easier for yourself using attribute value substitution:

    <o:function name="Fun">
        <o:param name="param1"/>
        <o:do>
            <o:variable name="var1" select="'value'"/>
            <db:execute sql="SELECT attr1, attr2, ..., {$param1} as param1, {$var11} as var1 FROM table">
               NOW I CAN ACCESS here parameter param1  and variable var1.
            </db:execute>
        </o:do>
    </o:function>

remember that string values have to be quoted, eg with the db:quote() function:

          <db:execute sql="SELECT {db:quote($param1)} as param1">
               NOW I CAN ACCESS here parameter param1
          </db:execute>


hope this helps!

/m