mybatis/mybatis-dynamic-sql

"In" and "NotIn" Conditions Render Incorrectly in Some Circumstances

jeffgbutler opened this issue · 0 comments

Currently the decision about whether or not to render an "In" or "NotIn" condition is made before any filter or map is applied to the value list. Then can cause incorrect rendering in some cases. For example, if a filter removes all items from a value list the condition will still render - yielding invalid SQL. For example, the following will render incorrectly:

SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
        .from(animalData)
        .where(id, isIn(null, 22, null).then(s -> s.filter(Objects::nonNull).filter(i -> i != 22)))
        .build()
        .render(RenderingStrategies.MYBATIS3);