Re: Re: dynamic queries
[email protected] Sat, 2 Dec 2006 14:29:37 +0000 (GMT)
| Newsgroups | gmane.text.xml.o-xml |
|---|---|
| Message-ID | <[email protected]> |
On 21 Nov 2006, at 1:10, Tomasz Rakowski wrote:
I would like to create general purpose function which will take two parameters:
SQL Query and name of the column. Function should execute given query and from
ResultSet it should return data from given column name.
Tomasz,
I misunderstood the issue - you could try something like:
<o:function name="getfield">
<o:param name="query"/>
<o:param name="fieldname"/>
<o:do>
<o:variable name="results">
<db:execute sql="{$query}">
<field1>{$field1}</field1>
<field2>{$field2}</field2>
<field3>{$field3}</field3>
</db:execute>
</o:variable>
<o:return select="$results/*[name() = $fieldname]/text()"/>
</o:do>
</o:function>
Of course, if you don't know the different column names (field1, field2 etc) when you write the function then this won't work.
The other (harder!) alternative is to use the Java extensions to execute a query and access the JDBC ResultSet directly.
hth,
/m