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 Rob Butler <cr...@yahoo.com> on 2005/05/30 07:02:31 UTC

is this possible?

I want to create a statement that performs inserts (or
updates, or creates tables) that can have the table
name as well as the number and type of the columns
determined at run time.

Assume a Map has two entries, tableName and records. 
Records is a List of record objects.  Record objects
have 3 values, fieldName, value and type.  fieldName
is the name of the column, and type is the JDBC type
of the column.  Value is always either a Date, Integer
(object, not primative), Long (object, not primative)
or String.

So assuming everything above, would the sqlMap segment
below work?

<insert id="insertRecord"
parameterClass="java.util.Map">
   insert into $tableName$ 
     <iterate open="(" close=")" conjunction=", ">
       $records[].fieldName$
     </iterate>
   values
     <iterate open="(" close=")" conjunction=", ">
       #records[].value#:$records[].type$
     </iterate>
</insert>

Thanks!
Rob

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: is this possible?

Posted by Larry Meadors <la...@gmail.com>.
Did you try it?

On 5/29/05, Rob Butler <cr...@yahoo.com> wrote:
> I want to create a statement that performs inserts (or
> updates, or creates tables) that can have the table
> name as well as the number and type of the columns
> determined at run time.
> 
> Assume a Map has two entries, tableName and records.
> Records is a List of record objects.  Record objects
> have 3 values, fieldName, value and type.  fieldName
> is the name of the column, and type is the JDBC type
> of the column.  Value is always either a Date, Integer
> (object, not primative), Long (object, not primative)
> or String.
> 
> So assuming everything above, would the sqlMap segment
> below work?
> 
> <insert id="insertRecord"
> parameterClass="java.util.Map">
>    insert into $tableName$
>      <iterate open="(" close=")" conjunction=", ">
>        $records[].fieldName$
>      </iterate>
>    values
>      <iterate open="(" close=")" conjunction=", ">
>        #records[].value#:$records[].type$
>      </iterate>
> </insert>
> 
> Thanks!
> Rob
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>