mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@118 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -108,8 +108,8 @@ public class MySqlLexer extends Lexer {
|
||||
DEFAULT_MYSQL_KEYWORDS = new Keywords(map);
|
||||
}
|
||||
|
||||
public MySqlLexer(char[] input, int inputLength){
|
||||
super(input, inputLength);
|
||||
public MySqlLexer(char[] input, int inputLength, boolean skipComment){
|
||||
super(input, inputLength, skipComment);
|
||||
super.keywods = DEFAULT_MYSQL_KEYWORDS;
|
||||
}
|
||||
|
||||
|
||||
@@ -74,11 +74,18 @@ public class Lexer {
|
||||
|
||||
protected String stringVal;
|
||||
|
||||
protected boolean skipComment = true;
|
||||
|
||||
public Lexer(String input){
|
||||
this(input.toCharArray(), input.length());
|
||||
this(input, true);
|
||||
}
|
||||
|
||||
public Lexer(char[] input, int inputLength){
|
||||
public Lexer(String input, boolean skipComment){
|
||||
this(input.toCharArray(), input.length(), skipComment);
|
||||
}
|
||||
|
||||
public Lexer(char[] input, int inputLength, boolean skipComment){
|
||||
this.skipComment = skipComment;
|
||||
this.sbuf = sbufRef.get(); // new char[1024];
|
||||
if (this.sbuf == null) {
|
||||
this.sbuf = new char[1024];
|
||||
@@ -245,6 +252,9 @@ public class Lexer {
|
||||
return;
|
||||
case '/':
|
||||
scanComment();
|
||||
if (skipComment) {
|
||||
continue;
|
||||
}
|
||||
return;
|
||||
default:
|
||||
if (Character.isLetter(ch)) {
|
||||
|
||||
@@ -287,8 +287,9 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter {
|
||||
public boolean visit(SQLInListExpr x) {
|
||||
x.getExpr().accept(this);
|
||||
|
||||
if (x.isNot()) print(" NOT IN (");
|
||||
else {
|
||||
if (x.isNot()) {
|
||||
print(" NOT IN (");
|
||||
} else {
|
||||
print(" IN (");
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public class CommentTest extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void f_test_1 () throws Exception {
|
||||
public void test_1 () throws Exception {
|
||||
String sql = "SELECT /*mark for picman*/ * FROM WP_ALBUM WHERE MEMBER_ID = ? AND ID IN (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
StringBuilder out = new StringBuilder();
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.alibaba.druid.sql.parser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLInListExpr;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.visitor.OracleOutputVisitor;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class SQLMergeTest extends TestCase {
|
||||
|
||||
public void test_merge() throws Exception {
|
||||
String sql = "SELECT /*mark for picman*/ * FROM WP_ALBUM WHERE MEMBER_ID = ? AND ID IN (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
StringBuilder out = new StringBuilder();
|
||||
OracleOutputVisitor visitor = new OracleOutputVisitor(out) {
|
||||
public boolean visit(SQLInListExpr x) {
|
||||
x.getExpr().accept(this);
|
||||
|
||||
if (x.isNot()) {
|
||||
print(" NOT IN (##)");
|
||||
} else {
|
||||
print(" IN (##)");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
for (SQLStatement statement : statementList) {
|
||||
statement.accept(visitor);
|
||||
visitor.println();
|
||||
}
|
||||
|
||||
System.out.println(out.toString());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user