mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed for mysql parser & update pom version
This commit is contained in:
@@ -477,6 +477,24 @@ public class SQLUtils {
|
||||
return stmtList;
|
||||
}
|
||||
|
||||
public static SQLStatement parseSingleStatement(String sql, String dbType, SQLParserFeature... features) {
|
||||
SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType, features);
|
||||
List<SQLStatement> stmtList = parser.parseStatementList();
|
||||
|
||||
if (stmtList.size() > 1) {
|
||||
throw new ParserException(" Mutil-Statment be found.");
|
||||
}
|
||||
|
||||
if (parser.getLexer().token() != Token.EOF) {
|
||||
throw new ParserException("syntax error. " + sql);
|
||||
}
|
||||
return stmtList.get(0);
|
||||
}
|
||||
|
||||
public static SQLStatement parseSingleMysqlStatement(String sql) {
|
||||
return parseSingleStatement(sql, JdbcConstants.MYSQL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @author owenludong.lud
|
||||
* @param columnName
|
||||
|
||||
@@ -24,4 +24,7 @@ public interface SQLStatement extends SQLObject {
|
||||
SQLStatement clone();
|
||||
List<SQLObject> getChildren();
|
||||
String toLowerCaseString();
|
||||
|
||||
List<SQLCommentHint> getHeadHintsDirect();
|
||||
void setHeadHints(List<SQLCommentHint> headHints);
|
||||
}
|
||||
|
||||
@@ -19,10 +19,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.SQLObjectImpl;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.*;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLInsertStatement extends SQLInsertInto implements SQLStatement {
|
||||
@@ -34,6 +31,8 @@ public class SQLInsertStatement extends SQLInsertInto implements SQLStatement {
|
||||
|
||||
private boolean afterSemi;
|
||||
|
||||
protected List<SQLCommentHint> headHints;
|
||||
|
||||
public SQLInsertStatement(){
|
||||
|
||||
}
|
||||
@@ -198,4 +197,12 @@ public class SQLInsertStatement extends SQLInsertInto implements SQLStatement {
|
||||
public String toLowerCaseString() {
|
||||
return SQLUtils.toSQLString(this, dbType, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
|
||||
}
|
||||
|
||||
public List<SQLCommentHint> getHeadHintsDirect() {
|
||||
return headHints;
|
||||
}
|
||||
|
||||
public void setHeadHints(List<SQLCommentHint> headHints) {
|
||||
this.headHints = headHints;
|
||||
}
|
||||
}
|
||||
|
||||
+15
-1
@@ -15,14 +15,18 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.dialect.mysql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
|
||||
|
||||
public class MySqlShowProcessListStatement extends MySqlStatementImpl implements MySqlShowStatement {
|
||||
|
||||
private boolean full = false;
|
||||
private SQLExpr where;
|
||||
|
||||
public void accept0(MySqlASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, where);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
@@ -34,4 +38,14 @@ public class MySqlShowProcessListStatement extends MySqlStatementImpl implements
|
||||
this.full = full;
|
||||
}
|
||||
|
||||
public SQLExpr getWhere() {
|
||||
return where;
|
||||
}
|
||||
|
||||
public void setWhere(SQLExpr x) {
|
||||
if (x != null) {
|
||||
x.setParent(this);
|
||||
}
|
||||
this.where = x;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -934,12 +934,12 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
}
|
||||
|
||||
if (tddlHints) {
|
||||
SQLStatementImpl stmt = (SQLStatementImpl)this.parseStatement();
|
||||
SQLStatement stmt = this.parseStatement();
|
||||
stmt.setHeadHints(hints);
|
||||
statementList.add(stmt);
|
||||
return true;
|
||||
} else if (accept) {
|
||||
SQLStatementImpl stmt = (SQLStatementImpl) this.parseStatement();
|
||||
SQLStatement stmt = this.parseStatement();
|
||||
stmt.setHeadHints(hints);
|
||||
statementList.add(stmt);
|
||||
return true;
|
||||
@@ -1712,6 +1712,14 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
if (lexer.identifierEquals("PROCESSLIST")) {
|
||||
lexer.nextToken();
|
||||
MySqlShowProcessListStatement stmt = new MySqlShowProcessListStatement();
|
||||
|
||||
if (lexer.token() == Token.WHERE) {
|
||||
lexer.nextToken();
|
||||
stmt.setWhere(
|
||||
this.exprParser.expr()
|
||||
);
|
||||
}
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
|
||||
@@ -888,6 +888,14 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlInsertStatement x) {
|
||||
List<SQLCommentHint> headHints = x.getHeadHintsDirect();
|
||||
if (headHints != null) {
|
||||
for (SQLCommentHint hint : headHints) {
|
||||
hint.accept(this);
|
||||
println();
|
||||
}
|
||||
}
|
||||
|
||||
print0(ucase ? "INSERT " : "insert ");
|
||||
|
||||
if (x.isLowPriority()) {
|
||||
|
||||
@@ -2548,6 +2548,14 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
}
|
||||
|
||||
public boolean visit(SQLInsertStatement x) {
|
||||
List<SQLCommentHint> headHints = x.getHeadHintsDirect();
|
||||
if (headHints != null) {
|
||||
for (SQLCommentHint hint : headHints) {
|
||||
hint.accept(this);
|
||||
println();
|
||||
}
|
||||
}
|
||||
|
||||
if (x.isUpsert()) {
|
||||
print0(ucase ? "UPSERT INTO " : "upsert into ");
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user