mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed for sql parser. for issue #2105
This commit is contained in:
@@ -87,11 +87,27 @@ public class ParameterizedOutputVisitorUtils {
|
||||
}
|
||||
|
||||
for (int i = 0; i < statementList.size(); i++) {
|
||||
if (i > 0) {
|
||||
out.append(";\n");
|
||||
}
|
||||
SQLStatement stmt = statementList.get(i);
|
||||
|
||||
if (i > 0) {
|
||||
SQLStatement preStmt = statementList.get(i - 1);
|
||||
|
||||
if (preStmt.getClass() == stmt.getClass()) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
ParameterizedVisitor v1 = createParameterizedOutputVisitor(buf, dbType);
|
||||
preStmt.accept(v1);
|
||||
if (out.toString().equals(buf.toString())) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!preStmt.isAfterSemi()) {
|
||||
out.append(";\n");
|
||||
} else {
|
||||
out.append('\n');
|
||||
}
|
||||
}
|
||||
|
||||
if (stmt.hasBeforeComment()) {
|
||||
stmt.getBeforeCommentsDirect().clear();
|
||||
}
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.alibaba.druid.bvt.sql.mysql.param;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.ParameterizedOutputVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by wenshao on 16/8/23.
|
||||
*/
|
||||
public class MySqlParameterizedOutputVisitorTest_59_multiupdate extends TestCase {
|
||||
final String dbType = JdbcConstants.MYSQL;
|
||||
public void test_for_parameterize() throws Exception {
|
||||
|
||||
String sql = "update t_order set salary = 101 where id = 101;update t_order set salary = 102 where id = 102";
|
||||
|
||||
List<Object> params = new ArrayList<Object>();
|
||||
String psql = ParameterizedOutputVisitorUtils.parameterize(sql, dbType, params);
|
||||
assertEquals("UPDATE t_order\n" +
|
||||
"SET salary = ?\n" +
|
||||
"WHERE id = ?;", psql);
|
||||
assertEquals(2, params.size());
|
||||
assertEquals(101, params.get(0));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user