Skip to content

Commit

Permalink
bug fixed for issue #2015
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Sep 28, 2017
1 parent bdb79ec commit 80d3e98
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import java.util.ArrayList;
import java.util.List;

import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.*;
import com.alibaba.druid.sql.visitor.SQLASTOutputVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;

public class SQLUpdateStatement extends SQLStatementImpl implements SQLReplaceable {
Expand Down Expand Up @@ -112,22 +114,8 @@ public void setFrom(SQLTableSource from) {

@Override
public void output(StringBuffer buf) {
buf.append("UPDATE ");

this.tableSource.output(buf);

buf.append(" SET ");
for (int i = 0, size = items.size(); i < size; ++i) {
if (i != 0) {
buf.append(", ");
}
items.get(i).output(buf);
}

if (this.where != null) {
buf.append(" WHERE ");
this.where.output(buf);
}
SQLASTOutputVisitor visitor = SQLUtils.createOutputVisitor(buf, dbType);
this.accept(visitor);
}

@Override
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/com/alibaba/druid/bvt/bug/Issue2015.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.alibaba.druid.bvt.bug;

import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.util.JdbcConstants;
import junit.framework.TestCase;

import java.util.List;

public class Issue2015 extends TestCase {
public void test_for_issue() throws Exception {
String sql = "update t set a=1,b=2 where a > 1";
List<SQLStatement> stmtList = SQLUtils.parseStatements(sql, JdbcConstants.MYSQL);

StringBuffer buf = new StringBuffer();
stmtList.get(0).output(buf);
assertEquals("UPDATE t\n" +
"SET a = 1, b = 2\n" +
"WHERE a > 1", buf.toString());
}
}

0 comments on commit 80d3e98

Please sign in to comment.