Skip to content

SQL include does not replace in attributes #1069

@kmoco2am

Description

@kmoco2am

Current implementation of SQL fragment include replaces placeholders only in text nodes of XML. If placeholder is placed for example in "test" attribute of "if" it is not replaced. It looks like a bug in the implementation which scans only "child" nodes but it had "attribute" branch too which has not been ever used.

Example usage:

<sql id="select-part">
    SELECT d.field1, d.field2, ..., d.fieldN
    <if test="${source} == 'active'">
        , null AS archivedDate
        FROM active_table d
    </if>
    <if test="${source} == 'archive'">
        , d.achived AS archivedDate
        FROM archive_table d
    </if>
    LEFT JOIN ...
    ORDER BY ...
</sql>

<select id="fetchData" resultMap="Data">
    <include refid="select-part">
        <property name="source" value="active"/>
    </include>
    UNION ALL
    <include refid="select-part">
        <property name="source" value="archive"/>
    </include>
</select>

(example taken from original question on StackOverflow)

Metadata

Metadata

Assignees

Labels

enhancementImprove a feature or add a new feature

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions