cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From solprovi...@apache.org
Subject Re: Cocoon database access strategy
Date Wed, 04 Jul 2007 15:54:40 GMT
On 7/4/07, Tobia <tobia.conforto@linux.it> wrote:
> Here's a followup for the fellow users who build their queries with XSLT.
>
> I found the question-mark + sql:in-parameter syntax a bit inconvenient,
> especially when the query is composed out of building blocks in XSLT:
>
>         <sql:query>
>           SELECT ...
>           FROM ...
>           WHERE ...
>           <xsl:if test="$name and $filter-name">
>             AND name = ?
>           </xsl:if>
>         </sql:query>
>
>         <xsl:if test="$name and $filter-name">
>           <sql:in-parameter nr="1" value="{$name}"/>
>         </xsl:if>
>
> As you can see, this approach is a maintainability nightmare: think of a
> 50 line query with dozens of parameters.
>
> So I came up with this solution, which works very well for me.
> It's somewhat similar in usage to <esql:parameter>:
>
>         <sql:query>
>           SELECT ...
>           FROM ...
>           WHERE ...
>           <xsl:if test="$name and $filter-name">
>             AND name = <sql:param value="{$name}"/>
>           </xsl:if>
>         </sql:query>
>
> This is processed by an additional XSLT transformer before being fed to
> the SQL transformer:
>
>         <xsl:template match="sql:query">
>           <xsl:copy>
>             <xsl:apply-templates select="@*|node()"/>
>           </xsl:copy>
>           <xsl:for-each select=".//sql:param">
>             <sql:in-parameter value="{@value}" nr="{position()}"/>
>           </xsl:for-each>
>         </xsl:template>
>
>         <xsl:template match="sql:param">
>           <xsl:text>?</xsl:text>
>         </xsl:template>
>
> I think it would be useful to include this functionality in the SQL
> transformer itself.
>
> Tobia

I like it.  Add priority="2" to the first match to make certain
sql:in-parameter elements are created before the sql:param are changed
to question marks.

solprovider

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message