New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL include does not replace in attributes #1069

kmoco2am opened this Issue Aug 8, 2017 · 3 comments


None yet
4 participants

kmoco2am commented Aug 8, 2017

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 test="${source} == 'archive'">
        , d.achived AS archivedDate
        FROM archive_table d
    LEFT JOIN ...
    ORDER BY ...

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

(example taken from original question on StackOverflow)


This comment has been minimized.

c340c340 commented Aug 11, 2017

mayby you can use <bind name="" value="">

<select id="select-part" resultClass="HashMap"  parameterClass="HashMap">
  <bind name="email" value="'%' +email + '%'" />
  select * from tableone
  <if test="email != null and email != ''">
    email like #{email}

This comment has been minimized.

amwei commented Aug 11, 2017

@c340c340 diff case you are


This comment has been minimized.

kmoco2am commented Aug 15, 2017

@c340c340 bind cannot be used in this case. Current implementation replaces include parameters only in text nodes in XML, attributes are completely ignored (so value attribute of bind element would be ignored the same way as attributes in if, for, or similar). Or could you provide some working example?

@harawata harawata added the enhancement label Sep 7, 2017

@harawata harawata added this to the 3.4.6 milestone Sep 7, 2017

@harawata harawata closed this in da2beb1 Sep 18, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment