ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Poitras Christian <Christian.Poit...@ircm.qc.ca>
Subject RE: dynamic CREATE TABLE woe
Date Thu, 23 Oct 2008 13:53:52 GMT
This is a bug in how iBATIS handles maps inside a list parameter.
Curiously, using #[].name# and #[].type# gave the expected result, but not $[].name$ and $[].type$...

You can use a simple patch by putting your list of maps inside a map:
    private Map<String, List<Map<String, String>>> prepareCreateTableParams(
            final String[] columnNames, final String[] columnTypes) {
        Map<String, List<Map<String, String>>> ret = new HashMap<String,
List<Map<String, String>>>();
        List<Map<String, String>> params =
            new ArrayList<Map<String, String>>();
        for(int i = 0; i < columnNames.length; i++) {
            HashMap<String, String> map = new HashMap<String, String>();
            map.put("name", columnNames[i]);
            map.put("type", columnTypes[i]);
            params.add(map);
        }
        ret.put("list", params);
        return ret;
    }

And in xml:
    <statement id="create-table" parameterClass="map">
        CREATE TABLE data
            <iterate open="(" close=")" conjunction="," property="list">
                $list[].name$ $list[].type$
            </iterate>
    </statement>


This should work.

Christian


-----Original Message-----
From: Pascal Jacob [mailto:zartc@wanadoo.fr]
Sent: Wednesday, October 22, 2008 4:59 PM
To: user-java@ibatis.apache.org
Subject: Re: dynamic CREATE TABLE woe

Investigating more, I found the following evidences in the PreparedStatement sent by iBatis
(I finally found the way to make iBatis log under SLF4J):

22:29:39.296 [DEBUG] [main] [java.sql.PreparedStatement:26] - {pstm-100002} Executing Statement:
CREATE TABLE seqnsdb.seqnsdata ( {name=ID, type=INTEGER} {name=ID, type=INTEGER}, {name=ARISING_SEQ_ID,
type=INTEGER} {name=ARISING_SEQ_ID, type=INTEGER}, {name=AC_SERIAL_NO, type=VARCHAR(255)}
{name=AC_SERIAL_NO, type=VARCHAR(255)} ... )

It is evident that iBatis is not transforming the SQLScript as expected !
It seems like the whole Map.Entry is printed each time instead of only the name value first
then only the type value.
AAMOF I did replace $[].name$ and $[].type$ by simply  $[]$ in the script and get the exact
same result, which confirms that $[].name$ don't do anything more than $[]$ which is obviously
not what is expected (or there is something i didn't understood)

Hope this helps someone helping me ;)

Tanks in advance.


Mime
View raw message