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:
@@ -17,4 +17,8 @@ package com.alibaba.druid.sql.ast;
|
||||
|
||||
public interface SQLStatement extends SQLObject {
|
||||
String getDbType();
|
||||
|
||||
boolean isAfterSemi();
|
||||
|
||||
void setAfterSemi(boolean afterSemi);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ public abstract class SQLStatementImpl extends SQLObjectImpl implements SQLState
|
||||
|
||||
private String dbType;
|
||||
|
||||
private boolean afterSemi;
|
||||
|
||||
public SQLStatementImpl(){
|
||||
|
||||
}
|
||||
@@ -46,4 +48,12 @@ public abstract class SQLStatementImpl extends SQLObjectImpl implements SQLState
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
throw new UnsupportedOperationException(this.getClass().getName());
|
||||
}
|
||||
|
||||
public boolean isAfterSemi() {
|
||||
return afterSemi;
|
||||
}
|
||||
|
||||
public void setAfterSemi(boolean afterSemi) {
|
||||
this.afterSemi = afterSemi;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
public class SQLBlockStatement extends SQLStatementImpl {
|
||||
private String labelName;
|
||||
|
||||
private String endLabel;
|
||||
|
||||
private List<SQLParameter> parameters = new ArrayList<SQLParameter>();
|
||||
|
||||
private List<SQLStatement> statementList = new ArrayList<SQLStatement>();
|
||||
@@ -73,4 +75,12 @@ public class SQLBlockStatement extends SQLStatementImpl {
|
||||
public void setException(SQLStatement exception) {
|
||||
this.exception = exception;
|
||||
}
|
||||
|
||||
public String getEndLabel() {
|
||||
return endLabel;
|
||||
}
|
||||
|
||||
public void setEndLabel(String endLabel) {
|
||||
this.endLabel = endLabel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLCommentStatement extends SQLStatementImpl implements SQLStatement {
|
||||
public class SQLCommentStatement extends SQLStatementImpl {
|
||||
|
||||
public static enum Type {
|
||||
TABLE, COLUMN
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* 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.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.*;
|
||||
|
||||
@@ -72,6 +72,9 @@ public class SQLIfStatement extends SQLStatementImpl {
|
||||
}
|
||||
|
||||
public void setElseItem(Else elseItem) {
|
||||
if (elseItem != null) {
|
||||
elseItem.setParent(this);
|
||||
}
|
||||
this.elseItem = elseItem;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ public class SQLInsertStatement extends SQLInsertInto implements SQLStatement {
|
||||
|
||||
protected boolean upsert = false; // for phoenix
|
||||
|
||||
private boolean afterSemi;
|
||||
|
||||
public SQLInsertStatement(){
|
||||
|
||||
}
|
||||
@@ -105,4 +107,14 @@ public class SQLInsertStatement extends SQLInsertInto implements SQLStatement {
|
||||
public void setDbType(String dbType) {
|
||||
this.dbType = dbType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAfterSemi() {
|
||||
return afterSemi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAfterSemi(boolean afterSemi) {
|
||||
this.afterSemi = afterSemi;
|
||||
}
|
||||
}
|
||||
|
||||
+52
-41
@@ -1,41 +1,52 @@
|
||||
/*
|
||||
* 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.ast.SQLName;
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;
|
||||
|
||||
public class OracleSavePointStatement extends OracleStatementImpl {
|
||||
|
||||
private SQLName to;
|
||||
|
||||
@Override
|
||||
public void accept0(OracleASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, to);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLName getTo() {
|
||||
return to;
|
||||
}
|
||||
|
||||
public void setTo(SQLName to) {
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* 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.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLReturnStatement extends SQLStatementImpl {
|
||||
|
||||
private SQLExpr expr;
|
||||
|
||||
public SQLReturnStatement() {
|
||||
|
||||
}
|
||||
|
||||
public SQLReturnStatement(String dbType) {
|
||||
super (dbType);
|
||||
}
|
||||
|
||||
public SQLExpr getExpr() {
|
||||
return expr;
|
||||
}
|
||||
|
||||
public void setExpr(SQLExpr expr) {
|
||||
if (expr != null) {
|
||||
expr.setParent(this);
|
||||
}
|
||||
this.expr = expr;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, expr);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLUseStatement extends SQLStatementImpl implements SQLStatement {
|
||||
public class SQLUseStatement extends SQLStatementImpl {
|
||||
|
||||
private SQLName database;
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ import com.alibaba.druid.sql.dialect.odps.visitor.OdpsASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
public class OdpsInsertStatement extends SQLStatementImpl implements SQLStatement {
|
||||
public class OdpsInsertStatement extends SQLStatementImpl {
|
||||
|
||||
private SQLTableSource from;
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import com.alibaba.druid.sql.dialect.odps.visitor.OdpsASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
public class OdpsListStmt extends SQLStatementImpl implements SQLStatement {
|
||||
public class OdpsListStmt extends SQLStatementImpl {
|
||||
|
||||
private SQLExpr object;
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.dialect.odps.visitor.OdpsASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class OdpsShowGrantsStmt extends SQLStatementImpl implements SQLStatement {
|
||||
public class OdpsShowGrantsStmt extends SQLStatementImpl {
|
||||
|
||||
private SQLExpr user;
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import com.alibaba.druid.sql.dialect.odps.visitor.OdpsASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
public class OdpsShowPartitionsStmt extends SQLStatementImpl implements SQLStatement {
|
||||
public class OdpsShowPartitionsStmt extends SQLStatementImpl {
|
||||
|
||||
private SQLExprTableSource tableSource;
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import com.alibaba.druid.sql.dialect.odps.visitor.OdpsASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
public class OdpsShowStatisticStmt extends SQLStatementImpl implements SQLStatement {
|
||||
public class OdpsShowStatisticStmt extends SQLStatementImpl {
|
||||
|
||||
private SQLExprTableSource tableSource;
|
||||
|
||||
|
||||
+15
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* 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.ast.SQLName;
|
||||
|
||||
+3
-10
@@ -18,11 +18,12 @@ package com.alibaba.druid.sql.dialect.oracle.ast.stmt;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.OracleSQLObjectImpl;
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerStatementImpl;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitor;
|
||||
|
||||
public class OracleSetTransactionStatement extends OracleSQLObjectImpl implements OracleStatement {
|
||||
public class OracleSetTransactionStatement extends OracleStatementImpl implements OracleStatement {
|
||||
|
||||
private boolean readOnly = false;
|
||||
private String dbType;
|
||||
|
||||
private SQLExpr name;
|
||||
|
||||
@@ -50,12 +51,4 @@ public class OracleSetTransactionStatement extends OracleSQLObjectImpl implement
|
||||
this.readOnly = readOnly;
|
||||
}
|
||||
|
||||
public String getDbType() {
|
||||
return dbType;
|
||||
}
|
||||
|
||||
public void setDbType(String dbType) {
|
||||
this.dbType = dbType;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ public class OracleLexer extends Lexer {
|
||||
map.put("PRIOR", Token.PRIOR);
|
||||
|
||||
map.put("REJECT", Token.REJECT);
|
||||
map.put("RETURN", Token.RETURN);
|
||||
map.put("RETURNING", Token.RETURNING);
|
||||
map.put("SAVEPOINT", Token.SAVEPOINT);
|
||||
map.put("SESSION", Token.SESSION);
|
||||
|
||||
+54
-6
@@ -83,6 +83,10 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
|
||||
if (lexer.token() == (Token.SEMI)) {
|
||||
lexer.nextToken();
|
||||
if(statementList.size() > 0) {
|
||||
SQLStatement lastStmt = statementList.get(statementList.size() - 1);
|
||||
lastStmt.setAfterSemi(true);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -138,7 +142,9 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.WITH) {
|
||||
statementList.add(new SQLSelectStatement(new OracleSelectParser(this.exprParser).select()));
|
||||
SQLSelectStatement stmt = new SQLSelectStatement(this.createSQLSelectParser().select());
|
||||
stmt.setParent(parent);
|
||||
statementList.add(stmt);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -401,13 +407,18 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
if (lexer.token() == Token.SAVEPOINT) {
|
||||
lexer.nextToken();
|
||||
|
||||
OracleSavePointStatement stmt = new OracleSavePointStatement();
|
||||
SQLSavePointStatement stmt = new SQLSavePointStatement();
|
||||
stmt.setDbType(dbType);
|
||||
stmt.setParent(parent);
|
||||
|
||||
if (lexer.token() == Token.TO) {
|
||||
lexer.nextToken();
|
||||
stmt.setTo(this.exprParser.name());
|
||||
stmt.setName(this.exprParser.name());
|
||||
} else if (lexer.token() != Token.SEMI) {
|
||||
stmt.setName(this.exprParser.name());
|
||||
}
|
||||
accept(Token.SEMI);
|
||||
stmt.setAfterSemi(true);
|
||||
|
||||
statementList.add(stmt);
|
||||
continue;
|
||||
@@ -562,10 +573,31 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.RETURN) {
|
||||
SQLStatement stmt = this.parseReturn();
|
||||
stmt.setParent(parent);
|
||||
statementList.add(stmt);
|
||||
continue;
|
||||
}
|
||||
|
||||
throw new ParserException("TODO : " + lexer.info());
|
||||
}
|
||||
}
|
||||
|
||||
public SQLStatement parseReturn() {
|
||||
accept(Token.RETURN);
|
||||
SQLReturnStatement stmt = new SQLReturnStatement();
|
||||
if (lexer.token() != Token.SEMI) {
|
||||
SQLExpr expr = this.exprParser.expr();
|
||||
stmt.setExpr(expr);
|
||||
}
|
||||
|
||||
accept(Token.SEMI);
|
||||
stmt.setAfterSemi(true);
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
public SQLStatement parseWhile() {
|
||||
accept(Token.WHILE);
|
||||
|
||||
@@ -610,7 +642,7 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
acceptIdentifier("RETURN");
|
||||
accept(Token.RETURN);
|
||||
SQLDataType returnDataType = this.exprParser.parseDataType();
|
||||
stmt.setReturnDataType(returnDataType);
|
||||
|
||||
@@ -674,11 +706,13 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
if (lexer.token() != Token.SEMI) {
|
||||
stmt.setException(this.exprParser.expr());
|
||||
}
|
||||
accept(Token.SEMI);
|
||||
return stmt;
|
||||
}
|
||||
|
||||
public SQLStatement parseCase() {
|
||||
SQLCaseStatement caseStmt = new SQLCaseStatement();
|
||||
caseStmt.setDbType(dbType);
|
||||
lexer.nextToken();
|
||||
if (lexer.token() != Token.WHEN) {
|
||||
caseStmt.setValueExpr(this.exprParser.expr());
|
||||
@@ -713,6 +747,7 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
|
||||
accept(Token.END);
|
||||
accept(Token.CASE);
|
||||
accept(Token.SEMI);
|
||||
return caseStmt;
|
||||
}
|
||||
|
||||
@@ -783,6 +818,14 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
this.parseStatementList(stmt.getStatements(), -1, stmt);
|
||||
accept(Token.END);
|
||||
accept(Token.LOOP);
|
||||
|
||||
if (lexer.token() != Token.SEMI) {
|
||||
SQLName endLabel = this.exprParser.name();
|
||||
stmt.setEndLabel(endLabel);
|
||||
}
|
||||
|
||||
accept(Token.SEMI);
|
||||
stmt.setAfterSemi(true);
|
||||
}
|
||||
return stmt;
|
||||
}
|
||||
@@ -1304,6 +1347,13 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
|
||||
accept(Token.END);
|
||||
|
||||
if (lexer.token() != Token.SEMI) {
|
||||
String endLabel = lexer.stringVal();
|
||||
accept(Token.IDENTIFIER);
|
||||
block.setEndLabel(endLabel);
|
||||
}
|
||||
accept(Token.SEMI);
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
@@ -1990,12 +2040,10 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
SQLStatement function = this.parseFunction();
|
||||
function.setParent(stmt);
|
||||
stmt.getStatements().add(function);
|
||||
accept(Token.SEMI);
|
||||
} else if (lexer.token() == Token.PROCEDURE) {
|
||||
SQLStatement proc = this.parseCreateProcedure();
|
||||
proc.setParent(stmt);
|
||||
stmt.getStatements().add(proc);
|
||||
accept(Token.SEMI);
|
||||
} else if (lexer.token() == Token.END) {
|
||||
break;
|
||||
} else {
|
||||
|
||||
@@ -397,10 +397,6 @@ public interface OracleASTVisitor extends SQLASTVisitor {
|
||||
|
||||
void endVisit(OracleRaiseStatement x);
|
||||
|
||||
boolean visit(OracleSavePointStatement x);
|
||||
|
||||
void endVisit(OracleSavePointStatement x);
|
||||
|
||||
boolean visit(OracleCreateDatabaseDbLinkStatement x);
|
||||
|
||||
void endVisit(OracleCreateDatabaseDbLinkStatement x);
|
||||
|
||||
-10
@@ -957,16 +957,6 @@ public class OracleASTVisitorAdapter extends SQLASTVisitorAdapter implements Ora
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleSavePointStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(OracleSavePointStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleCreateDatabaseDbLinkStatement x) {
|
||||
return true;
|
||||
|
||||
+12
-71
@@ -100,44 +100,6 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
return printPostSemi;
|
||||
}
|
||||
|
||||
public void postVisit(SQLObject x) {
|
||||
if (!(x instanceof SQLStatement)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SQLObject parent = x.getParent();
|
||||
|
||||
if ((!isPrintPostSemi()) //
|
||||
&& (!(parent instanceof SQLBlockStatement))
|
||||
&& (!(parent instanceof OracleForStatement))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (x instanceof OraclePLSQLCommitStatement
|
||||
|| x instanceof OracleLabelStatement
|
||||
|| x instanceof OracleExceptionStatement.Item
|
||||
|| x instanceof OracleExceptionStatement
|
||||
|| x instanceof OracleCreatePackageStatement) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (parent instanceof SQLCreateProcedureStatement
|
||||
|| parent instanceof OracleExceptionStatement.Item
|
||||
|| parent instanceof OracleForStatement
|
||||
|| parent instanceof SQLCreateFunctionStatement) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isPrettyFormat()) {
|
||||
if (parent != null) {
|
||||
print(';');
|
||||
} else {
|
||||
println(";");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void printHints(List<SQLHint> hints) {
|
||||
if (hints.size() > 0) {
|
||||
print0("/*+ ");
|
||||
@@ -1386,13 +1348,10 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
}
|
||||
print0(ucase ? "BEGIN" : "begin");
|
||||
incrementIndent();
|
||||
println();
|
||||
|
||||
for (int i = 0, size = x.getStatementList().size(); i < size; ++i) {
|
||||
if (i != 0) {
|
||||
println();
|
||||
}
|
||||
println();
|
||||
SQLStatement stmt = x.getStatementList().get(i);
|
||||
stmt.setParent(x);
|
||||
stmt.accept(this);
|
||||
}
|
||||
decrementIndent();
|
||||
@@ -1404,7 +1363,7 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
}
|
||||
|
||||
println();
|
||||
print0(ucase ? "END" : "end");
|
||||
print0(ucase ? "END;" : "end;");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1519,7 +1478,6 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
}
|
||||
SQLStatement stmt = x.getStatements().get(i);
|
||||
stmt.accept(this);
|
||||
print(";");
|
||||
}
|
||||
|
||||
decrementIndent();
|
||||
@@ -1908,9 +1866,7 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
stmt.accept(this);
|
||||
if (!all) {
|
||||
if (i != size - 1) {
|
||||
println(";");
|
||||
} else {
|
||||
print(';');
|
||||
println();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1947,7 +1903,6 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
item.setParent(x);
|
||||
item.accept(this);
|
||||
}
|
||||
print(';');
|
||||
|
||||
decrementIndent();
|
||||
return false;
|
||||
@@ -1959,17 +1914,12 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
x.getCondition().accept(this);
|
||||
print0(ucase ? " THEN" : " then");
|
||||
incrementIndent();
|
||||
println();
|
||||
|
||||
for (int i = 0, size = x.getStatements().size(); i < size; ++i) {
|
||||
if (i != 0) {
|
||||
println();
|
||||
}
|
||||
println();
|
||||
SQLStatement item = x.getStatements().get(i);
|
||||
item.setParent(x);
|
||||
item.accept(this);
|
||||
}
|
||||
print(';');
|
||||
|
||||
decrementIndent();
|
||||
return false;
|
||||
@@ -1991,16 +1941,11 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
print0(ucase ? "THEN" : "then");
|
||||
|
||||
incrementIndent();
|
||||
println();
|
||||
for (int i = 0, size = x.getStatements().size(); i < size; ++i) {
|
||||
println();
|
||||
SQLStatement item = x.getStatements().get(i);
|
||||
item.setParent(x);
|
||||
item.accept(this);
|
||||
if (i != size - 1) {
|
||||
println();
|
||||
}
|
||||
}
|
||||
print(';');
|
||||
decrementIndent();
|
||||
|
||||
for (SQLIfStatement.ElseIf elseIf : x.getElseIfList()) {
|
||||
@@ -2013,7 +1958,7 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
x.getElseItem().accept(this);
|
||||
}
|
||||
println();
|
||||
print0(ucase ? "END IF" : "end if");
|
||||
print0(ucase ? "END IF;" : "end if;");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2528,6 +2473,7 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
print(' ');
|
||||
x.getException().accept(this);
|
||||
}
|
||||
print(';');
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2542,20 +2488,15 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleSavePointStatement x) {
|
||||
print0(ucase ? "ROLLBACK" : "rollback");
|
||||
if (x.getTo() != null) {
|
||||
public boolean visit(SQLSavePointStatement x) {
|
||||
print0(ucase ? "SAVEPOINT" : "savepoint");
|
||||
if (x.getName() != null) {
|
||||
print0(ucase ? " TO " : " to ");
|
||||
x.getTo().accept(this);
|
||||
x.getName().accept(this);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(OracleSavePointStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLCreateProcedureStatement x) {
|
||||
boolean create = x.isCreate();
|
||||
|
||||
-10
@@ -1290,16 +1290,6 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleSavePointStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(OracleSavePointStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleCreateDatabaseDbLinkStatement x) {
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.sqlserver.ast;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLObjectImpl;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public abstract class SQLServerStatementImpl extends SQLStatementImpl implements SQLServerStatement {
|
||||
|
||||
public SQLServerStatementImpl(){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
this.accept0((SQLServerASTVisitor) visitor);
|
||||
}
|
||||
|
||||
public abstract void accept0(SQLServerASTVisitor visitor);
|
||||
}
|
||||
+2
-11
@@ -18,9 +18,10 @@ package com.alibaba.druid.sql.dialect.sqlserver.ast.stmt;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerObjectImpl;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerStatementImpl;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitor;
|
||||
|
||||
public class SQLServerCommitStatement extends SQLServerObjectImpl implements SQLServerStatement {
|
||||
public class SQLServerCommitStatement extends SQLServerStatementImpl implements SQLServerStatement {
|
||||
|
||||
private boolean work = false;
|
||||
|
||||
@@ -28,8 +29,6 @@ public class SQLServerCommitStatement extends SQLServerObjectImpl implements SQL
|
||||
|
||||
private SQLExpr delayedDurability;
|
||||
|
||||
private String dbType;
|
||||
|
||||
public boolean isWork() {
|
||||
return work;
|
||||
}
|
||||
@@ -61,12 +60,4 @@ public class SQLServerCommitStatement extends SQLServerObjectImpl implements SQL
|
||||
public void setDelayedDurability(SQLExpr delayedDurability) {
|
||||
this.delayedDurability = delayedDurability;
|
||||
}
|
||||
|
||||
public String getDbType() {
|
||||
return dbType;
|
||||
}
|
||||
|
||||
public void setDbType(String dbType) {
|
||||
this.dbType = dbType;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-11
@@ -22,14 +22,14 @@ import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerObjectImpl;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerStatementImpl;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitor;
|
||||
|
||||
public class SQLServerExecStatement extends SQLServerObjectImpl implements SQLServerStatement {
|
||||
public class SQLServerExecStatement extends SQLServerStatementImpl implements SQLServerStatement {
|
||||
|
||||
private SQLName returnStatus;
|
||||
private SQLName moduleName;
|
||||
private List<SQLServerParameter> parameters = new ArrayList<SQLServerParameter>();
|
||||
private String dbType;
|
||||
|
||||
public SQLName getModuleName() {
|
||||
return moduleName;
|
||||
@@ -59,15 +59,7 @@ public class SQLServerExecStatement extends SQLServerObjectImpl implements SQLSe
|
||||
public void setReturnStatus(SQLName returnStatus) {
|
||||
this.returnStatus = returnStatus;
|
||||
}
|
||||
|
||||
public String getDbType() {
|
||||
return dbType;
|
||||
}
|
||||
|
||||
public void setDbType(String dbType) {
|
||||
this.dbType = dbType;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zz [455910092@qq.com]
|
||||
|
||||
+2
-10
@@ -19,12 +19,12 @@ import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAssignItem;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerObjectImpl;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerStatementImpl;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitor;
|
||||
|
||||
public class SQLServerSetStatement extends SQLServerObjectImpl implements SQLServerStatement {
|
||||
public class SQLServerSetStatement extends SQLServerStatementImpl implements SQLServerStatement {
|
||||
|
||||
private SQLAssignItem item = new SQLAssignItem();
|
||||
private String dbType;
|
||||
|
||||
public SQLServerSetStatement(){
|
||||
}
|
||||
@@ -53,12 +53,4 @@ public class SQLServerSetStatement extends SQLServerObjectImpl implements SQLSer
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public String getDbType() {
|
||||
return dbType;
|
||||
}
|
||||
|
||||
public void setDbType(String dbType) {
|
||||
this.dbType = dbType;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-10
@@ -17,12 +17,12 @@ package com.alibaba.druid.sql.dialect.sqlserver.ast.stmt;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerObjectImpl;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerStatementImpl;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitor;
|
||||
|
||||
public class SQLServerSetTransactionIsolationLevelStatement extends SQLServerObjectImpl implements SQLServerStatement {
|
||||
public class SQLServerSetTransactionIsolationLevelStatement extends SQLServerStatementImpl implements SQLServerStatement {
|
||||
|
||||
private String level;
|
||||
private String dbType;
|
||||
|
||||
@Override
|
||||
public void accept0(SQLServerASTVisitor visitor) {
|
||||
@@ -37,12 +37,4 @@ public class SQLServerSetTransactionIsolationLevelStatement extends SQLServerObj
|
||||
public void setLevel(String level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public String getDbType() {
|
||||
return dbType;
|
||||
}
|
||||
|
||||
public void setDbType(String dbType) {
|
||||
this.dbType = dbType;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-11
@@ -19,9 +19,10 @@ import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerObjectImpl;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerStatementImpl;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitor;
|
||||
|
||||
public class SQLServerWaitForStatement extends SQLServerObjectImpl implements SQLServerStatement {
|
||||
public class SQLServerWaitForStatement extends SQLServerStatementImpl implements SQLServerStatement {
|
||||
|
||||
private SQLExpr delay;
|
||||
|
||||
@@ -31,8 +32,6 @@ public class SQLServerWaitForStatement extends SQLServerObjectImpl implements SQ
|
||||
|
||||
private SQLExpr timeout;
|
||||
|
||||
private String dbType;
|
||||
|
||||
@Override
|
||||
public void accept0(SQLServerASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
@@ -75,12 +74,4 @@ public class SQLServerWaitForStatement extends SQLServerObjectImpl implements SQ
|
||||
public void setTimeout(SQLExpr timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
public String getDbType() {
|
||||
return dbType;
|
||||
}
|
||||
|
||||
public void setDbType(String dbType) {
|
||||
this.dbType = dbType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2222,6 +2222,7 @@ public class SQLStatementParser extends SQLParser {
|
||||
}
|
||||
}
|
||||
accept(Token.SEMI);
|
||||
stmt.setAfterSemi(true);
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@@ -2256,6 +2257,7 @@ public class SQLStatementParser extends SQLParser {
|
||||
accept(Token.CLOSE);
|
||||
stmt.setCursorName(exprParser.name().getSimpleName());
|
||||
accept(Token.SEMI);
|
||||
stmt.setAfterSemi(true);
|
||||
return stmt;
|
||||
}
|
||||
|
||||
|
||||
@@ -116,6 +116,8 @@ public enum Token {
|
||||
ANY("ANY"),
|
||||
TRUNCATE("TRUNCATE"),
|
||||
|
||||
RETURN("RETURN"),
|
||||
|
||||
// mysql
|
||||
TRUE("TRUE"),
|
||||
FALSE("FALSE"),
|
||||
|
||||
@@ -524,17 +524,19 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
println();
|
||||
printlnAndAccept(x.getItems(), " ");
|
||||
|
||||
if (x.getElseStatements() != null) {
|
||||
if (x.getElseStatements().size() > 0) {
|
||||
println();
|
||||
print0(ucase ? "ELSE " : "else ");
|
||||
printlnAndAccept(x.getElseStatements(), ";");
|
||||
print(';');
|
||||
printlnAndAccept(x.getElseStatements(), "");
|
||||
}
|
||||
|
||||
decrementIndent();
|
||||
|
||||
println();
|
||||
print0(ucase ? "END CASE" : "end case");
|
||||
if (JdbcConstants.ORACLE.equals(dbType)) {
|
||||
print(';');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2207,8 +2209,11 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLSavePointStatement x) {
|
||||
print0(ucase ? "SAVEPOINT " : "savepoint ");
|
||||
x.getName().accept(this);
|
||||
print0(ucase ? "SAVEPOINT" : "savepoint");
|
||||
if (x.getName() != null) {
|
||||
print(' ');
|
||||
x.getName().accept(this);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -3393,10 +3398,6 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
item.setParent(x);
|
||||
item.accept(this);
|
||||
|
||||
if (JdbcConstants.ORACLE.equals(dbType)) {
|
||||
print(";");
|
||||
}
|
||||
|
||||
if (i != size - 1) {
|
||||
println();
|
||||
}
|
||||
@@ -4241,4 +4242,24 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
this.printAndAccept(x.getItems(), ", ");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLReturnStatement x) {
|
||||
print0(ucase ? "RETURN" : "return");
|
||||
|
||||
if (x.getExpr() != null) {
|
||||
print(' ');
|
||||
x.getExpr().accept(this);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void postVisit(SQLObject x) {
|
||||
if (x instanceof SQLStatement) {
|
||||
SQLStatement stmt = (SQLStatement) x;
|
||||
if (stmt.isAfterSemi()) {
|
||||
print(';');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -713,4 +713,8 @@ public interface SQLASTVisitor {
|
||||
boolean visit(SQLDeclareStatement x);
|
||||
|
||||
void endVisit(SQLDeclareStatement x);
|
||||
|
||||
boolean visit(SQLReturnStatement x);
|
||||
|
||||
void endVisit(SQLReturnStatement x);
|
||||
}
|
||||
|
||||
@@ -558,7 +558,7 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLSavePointStatement x) {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1621,4 +1621,14 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
|
||||
public void endVisit(SQLDeclareStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLReturnStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLReturnStatement x) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user