You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Cristiano Monteiro dos Santos <cs...@polimed.com.br> on 2006/06/19 21:46:15 UTC

Appending strings to query

Hi again, guys.

I have another question: is it possible to append string snippets to the
iBATIS's xml queries? I mean, I have several databases, each of then
containing the same set of tables, following the schema
#databasename#:tb#customerid#user (not telling if it's right or wrong, it's
fact), and I want to execute the queries sometimes in one database,
sometimes in the other. Like this:

select f1, f2, f3
#databasename#:tb#customerid#user

Resulting in the following query:
select f1, f2, f3
custname:tb123user

Where #databasename# and #customerid# are both attributes of the
parameterClass. Am I expecting too much?

Thanks!
Cristiano

Re: Appending strings to query

Posted by Ted Schrader <ts...@gmail.com>.
Hi Cristiano,

No, it's not too much to expect.  I've had to do something similar,
although probably not as complicated as your situation.

Here's an example:

SELECT NUMBER, DESCRIPTION
  FROM $dbName$.ITEMS

My application spans multiple databases (actually, multiple iSeries
libraries) and this has worked out okay, since all of our ITEMS tables
have identical definitions (not my schema!).

Note that we have to use the $ symbol, not #.  Also, when using $, be
sure your values are SQL-escaped to avoid injection attacks.  In my
case, the dbName variable is managed internally by the application.

Also, I recommend you get familiar with the remapResults="true"
setting in case it applies to your situation:
http://opensource.atlassian.com/confluence/oss/pages/viewpage.action?pageId=3057

Cheers!

Ted


On 19/06/06, Cristiano Monteiro dos Santos <cs...@polimed.com.br> wrote:
> Hi again, guys.
>
> I have another question: is it possible to append string snippets to the
> iBATIS's xml queries? I mean, I have several databases, each of then
> containing the same set of tables, following the schema
> #databasename#:tb#customerid#user (not telling if it's right or wrong, it's
> fact), and I want to execute the queries sometimes in one database,
> sometimes in the other. Like this:
>
> select f1, f2, f3
> #databasename#:tb#customerid#user
>
> Resulting in the following query:
> select f1, f2, f3
> custname:tb123user
>
> Where #databasename# and #customerid# are both attributes of the
> parameterClass. Am I expecting too much?
>
> Thanks!
> Cristiano
>