Skip to content

Commit 95166a6

Browse files
committed
fixes #21 SetSqlNode should remove comma before column name.
1 parent 9abf46b commit 95166a6

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2015 the original author or authors.
2+
* Copyright 2009-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
1515
*/
1616
package org.apache.ibatis.scripting.xmltags;
1717

18-
import java.util.Arrays;
18+
import java.util.Collections;
1919
import java.util.List;
2020

2121
import org.apache.ibatis.session.Configuration;
@@ -25,10 +25,10 @@
2525
*/
2626
public class SetSqlNode extends TrimSqlNode {
2727

28-
private static List<String> suffixList = Arrays.asList(",");
28+
private static List<String> COMMA = Collections.singletonList(",");
2929

3030
public SetSqlNode(Configuration configuration,SqlNode contents) {
31-
super(configuration, contents, "SET", null, null, suffixList);
31+
super(configuration, contents, "SET", COMMA, null, COMMA);
3232
}
3333

3434
}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2015 the original author or authors.
2+
* Copyright 2009-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -285,6 +285,18 @@ public void shouldTrimSETInsteadOfCOMMAForBothConditions() throws Exception {
285285
assertEquals(expected, boundSql.getSql());
286286
}
287287

288+
@Test
289+
public void shouldTrimCommaAfterSET() throws Exception {
290+
final String expected = "UPDATE BLOG SET NAME = ?";
291+
DynamicSqlSource source = createDynamicSqlSource(
292+
new TextSqlNode("UPDATE BLOG"),
293+
new SetSqlNode(new Configuration(), mixedContents(
294+
new IfSqlNode(mixedContents(new TextSqlNode("ID = ?")), "false"),
295+
new IfSqlNode(mixedContents(new TextSqlNode(", NAME = ?")), "true"))));
296+
BoundSql boundSql = source.getBoundSql(null);
297+
assertEquals(expected, boundSql.getSql());
298+
}
299+
288300
@Test
289301
public void shouldTrimNoSetClause() throws Exception {
290302
final String expected = "UPDATE BLOG";

0 commit comments

Comments
 (0)