Skip to content

Commit b3fcae3

Browse files
committed
TrimSqlNode should add an extra space when concatenating its contents like MixedSqlNode does
This was the [key difference](#3349 (comment)) that broke #3349 .
1 parent b90a0f8 commit b3fcae3

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/main/java/org/apache/ibatis/scripting/xmltags/TrimSqlNode.java

+3
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ public void applyAll() {
9999

100100
@Override
101101
public void appendSql(String sql) {
102+
if (!sqlBuffer.isEmpty()) {
103+
sqlBuffer.append(" ");
104+
}
102105
sqlBuffer.append(sql);
103106
}
104107

src/test/java/org/apache/ibatis/builder/xml/dynamic/DynamicSqlSourceTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ void shouldTrimWHEREInsteadOfORForSecondCondition() throws Exception {
214214

215215
@Test
216216
void shouldTrimWHEREInsteadOfANDForBothConditions() throws Exception {
217-
final String expected = "SELECT * FROM BLOG WHERE ID = ? OR NAME = ?";
217+
final String expected = "SELECT * FROM BLOG WHERE ID = ? OR NAME = ?";
218218
DynamicSqlSource source = createDynamicSqlSource(new TextSqlNode("SELECT * FROM BLOG"),
219219
new WhereSqlNode(new Configuration(),
220220
mixedContents(new IfSqlNode(mixedContents(new TextSqlNode(" and ID = ? ")), "true"),
@@ -236,7 +236,7 @@ void shouldTrimNoWhereClause() throws Exception {
236236

237237
@Test
238238
void shouldTrimSETInsteadOfCOMMAForBothConditions() throws Exception {
239-
final String expected = "UPDATE BLOG SET ID = ?, NAME = ?";
239+
final String expected = "UPDATE BLOG SET ID = ?, NAME = ?";
240240
DynamicSqlSource source = createDynamicSqlSource(new TextSqlNode("UPDATE BLOG"),
241241
new SetSqlNode(new Configuration(),
242242
mixedContents(new IfSqlNode(mixedContents(new TextSqlNode(" ID = ?, ")), "true"),

0 commit comments

Comments
 (0)