Skip to content

Commit

Permalink
fixes mybatis#21 SetSqlNode should remove comma before column name.
Browse files Browse the repository at this point in the history
  • Loading branch information
harawata committed Oct 30, 2018
1 parent 9abf46b commit 95166a6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2009-2015 the original author or authors.
* Copyright 2009-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,7 @@
*/
package org.apache.ibatis.scripting.xmltags;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.apache.ibatis.session.Configuration;
Expand All @@ -25,10 +25,10 @@
*/
public class SetSqlNode extends TrimSqlNode {

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

public SetSqlNode(Configuration configuration,SqlNode contents) {
super(configuration, contents, "SET", null, null, suffixList);
super(configuration, contents, "SET", COMMA, null, COMMA);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2009-2015 the original author or authors.
* Copyright 2009-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -285,6 +285,18 @@ public void shouldTrimSETInsteadOfCOMMAForBothConditions() throws Exception {
assertEquals(expected, boundSql.getSql());
}

@Test
public void shouldTrimCommaAfterSET() throws Exception {
final String expected = "UPDATE BLOG SET NAME = ?";
DynamicSqlSource source = createDynamicSqlSource(
new TextSqlNode("UPDATE BLOG"),
new SetSqlNode(new Configuration(), mixedContents(
new IfSqlNode(mixedContents(new TextSqlNode("ID = ?")), "false"),
new IfSqlNode(mixedContents(new TextSqlNode(", NAME = ?")), "true"))));
BoundSql boundSql = source.getBoundSql(null);
assertEquals(expected, boundSql.getSql());
}

@Test
public void shouldTrimNoSetClause() throws Exception {
final String expected = "UPDATE BLOG";
Expand Down

0 comments on commit 95166a6

Please sign in to comment.