You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Stefan Hübner <st...@googlemail.com> on 2007/02/22 16:29:31 UTC
SQLTransformer vs. column aliases
Hello,
I run into a problem using SQLTransformer regarding multiple columns
with same name in a joint sql select. how can I assign cutomized names
to columns of a sql result?
Here's an example of what I get so far:
my query looks like this:
<sql:query>
select a.name, a.id, b.id, b.name
from a, b
where a.b_id = b.id
</sql:query>
the results I get look like this:
<sql:rowset>
<sql:row>
<sql:id>19</sql:id>
<sql:name>a's name</sql:name>
<sql:id>23</sql:id>
<sql:name>b's name</sql:name>
</sql:row>
<sql:row>
<sql:id>10</sql:id>
<sql:name>a's name</sql:name>
<sql:id>23</sql:id>
<sql:name>b's name</sql:name>
</sql:row>
...
</sql:rowset
thanks for any hints!
-Stefan
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: SQLTransformer vs. column aliases
Posted by Stefan Hübner <st...@googlemail.com>.
I actually found the reason for this behaviour. MySQL Connector/J
5.x's implementation has been changed not to return column labels but
their names, that is the original columns' names. According to
http://bugs.mysql.com/bug.php?id=21596, the reason for changing the
implementation was to make it more JDBC compliant. So it's not a bug,
it's actually a feature.
Since SQLTransformer uses getColumnName(), no column aliases make it
into the output. Should SQLTransformer's implementation be altered
then?
Those who use MySQL Connector/J 5.x and rely on aliases should use the
useOldAliasMetadataBehavior-option in their jdbc-URL. This works from
Connector/J 5.0.4 onward.
Thanks again, Tobia, for pointing me in that direction!
-Stefan
2007/2/22, Stefan Hübner <st...@googlemail.com>:
> Thanks Tobia,
>
> I'm working with MySQL too. Maybe I should have a look at their docu.
>
> -Stefan
>
> 2007/2/22, Tobia <to...@linux.it>:
> > Stefan Hübner wrote:
> > > Dev at weitling <de...@weitling.net>:
> > > > select a.name as aName, a.id as aID, b.id as bID, b.name as bName
> > >
> > > no, disappointingly enough, that doesn't work.
> >
> > It works here, using MySQL.
> > Maybe it depends on the SQL engine?
> >
> > If you can't get the "as" keyword to work, you can always use some XSLT
> > to tell them apart or to rename them:
> >
> > <xsl:template match="sql:rowset/sql:row/sql:id[position() = 1]">
> >
> > <xsl:template match="sql:rowset/sql:row/sql:id[position() = 2]">
> >
> >
> > Tobia
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> > For additional commands, e-mail: users-help@cocoon.apache.org
> >
> >
>
Re: SQLTransformer vs. column aliases
Posted by Stefan Hübner <st...@googlemail.com>.
Thanks Tobia,
I'm working with MySQL too. Maybe I should have a look at their docu.
-Stefan
2007/2/22, Tobia <to...@linux.it>:
> Stefan Hübner wrote:
> > Dev at weitling <de...@weitling.net>:
> > > select a.name as aName, a.id as aID, b.id as bID, b.name as bName
> >
> > no, disappointingly enough, that doesn't work.
>
> It works here, using MySQL.
> Maybe it depends on the SQL engine?
>
> If you can't get the "as" keyword to work, you can always use some XSLT
> to tell them apart or to rename them:
>
> <xsl:template match="sql:rowset/sql:row/sql:id[position() = 1]">
>
> <xsl:template match="sql:rowset/sql:row/sql:id[position() = 2]">
>
>
> Tobia
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
Re: SQLTransformer vs. column aliases
Posted by Tobia <to...@linux.it>.
Stefan Hübner wrote:
> Dev at weitling <de...@weitling.net>:
> > select a.name as aName, a.id as aID, b.id as bID, b.name as bName
>
> no, disappointingly enough, that doesn't work.
It works here, using MySQL.
Maybe it depends on the SQL engine?
If you can't get the "as" keyword to work, you can always use some XSLT
to tell them apart or to rename them:
<xsl:template match="sql:rowset/sql:row/sql:id[position() = 1]">
<xsl:template match="sql:rowset/sql:row/sql:id[position() = 2]">
Tobia
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: SQLTransformer vs. column aliases
Posted by Stefan Hübner <st...@googlemail.com>.
Hi Dev,
no, disappointingly enough, that doesn't work. I tried that having no luck.
2007/2/22, Dev at weitling <de...@weitling.net>:
> Hello Stefan,
>
> I don't know if it works but gives this a try:
>
> <sql:query>
> select a.name as aName, a.id as aID, b.id as bID, b.name as bName
> from a, b
> where a.b_id = b.id
> </sql:query>
>
> Bye,
> Florian
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: SQLTransformer vs. column aliases
Posted by Dev at weitling <de...@weitling.net>.
Hello Stefan,
I don't know if it works but gives this a try:
<sql:query>
select a.name as aName, a.id as aID, b.id as bID, b.name as bName
from a, b
where a.b_id = b.id
</sql:query>
Bye,
Florian
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org