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 Artin Petrossian <Ar...@sas.com> on 2008/05/20 21:38:41 UTC

setting table prefix in sql statement

Hi,

Is there a way to define a prefix for a table name in the sqlmap?  For example, let's say we have a simple select that uses a parameter:

<select id="findById" resultMap="projectLinkResult" parameterClass="java.lang.Long">
   SELECT projectId, customerName
   FROM projects
   WHERE projectId = #value#
</select>

Can I have a prefix value in front of "projects", so it would be something like:

<select id="findById" resultMap="projectLinkResult" parameterClass="java.lang.Long">
   SELECT projectId, customerName
   FROM $prefix$projects
   WHERE projectId = #value#
</select>

...and have that "prefix" value be defined in a property file or anywhere else?

I can't do this using parameter maps because this prefix needs to be applied globally to every table in all of my sqlmaps, and I only want to define it in one location.  I don't want to have to go and change all of my parameters to be maps that include both the original param value as well as this prefix value.

If this is not possible, is it something that will be possible to do in 3.0?

Thanks



RE: setting table prefix in sql statement

Posted by Artin Petrossian <Ar...@sas.com>.
Thanks Niels this is exactly what I needed.

-----Original Message-----
From: Niels Beekman [mailto:n.beekman@wis.nl]
Sent: Tuesday, May 20, 2008 3:54 PM
To: user-java@ibatis.apache.org
Subject: RE: setting table prefix in sql statement

See
http://www.mail-archive.com/user-java@ibatis.apache.org/msg09859.html

Niels

-----Original Message-----
From: Artin Petrossian [mailto:Artin.Petrossian@sas.com]
Sent: Tuesday, May 20, 2008 9:39 PM
To: user-java@ibatis.apache.org
Subject: setting table prefix in sql statement

Hi,

Is there a way to define a prefix for a table name in the sqlmap?  For
example, let's say we have a simple select that uses a parameter:

<select id="findById" resultMap="projectLinkResult"
parameterClass="java.lang.Long">
   SELECT projectId, customerName
   FROM projects
   WHERE projectId = #value#
</select>

Can I have a prefix value in front of "projects", so it would be
something like:

<select id="findById" resultMap="projectLinkResult"
parameterClass="java.lang.Long">
   SELECT projectId, customerName
   FROM $prefix$projects
   WHERE projectId = #value#
</select>

...and have that "prefix" value be defined in a property file or
anywhere else?

I can't do this using parameter maps because this prefix needs to be
applied globally to every table in all of my sqlmaps, and I only want to
define it in one location.  I don't want to have to go and change all of
my parameters to be maps that include both the original param value as
well as this prefix value.

If this is not possible, is it something that will be possible to do in
3.0?

Thanks




RE: setting table prefix in sql statement

Posted by Niels Beekman <n....@wis.nl>.
See
http://www.mail-archive.com/user-java@ibatis.apache.org/msg09859.html

Niels

-----Original Message-----
From: Artin Petrossian [mailto:Artin.Petrossian@sas.com] 
Sent: Tuesday, May 20, 2008 9:39 PM
To: user-java@ibatis.apache.org
Subject: setting table prefix in sql statement

Hi,

Is there a way to define a prefix for a table name in the sqlmap?  For
example, let's say we have a simple select that uses a parameter:

<select id="findById" resultMap="projectLinkResult"
parameterClass="java.lang.Long">
   SELECT projectId, customerName
   FROM projects
   WHERE projectId = #value#
</select>

Can I have a prefix value in front of "projects", so it would be
something like:

<select id="findById" resultMap="projectLinkResult"
parameterClass="java.lang.Long">
   SELECT projectId, customerName
   FROM $prefix$projects
   WHERE projectId = #value#
</select>

...and have that "prefix" value be defined in a property file or
anywhere else?

I can't do this using parameter maps because this prefix needs to be
applied globally to every table in all of my sqlmaps, and I only want to
define it in one location.  I don't want to have to go and change all of
my parameters to be maps that include both the original param value as
well as this prefix value.

If this is not possible, is it something that will be possible to do in
3.0?

Thanks