ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Richard Yee <r...@cruzio.com>
Subject Re: multiple SQL statments in one SqlMap <sql> or <select>
Date Tue, 17 Apr 2007 13:38:57 GMT
Maarten,
Why don't you run them as separate statements and run the delete script 
in the teardown method of the test case?

-Richard


Maarten Meijer wrote:
> Can I do the following to make a single clean up query for after unit 
> testing:
>
> <sqlMap namespace="junit">
>     <!-- then do the special SQL operations for unit testing -->
>     <select id="countEmpty" resultClass="java.lang.Integer">
>         SELECT count(*) FROM `lqueries` WHERE q_nresults = 0 AND
>         q_ID &gt; #firstProject# AND
>         q_ID &lt;= #lastProject#;
>     </select>
>     <select id="restoreTables" resultClass="java.lang.Integer">
>         DELETE FROM `lqueries` WHERE q_ID &gt; #firstProject#;
>         DELETE FROM `lresults` WHERE r_ID &gt; #firstProject#;
>         ALTER TABLE `lqueries` AUTO_INCREMENT = #firstProject#;
>     </select>
> </sqlMap>
>
> If I try this, I get the following error message because of an 
> SQLException:
>
> junit.framework.AssertionFailedError: restoreTables() :
> --- The error occurred in com/fold1/dbtest/sqlmap/maps/UnitTests.xml.
> --- The error occurred while applying a parameter map.
> --- Check the junit.restoreTables-InlineParameterMap.
> --- Check the statement (query failed).
> --- Cause: java.sql.SQLException: You have an error in your SQL 
> syntax; check the manual that corresponds to your MySQL server version 
> for the right syntax to use near ';         DELETE FROM `lresults` 
> WHERE r_ID > 6672;         ALTER TABLE `lquerie' at line 1
>
> Is there a workaround whereby I can leave/hide all my SQL clean up 
> statements in the SqlMap and call them as a single unit from Java?
>
> Maarten


Mime
View raw message