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:
@@ -162,4 +162,17 @@ public class SQLAlterTableStatement extends SQLStatementImpl implements SQLDDLSt
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getSchema() {
|
||||
SQLName name = getName();
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (name instanceof SQLPropertyExpr) {
|
||||
return ((SQLPropertyExpr) name).getOwnernName();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.*;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -153,4 +154,17 @@ public class SQLCreateFunctionStatement extends SQLStatementImpl {
|
||||
public void setDeterministic(boolean deterministic) {
|
||||
this.deterministic = deterministic;
|
||||
}
|
||||
|
||||
public String getSchema() {
|
||||
SQLName name = getName();
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (name instanceof SQLPropertyExpr) {
|
||||
return ((SQLPropertyExpr) name).getOwnernName();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,4 +115,24 @@ public class SQLCreateIndexStatement extends SQLStatementImpl implements SQLDDLS
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public String getSchema() {
|
||||
SQLName name = null;
|
||||
if (table instanceof SQLExprTableSource) {
|
||||
SQLExpr expr = ((SQLExprTableSource) table).getExpr();
|
||||
if (expr instanceof SQLName) {
|
||||
name = (SQLName) expr;
|
||||
}
|
||||
}
|
||||
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (name instanceof SQLPropertyExpr) {
|
||||
return ((SQLPropertyExpr) name).getOwnernName();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
@@ -130,4 +131,17 @@ public class SQLCreateSequenceStatement extends SQLStatementImpl {
|
||||
public void setNoMinValue(boolean noMinValue) {
|
||||
this.noMinValue = noMinValue;
|
||||
}
|
||||
|
||||
public String getSchema() {
|
||||
SQLName name = getName();
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (name instanceof SQLPropertyExpr) {
|
||||
return ((SQLPropertyExpr) name).getOwnernName();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,26 @@ public class SQLCreateTableStatement extends SQLStatementImpl implements SQLDDLS
|
||||
return (SQLName) tableSource.getExpr();
|
||||
}
|
||||
|
||||
public String getSchema() {
|
||||
SQLName name = getName();
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (name instanceof SQLPropertyExpr) {
|
||||
return ((SQLPropertyExpr) name).getOwnernName();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setSchema(String name) {
|
||||
if (this.tableSource == null) {
|
||||
return;
|
||||
}
|
||||
tableSource.setSchema(name);
|
||||
}
|
||||
|
||||
public void setName(SQLName name) {
|
||||
this.setTableSource(new SQLExprTableSource(name));
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLLiteralExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLCreateViewStatement extends SQLStatementImpl implements SQLDDLStatement {
|
||||
@@ -73,6 +74,19 @@ public class SQLCreateViewStatement extends SQLStatementImpl implements SQLDDLSt
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getSchema() {
|
||||
SQLName name = getName();
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (name instanceof SQLPropertyExpr) {
|
||||
return ((SQLPropertyExpr) name).getOwnernName();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isOrReplace() {
|
||||
return orReplace;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLDropSequenceStatement extends SQLStatementImpl implements SQLDDLStatement {
|
||||
@@ -55,4 +56,17 @@ public class SQLDropSequenceStatement extends SQLStatementImpl implements SQLDDL
|
||||
public void setIfExists(boolean ifExists) {
|
||||
this.ifExists = ifExists;
|
||||
}
|
||||
|
||||
public String getSchema() {
|
||||
SQLName name = getName();
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (name instanceof SQLPropertyExpr) {
|
||||
return ((SQLPropertyExpr) name).getOwnernName();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,11 +18,14 @@ package com.alibaba.druid.sql.ast.statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLCommentHint;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLDropTableStatement extends SQLStatementImpl implements SQLDDLStatement {
|
||||
private List<SQLCommentHint> hints;
|
||||
|
||||
protected List<SQLExprTableSource> tableSources = new ArrayList<SQLExprTableSource>();
|
||||
|
||||
@@ -129,4 +132,11 @@ public class SQLDropTableStatement extends SQLStatementImpl implements SQLDDLSta
|
||||
this.temporary = temporary;
|
||||
}
|
||||
|
||||
public List<SQLCommentHint> getHints() {
|
||||
return hints;
|
||||
}
|
||||
|
||||
public void setHints(List<SQLCommentHint> hints) {
|
||||
this.hints = hints;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.repository.SchemaObject;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
@@ -57,6 +58,43 @@ public class SQLExprTableSource extends SQLTableSourceImpl {
|
||||
this.expr = expr;
|
||||
}
|
||||
|
||||
public SQLName getName() {
|
||||
if (expr instanceof SQLName) {
|
||||
return (SQLName) expr;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getSchema() {
|
||||
if (expr == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (expr instanceof SQLPropertyExpr) {
|
||||
return ((SQLPropertyExpr) expr).getOwnernName();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setSchema(String schema) {
|
||||
if (expr instanceof SQLIdentifierExpr) {
|
||||
if (schema == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String ident = ((SQLIdentifierExpr) expr).getName();
|
||||
this.setExpr(new SQLPropertyExpr(schema, ident));
|
||||
} else if (expr instanceof SQLPropertyExpr) {
|
||||
SQLPropertyExpr propertyExpr = (SQLPropertyExpr) expr;
|
||||
if (schema == null) {
|
||||
setExpr(new SQLIdentifierExpr(propertyExpr.getName()));
|
||||
} else {
|
||||
propertyExpr.setOwner(schema);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<SQLName> getPartitions() {
|
||||
if (this.partitions == null) {
|
||||
this.partitions = new ArrayList<SQLName>(2);
|
||||
|
||||
Reference in New Issue
Block a user