Skip to content

Commit 9b6ce3f

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 9b6ce3f

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public FilteredDynamicContext(DynamicContext delegate) {
9090
public void applyAll() {
9191
sqlBuffer = new StringBuilder(sqlBuffer.toString().trim());
9292
String trimmedUppercaseSql = sqlBuffer.toString().toUpperCase(Locale.ENGLISH);
93-
if (trimmedUppercaseSql.length() > 0) {
93+
if (!trimmedUppercaseSql.isEmpty()) {
9494
applyPrefix(sqlBuffer, trimmedUppercaseSql);
9595
applySuffix(sqlBuffer, trimmedUppercaseSql);
9696
}
@@ -99,6 +99,9 @@ public void applyAll() {
9999

100100
@Override
101101
public void appendSql(String sql) {
102+
if (sqlBuffer.length() > 0) {
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)