dynamic statement (all parameter is dynamically generated)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

dynamic statement (all parameter is dynamically generated)

abchau
I used to use iBatisNet 1.0 and was using an abnormal way to generate sql for me.
Recently i want to move to the latest version, and found that the old way is not work anymore.
I would lilke to ask if someone know how to do the same thing in latest verion.

This is the normal way, predefined the column name & parameters
<insert id="insertsql" parameterClass="hashtable">
        insert into User (username, password) values (#username#, #password#)")
</insert>

What i was doing is to define nothing in the mapped statements, but just a $strparam$
<insert id="insertsql" parameterClass="hashtable">
        $strparam$
</insert>

In the code, i generate the statement dynamically according to waht i want to insert:
Hashtable hashtable = new Hashtable();
hashtable.add("username", "admin");
hashtable.add("password", "password");
hashtable.add("strparam", "insert into User (username, password) values (#username#, #password#)");
SqlMapper.Insert("insertsql", hashtable);

By generating SQL in this way, i can define only ONE <insert>..</insert> for all case even if i have 1000 tables.
And this method works fine in 1.0 ( perhaps it may be a bug)

I know that i can generate the SQL in Stirng, but not hashtable:
<insert id="insertsql" parameterClass="string">
        $strparam$
</insert>
string strparam = "insert into User (username, password) values ('admin', 'password')";
SqlMapper.Insert("insertsql", strparam);

But using String got problem when:
1) need to replace all ' into ''
2) the value is very very long,  db field is storing entire code of a html page

That's why i still want to implment the "hashtable" way
Is anyone got idea?

Thanks in advance!!!!
Loading...