mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser.
This commit is contained in:
@@ -144,18 +144,13 @@ public class MySqlLexer extends Lexer {
|
||||
}
|
||||
|
||||
public void scanVariable() {
|
||||
if (ch != '@' && ch != ':' && ch != '#' && ch != '$') {
|
||||
if (ch != ':' && ch != '#' && ch != '$') {
|
||||
throw new ParserException("illegal variable. " + info());
|
||||
}
|
||||
|
||||
mark = pos;
|
||||
bufPos = 1;
|
||||
|
||||
if (charAt(pos + 1) == '@') {
|
||||
ch = charAt(++pos);
|
||||
bufPos++;
|
||||
}
|
||||
|
||||
if (charAt(pos + 1) == '`') {
|
||||
++pos;
|
||||
++bufPos;
|
||||
@@ -221,6 +216,61 @@ public class MySqlLexer extends Lexer {
|
||||
token = Token.VARIANT;
|
||||
}
|
||||
|
||||
protected void scanVariable_at() {
|
||||
if (ch != '@') {
|
||||
throw new ParserException("illegal variable. " + info());
|
||||
}
|
||||
|
||||
mark = pos;
|
||||
bufPos = 1;
|
||||
|
||||
if (charAt(pos + 1) == '@') {
|
||||
ch = charAt(++pos);
|
||||
bufPos++;
|
||||
}
|
||||
|
||||
if (charAt(pos + 1) == '`') {
|
||||
++pos;
|
||||
++bufPos;
|
||||
char ch;
|
||||
for (;;) {
|
||||
ch = charAt(++pos);
|
||||
|
||||
if (ch == '`') {
|
||||
bufPos++;
|
||||
++pos;
|
||||
break;
|
||||
} else if (ch == EOI) {
|
||||
throw new ParserException("illegal identifier. " + info());
|
||||
}
|
||||
|
||||
bufPos++;
|
||||
continue;
|
||||
}
|
||||
|
||||
this.ch = charAt(pos);
|
||||
|
||||
stringVal = subString(mark, bufPos);
|
||||
token = Token.VARIANT;
|
||||
} else {
|
||||
for (; ; ) {
|
||||
ch = charAt(++pos);
|
||||
|
||||
if (!isIdentifierChar(ch)) {
|
||||
break;
|
||||
}
|
||||
|
||||
bufPos++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
this.ch = charAt(pos);
|
||||
|
||||
stringVal = subString(mark, bufPos);
|
||||
token = Token.VARIANT;
|
||||
}
|
||||
|
||||
public void scanIdentifier() {
|
||||
hash_lower = 0;
|
||||
hash = 0;
|
||||
@@ -342,6 +392,8 @@ public class MySqlLexer extends Lexer {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected final void scanString() {
|
||||
scanString2();
|
||||
}
|
||||
|
||||
+91
-56
@@ -17,15 +17,7 @@ package com.alibaba.druid.sql.dialect.mysql.parser;
|
||||
|
||||
import com.alibaba.druid.sql.ast.*;
|
||||
import com.alibaba.druid.sql.ast.SQLParameter.ParameterType;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOperator;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLLiteralExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLQueryExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.*;
|
||||
import com.alibaba.druid.sql.ast.statement.*;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement.ValuesClause;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.MysqlForeignKey;
|
||||
@@ -65,7 +57,6 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
private static final String GLOBAL = "GLOBAL";
|
||||
private static final String VARIABLES = "VARIABLES";
|
||||
private static final String STATUS = "STATUS";
|
||||
private static final String IGNORE = "IGNORE";
|
||||
private static final String RESET = "RESET";
|
||||
private static final String DESCRIBE = "DESCRIBE";
|
||||
private static final String WRITE = "WRITE";
|
||||
@@ -75,7 +66,6 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
private static final String TEMPORARY = "TEMPORARY";
|
||||
private static final String SPATIAL = "SPATIAL";
|
||||
private static final String FULLTEXT = "FULLTEXT";
|
||||
private static final String DELAYED = "DELAYED";
|
||||
private static final String LOW_PRIORITY = "LOW_PRIORITY";
|
||||
private static final String CONNECTION = "CONNECTION";
|
||||
private static final String EXTENDED = "EXTENDED";
|
||||
@@ -151,7 +141,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
this.getExprParser().parseHints(deleteStatement.getHints());
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(LOW_PRIORITY)) {
|
||||
if (lexer.identifierEquals(FnvHash.Constants.LOW_PRIORITY)) {
|
||||
deleteStatement.setLowPriority(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
@@ -161,7 +151,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(IGNORE)) {
|
||||
if (lexer.identifierEquals(FnvHash.Constants.IGNORE)) {
|
||||
deleteStatement.setIgnore(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
@@ -607,7 +597,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
}
|
||||
} else if (lexer.identifierEquals(WRITE)) {
|
||||
stmt.setLockType(LockType.WRITE);
|
||||
} else if (lexer.identifierEquals(LOW_PRIORITY)) {
|
||||
} else if (lexer.identifierEquals(FnvHash.Constants.LOW_PRIORITY)) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier(WRITE);
|
||||
stmt.setLockType(LockType.LOW_PRIORITY_WRITE);
|
||||
@@ -1792,12 +1782,12 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(LOW_PRIORITY)) {
|
||||
if (lexer.identifierEquals(FnvHash.Constants.LOW_PRIORITY)) {
|
||||
stmt.setLowPriority(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(DELAYED)) {
|
||||
if (lexer.identifierEquals(FnvHash.Constants.DELAYED)) {
|
||||
stmt.setDelayed(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
@@ -1879,7 +1869,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
|
||||
MySqlLoadXmlStatement stmt = new MySqlLoadXmlStatement();
|
||||
|
||||
if (lexer.identifierEquals(LOW_PRIORITY)) {
|
||||
if (lexer.identifierEquals(FnvHash.Constants.LOW_PRIORITY)) {
|
||||
stmt.setLowPriority(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
@@ -1904,7 +1894,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(IGNORE)) {
|
||||
if (lexer.identifierEquals(FnvHash.Constants.IGNORE)) {
|
||||
stmt.setIgnore(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
@@ -1936,7 +1926,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
stmt.setRowsIdentifiedBy(rowsIdentifiedBy);
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(IGNORE)) {
|
||||
if (lexer.identifierEquals(FnvHash.Constants.IGNORE)) {
|
||||
throw new ParserException("TODO. " + lexer.info());
|
||||
}
|
||||
|
||||
@@ -1953,7 +1943,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
|
||||
MySqlLoadDataInFileStatement stmt = new MySqlLoadDataInFileStatement();
|
||||
|
||||
if (lexer.identifierEquals(LOW_PRIORITY)) {
|
||||
if (lexer.identifierEquals(FnvHash.Constants.LOW_PRIORITY)) {
|
||||
stmt.setLowPriority(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
@@ -1978,7 +1968,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(IGNORE)) {
|
||||
if (lexer.identifierEquals(FnvHash.Constants.IGNORE)) {
|
||||
stmt.setIgnore(true);
|
||||
lexer.nextToken();
|
||||
}
|
||||
@@ -2048,7 +2038,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
}
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(IGNORE)) {
|
||||
if (lexer.identifierEquals(FnvHash.Constants.IGNORE)) {
|
||||
lexer.nextToken();
|
||||
stmt.setIgnoreLinesNumber(this.exprParser.expr());
|
||||
acceptIdentifier("LINES");
|
||||
@@ -2115,35 +2105,40 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
lexer.nextToken();
|
||||
|
||||
for (; ; ) {
|
||||
if (lexer.identifierEquals(LOW_PRIORITY)) {
|
||||
insertStatement.setLowPriority(true);
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
if (lexer.token() == Token.IDENTIFIER) {
|
||||
long hash = lexer.hash_lower();
|
||||
|
||||
if (hash == FnvHash.Constants.LOW_PRIORITY) {
|
||||
insertStatement.setLowPriority(true);
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hash == FnvHash.Constants.DELAYED) {
|
||||
insertStatement.setDelayed(true);
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hash == FnvHash.Constants.HIGH_PRIORITY) {
|
||||
insertStatement.setHighPriority(true);
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hash == FnvHash.Constants.IGNORE) {
|
||||
insertStatement.setIgnore(true);
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hash == FnvHash.Constants.ROLLBACK_ON_FAIL) {
|
||||
insertStatement.setRollbackOnFail(true);
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(DELAYED)) {
|
||||
insertStatement.setDelayed(true);
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals("HIGH_PRIORITY")) {
|
||||
insertStatement.setHighPriority(true);
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(IGNORE)) {
|
||||
insertStatement.setIgnore(true);
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals("ROLLBACK_ON_FAIL")) {
|
||||
insertStatement.setRollbackOnFail(true);
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -2155,7 +2150,8 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
SQLName tableName = this.exprParser.name();
|
||||
insertStatement.setTableName(tableName);
|
||||
|
||||
if (lexer.token() == Token.IDENTIFIER && !lexer.identifierEquals("VALUE")) {
|
||||
if (lexer.token() == Token.IDENTIFIER
|
||||
&& !lexer.identifierEquals(FnvHash.Constants.VALUE)) {
|
||||
insertStatement.setAlias(lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
}
|
||||
@@ -2163,20 +2159,59 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
}
|
||||
|
||||
int columnSize = 0;
|
||||
if (lexer.token() == (Token.LPAREN)) {
|
||||
if (lexer.token() == Token.LPAREN) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == (Token.SELECT)) {
|
||||
if (lexer.token() == Token.SELECT) {
|
||||
SQLSelect select = this.exprParser.createSelectParser().select();
|
||||
select.setParent(insertStatement);
|
||||
insertStatement.setQuery(select);
|
||||
} else {
|
||||
this.exprParser.exprList(insertStatement.getColumns(), insertStatement);
|
||||
columnSize = insertStatement.getColumns().size();
|
||||
List<SQLExpr> columns = insertStatement.getColumns();
|
||||
//this.exprParser.exprList(insertStatement.getColumns(), insertStatement);
|
||||
|
||||
if (lexer.token() != Token.RPAREN) {
|
||||
for (; ; ) {
|
||||
String identName;
|
||||
long hash;
|
||||
|
||||
Token token = lexer.token();
|
||||
if (token == Token.IDENTIFIER) {
|
||||
identName = lexer.stringVal();
|
||||
hash = lexer.hash_lower();
|
||||
} else if (token == Token.LITERAL_CHARS) {
|
||||
identName = '\'' + lexer.stringVal() + '\'';
|
||||
hash = 0;
|
||||
} else {
|
||||
identName = lexer.stringVal();
|
||||
hash = 0;
|
||||
}
|
||||
lexer.nextTokenComma();
|
||||
SQLExpr expr = new SQLIdentifierExpr(identName, hash);
|
||||
while (lexer.token() == Token.DOT) {
|
||||
lexer.nextToken();
|
||||
String propertyName = lexer.stringVal();
|
||||
lexer.nextToken();
|
||||
expr = new SQLPropertyExpr(expr, propertyName);
|
||||
}
|
||||
|
||||
expr.setParent(insertStatement);
|
||||
columns.add(expr);
|
||||
columnSize++;
|
||||
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
columnSize = insertStatement.getColumns().size();
|
||||
}
|
||||
}
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.VALUES || lexer.identifierEquals("VALUE")) {
|
||||
if (lexer.token() == Token.VALUES || lexer.identifierEquals(FnvHash.Constants.VALUE)) {
|
||||
lexer.nextTokenLParen();
|
||||
parseValueClause(insertStatement.getValuesList(), columnSize, insertStatement);
|
||||
} else if (lexer.token() == Token.SET) {
|
||||
@@ -2472,7 +2507,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
|
||||
boolean ignore = false;
|
||||
|
||||
if (lexer.identifierEquals(IGNORE)) {
|
||||
if (lexer.identifierEquals(FnvHash.Constants.IGNORE)) {
|
||||
ignore = true;
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
@@ -1072,7 +1072,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
|
||||
print0(ucase ? "INTO " : "into ");
|
||||
|
||||
printExpr(x.getTableName());
|
||||
printTableSourceExpr(x.getTableName());
|
||||
|
||||
List<SQLExpr> columns = x.getColumns();
|
||||
if (columns.size() > 0) {
|
||||
|
||||
+1
-9
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.dialect.mysql.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.ast.statement.SQLScriptCommitStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.OracleDataTypeIntervalDay;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.OracleDataTypeIntervalYear;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.clause.*;
|
||||
@@ -34,10 +35,6 @@ public class OracleToMySqlOutputVisitor extends MySqlOutputVisitor implements Or
|
||||
super(appender, parameterized);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(OraclePLSQLCommitStatement astNode) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(OracleAnalytic x) {
|
||||
@@ -109,11 +106,6 @@ public class OracleToMySqlOutputVisitor extends MySqlOutputVisitor implements Or
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OraclePLSQLCommitStatement astNode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleAnalytic x) {
|
||||
return false;
|
||||
|
||||
@@ -153,24 +153,6 @@ public class OdpsExprParser extends SQLExprParser {
|
||||
return super.primaryRest(expr);
|
||||
}
|
||||
|
||||
public SQLExpr equalityRest(SQLExpr expr) {
|
||||
if (lexer.token() == Token.EQEQ) {
|
||||
SQLExpr rightExp;
|
||||
lexer.nextToken();
|
||||
try {
|
||||
rightExp = bitOr();
|
||||
} catch (EOFParserException e) {
|
||||
throw new ParserException("EOF, " + expr + "=", e);
|
||||
}
|
||||
rightExp = equalityRest(rightExp);
|
||||
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.Equality, rightExp, getDbType());
|
||||
|
||||
return expr;
|
||||
}
|
||||
|
||||
return super.equalityRest(expr);
|
||||
}
|
||||
|
||||
public SQLExpr relationalRest(SQLExpr expr) {
|
||||
if (lexer.identifierEquals("REGEXP")) {
|
||||
|
||||
@@ -362,6 +362,10 @@ public class OdpsLexer extends Lexer {
|
||||
super.scanVariable();
|
||||
}
|
||||
|
||||
protected void scanVariable_at() {
|
||||
scanVariable();
|
||||
}
|
||||
|
||||
protected final void scanString() {
|
||||
scanString2();
|
||||
}
|
||||
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.sql.dialect.oracle.ast.stmt;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;
|
||||
|
||||
public class OraclePLSQLCommitStatement extends OracleStatementImpl {
|
||||
|
||||
public OraclePLSQLCommitStatement(){
|
||||
|
||||
}
|
||||
|
||||
public void accept0(OracleASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
}
|
||||
@@ -998,43 +998,6 @@ public class OracleExprParser extends SQLExprParser {
|
||||
return name;
|
||||
}
|
||||
|
||||
public SQLExpr equalityRest(SQLExpr expr) {
|
||||
SQLExpr rightExp;
|
||||
if (lexer.token() == Token.EQ) {
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token() == Token.GT) {
|
||||
lexer.nextToken();
|
||||
rightExp = expr();
|
||||
String argumentName = ((SQLIdentifierExpr) expr).getName();
|
||||
return new OracleArgumentExpr(argumentName, rightExp);
|
||||
}
|
||||
|
||||
rightExp = shift();
|
||||
|
||||
rightExp = equalityRest(rightExp);
|
||||
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.Equality, rightExp, getDbType());
|
||||
} else if (lexer.token() == Token.BANGEQ || lexer.token() == Token.CARETEQ) {
|
||||
lexer.nextToken();
|
||||
rightExp = shift();
|
||||
|
||||
rightExp = equalityRest(rightExp);
|
||||
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.NotEqual, rightExp, getDbType());
|
||||
} else if (lexer.token() == Token.BANG) {
|
||||
lexer.nextToken();
|
||||
accept(Token.EQ);
|
||||
rightExp = shift();
|
||||
|
||||
rightExp = equalityRest(rightExp);
|
||||
|
||||
expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.NotEqual, rightExp, getDbType());
|
||||
}
|
||||
|
||||
return expr;
|
||||
}
|
||||
|
||||
public OraclePrimaryKey parsePrimaryKey() {
|
||||
lexer.nextToken();
|
||||
accept(Token.KEY);
|
||||
@@ -1043,7 +1006,6 @@ public class OracleExprParser extends SQLExprParser {
|
||||
accept(Token.LPAREN);
|
||||
orderBy(primaryKey.getColumns(), primaryKey);
|
||||
accept(Token.RPAREN);
|
||||
|
||||
|
||||
if (lexer.token() == Token.USING) {
|
||||
OracleUsingIndexClause using = parseUsingIndex();
|
||||
|
||||
@@ -144,12 +144,6 @@ public class OracleLexer extends Lexer {
|
||||
}
|
||||
|
||||
public void scanVariable() {
|
||||
if (ch == '@') {
|
||||
scanChar();
|
||||
token = Token.MONKEYS_AT;
|
||||
return;
|
||||
}
|
||||
|
||||
if (ch != ':' && ch != '#' && ch != '$') {
|
||||
throw new ParserException("illegal variable. " + info());
|
||||
}
|
||||
@@ -206,6 +200,12 @@ public class OracleLexer extends Lexer {
|
||||
}
|
||||
}
|
||||
|
||||
protected void scanVariable_at() {
|
||||
scanChar();
|
||||
token = Token.MONKEYS_AT;
|
||||
return;
|
||||
}
|
||||
|
||||
public void scanComment() {
|
||||
if (ch != '/' && ch != '-') {
|
||||
throw new IllegalStateException();
|
||||
|
||||
+1
-1
@@ -129,7 +129,7 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
if (lexer.token() == (Token.SLASH)) {
|
||||
lexer.nextToken();
|
||||
|
||||
SQLStatement stmt = new OraclePLSQLCommitStatement();
|
||||
SQLStatement stmt = new SQLScriptCommitStatement();
|
||||
stmt.setParent(parent);
|
||||
statementList.add(stmt);
|
||||
continue;
|
||||
|
||||
@@ -36,7 +36,7 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public interface OracleASTVisitor extends SQLASTVisitor {
|
||||
|
||||
void endVisit(OraclePLSQLCommitStatement astNode);
|
||||
|
||||
|
||||
void endVisit(OracleAnalytic x);
|
||||
|
||||
@@ -68,8 +68,6 @@ public interface OracleASTVisitor extends SQLASTVisitor {
|
||||
|
||||
void endVisit(OracleUpdateStatement x);
|
||||
|
||||
boolean visit(OraclePLSQLCommitStatement astNode);
|
||||
|
||||
boolean visit(OracleAnalytic x);
|
||||
|
||||
boolean visit(OracleAnalyticWindowing x);
|
||||
|
||||
+3
-2
@@ -17,6 +17,7 @@ package com.alibaba.druid.sql.dialect.oracle.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.ast.statement.SQLMergeStatement.MergeInsertClause;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLMergeStatement.MergeUpdateClause;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLScriptCommitStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.OracleDataTypeIntervalDay;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.OracleDataTypeIntervalYear;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.clause.CycleClause;
|
||||
@@ -49,7 +50,7 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitorAdapter;
|
||||
public class OracleASTVisitorAdapter extends SQLASTVisitorAdapter implements OracleASTVisitor {
|
||||
|
||||
@Override
|
||||
public void endVisit(OraclePLSQLCommitStatement astNode) {
|
||||
public void endVisit(SQLScriptCommitStatement astNode) {
|
||||
|
||||
}
|
||||
|
||||
@@ -124,7 +125,7 @@ public class OracleASTVisitorAdapter extends SQLASTVisitorAdapter implements Ora
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OraclePLSQLCommitStatement astNode) {
|
||||
public boolean visit(SQLScriptCommitStatement astNode) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(OraclePLSQLCommitStatement astNode) {
|
||||
public boolean visit(SQLScriptCommitStatement astNode) {
|
||||
print('/');
|
||||
println();
|
||||
return false;
|
||||
@@ -624,11 +624,6 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(OraclePLSQLCommitStatement astNode) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(OracleAnalytic x) {
|
||||
|
||||
|
||||
+1
-7
@@ -17,7 +17,6 @@ package com.alibaba.druid.sql.dialect.oracle.visitor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
@@ -222,11 +221,6 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(OraclePLSQLCommitStatement astNode) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(OracleAnalytic x) {
|
||||
|
||||
@@ -288,7 +282,7 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OraclePLSQLCommitStatement astNode) {
|
||||
public boolean visit(SQLScriptCommitStatement astNode) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -15,15 +15,13 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.dialect.postgresql.parser;
|
||||
|
||||
import static com.alibaba.druid.sql.parser.CharTypes.isIdentifierChar;
|
||||
import static com.alibaba.druid.sql.parser.Token.LITERAL_CHARS;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.druid.sql.parser.Keywords;
|
||||
import com.alibaba.druid.sql.parser.Lexer;
|
||||
import com.alibaba.druid.sql.parser.SQLParserFeature;
|
||||
import com.alibaba.druid.sql.parser.Token;
|
||||
import com.alibaba.druid.sql.parser.*;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
public class PGLexer extends Lexer {
|
||||
@@ -187,4 +185,43 @@ public class PGLexer extends Lexer {
|
||||
token = Token.POUND;
|
||||
}
|
||||
}
|
||||
|
||||
protected void scanVariable_at() {
|
||||
if (ch != '@') {
|
||||
throw new ParserException("illegal variable. " + info());
|
||||
}
|
||||
|
||||
mark = pos;
|
||||
bufPos = 1;
|
||||
char ch;
|
||||
|
||||
final char c1 = charAt(pos + 1);
|
||||
if (c1 == '@') {
|
||||
pos += 2;
|
||||
token = Token.MONKEYS_AT_AT;
|
||||
this.ch = charAt(++pos);
|
||||
return;
|
||||
} else if (c1 == '>') {
|
||||
pos += 2;
|
||||
token = Token.MONKEYS_AT_GT;
|
||||
this.ch = charAt(++pos);
|
||||
return;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
ch = charAt(++pos);
|
||||
|
||||
if (!isIdentifierChar(ch)) {
|
||||
break;
|
||||
}
|
||||
|
||||
bufPos++;
|
||||
continue;
|
||||
}
|
||||
|
||||
this.ch = charAt(pos);
|
||||
|
||||
stringVal = addSymbol();
|
||||
token = Token.VARIANT;
|
||||
}
|
||||
}
|
||||
|
||||
+13
-4
@@ -38,6 +38,7 @@ import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerSetTransactionI
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerUpdateStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerWaitForStatement;
|
||||
import com.alibaba.druid.sql.parser.*;
|
||||
import com.alibaba.druid.util.FnvHash;
|
||||
|
||||
public class SQLServerStatementParser extends SQLStatementParser {
|
||||
|
||||
@@ -64,7 +65,7 @@ public class SQLServerStatementParser extends SQLStatementParser {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals("EXEC") || lexer.identifierEquals("EXECUTE")) {
|
||||
if (lexer.identifierEquals(FnvHash.Constants.EXEC) || lexer.identifierEquals(FnvHash.Constants.EXECUTE)) {
|
||||
lexer.nextToken();
|
||||
|
||||
SQLServerExecStatement execStmt = new SQLServerExecStatement();
|
||||
@@ -109,10 +110,18 @@ public class SQLServerStatementParser extends SQLStatementParser {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals("WAITFOR")) {
|
||||
if (lexer.identifierEquals(FnvHash.Constants.WAITFOR)) {
|
||||
statementList.add(this.parseWaitFor());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (lexer.identifierEquals(FnvHash.Constants.GO)) {
|
||||
lexer.nextToken();
|
||||
|
||||
SQLStatement stmt = new SQLScriptCommitStatement();
|
||||
statementList.add(stmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -442,7 +451,7 @@ public class SQLServerStatementParser extends SQLStatementParser {
|
||||
|
||||
stmt.setCondition(this.exprParser.expr());
|
||||
|
||||
this.parseStatementList(stmt.getStatements(), 1);
|
||||
this.parseStatementList(stmt.getStatements(), 1, stmt);
|
||||
|
||||
if(lexer.token() == Token.SEMI) {
|
||||
lexer.nextToken();
|
||||
@@ -452,7 +461,7 @@ public class SQLServerStatementParser extends SQLStatementParser {
|
||||
lexer.nextToken();
|
||||
|
||||
SQLIfStatement.Else elseItem = new SQLIfStatement.Else();
|
||||
this.parseStatementList(elseItem.getStatements(), 1);
|
||||
this.parseStatementList(elseItem.getStatements(), 1, elseItem);
|
||||
stmt.setElseItem(elseItem);
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -573,4 +573,10 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLScriptCommitStatement x) {
|
||||
print0(ucase ? "GO" : "go");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user