appfuse and ibatis dynamic queries
for some reason appfuse defines the iBatis queries in a CDATA section.
<select id="getStockMaintenanceQueryCriterias" resultMap="stockMaintenanceQueryCriteriaResult">
<!-- Can say also say part_nm like '%$partNm$%', but partNm will need to have escape processing carried out -->
<![CDATA[
select * from stock_maintenance_query
where 1=1
<isNotEmpty prepend="and" property="partNm" >
part_nm like '%' || #partNm# || '%'
</isNotEmpty>
]]>
</select>
but if you want to use the dynamic sql then you have to remove the CDATA. Not sure why the CDATA was there in the first place in appfuse.
<select id="getStockMaintenanceQueryCriterias" resultMap="stockMaintenanceQueryCriteriaResult">
<!-- Can say also say part_nm like '%$partNm$%', but partNm will need to have escape processing carried out -->
select * from stock_maintenance_query
where 1=1
<isNotEmpty prepend="and" property="partNm" >
part_nm like '%' || #partNm# || '%'
</isNotEmpty>
</select>
There is a good reason for the CDATA - its
3.3.3.1. Escaping XML symbols
Because you are combining SQL and XML in a single document, conflicts can occur. The most common conflict is the greater-than and less-than symbols (><). SQL statements use these symbols as operators, but they are reserved symbols in XML. A simple solution is to escape the SQL statements that uses XML reserved symbols within a CDATA element. Example 3.6 demonstrates this.
Example 3.6. Using CDATA to "escape" SQL code
<statement id="SelectPersonsByAge" parameterClass="int" resultClass="Person">
<![CDATA[
SELECT * FROM PERSON WHERE AGE > #value#
]]>
</statement>
0 Comments:
Post a Comment
<< Home