ameterizedOutputVisitorTest_6.java

This commit is contained in:
Yako
2014-10-27 14:34:02 +08:00
148 changed files with 1565 additions and 206 deletions
@@ -40,6 +40,7 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock;
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock.Limit;
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleSelectQueryBlock;
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock;
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.PGLimit;
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelectQueryBlock;
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerTop;
import com.alibaba.druid.util.JdbcConstants;
@@ -112,9 +113,30 @@ public class PagerUtils {
return limitMySqlQueryBlock((MySqlSelectQueryBlock) queryBlock, dbType, offset, count);
}
if (JdbcConstants.POSTGRESQL.equals(dbType))
{
return limitPostgreSQLQueryBlock((PGSelectQueryBlock) queryBlock, dbType, offset, count);
}
throw new UnsupportedOperationException();
}
private static String limitPostgreSQLQueryBlock(PGSelectQueryBlock queryBlock, String dbType,
int offset, int count) {
if (queryBlock.getLimit() != null)
{
throw new IllegalArgumentException("limit already exists.");
}
PGLimit limit = new PGLimit();
if (offset > 0)
{
limit.setOffset(new SQLNumberExpr(offset));
}
limit.setRowCount(new SQLNumberExpr(count));
queryBlock.setLimit(limit);
return SQLUtils.toSQLString(queryBlock, dbType);
}
private static String limitDB2(SQLSelect select, String dbType, int offset, int count) {
SQLSelectQuery query = select.getQuery();
@@ -20,12 +20,26 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public abstract class SQLStatementImpl extends SQLObjectImpl implements SQLStatement {
private String dbType;
public SQLStatementImpl(){
}
public SQLStatementImpl(String dbType){
this.dbType = dbType;
}
public String getDbType() {
return dbType;
}
public void setDbType(String dbType) {
this.dbType = dbType;
}
public String toString() {
return SQLUtils.toSQLString(this);
return SQLUtils.toSQLString(this, dbType);
}
@Override
@@ -26,6 +26,14 @@ public class SQLAlterTableStatement extends SQLStatementImpl implements SQLDDLSt
private SQLExprTableSource tableSource;
private List<SQLAlterTableItem> items = new ArrayList<SQLAlterTableItem>();
public SQLAlterTableStatement() {
}
public SQLAlterTableStatement(String dbType) {
super (dbType);
}
public List<SQLAlterTableItem> getItems() {
return items;
@@ -33,6 +33,14 @@ public class SQLCallStatement extends SQLStatementImpl {
private SQLName procedureName;
private final List<SQLExpr> parameters = new ArrayList<SQLExpr>();
public SQLCallStatement() {
}
public SQLCallStatement(String dbType) {
super (dbType);
}
public SQLVariantRefExpr getOutParameter() {
return outParameter;
@@ -33,6 +33,10 @@ public class SQLCreateDatabaseStatement extends SQLStatementImpl {
public SQLCreateDatabaseStatement(){
}
public SQLCreateDatabaseStatement(String dbType){
super (dbType);
}
@Override
protected void accept0(SQLASTVisitor visitor) {
@@ -35,6 +35,10 @@ public class SQLCreateIndexStatement extends SQLStatementImpl implements SQLDDLS
public SQLCreateIndexStatement(){
}
public SQLCreateIndexStatement(String dbType){
super (dbType);
}
public SQLTableSource getTable() {
return table;
@@ -24,6 +24,7 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLCreateTableStatement extends SQLStatementImpl implements SQLDDLStatement {
protected boolean ifNotExiists = false;
protected Type type;
protected SQLExprTableSource tableSource;
@@ -32,6 +33,10 @@ public class SQLCreateTableStatement extends SQLStatementImpl implements SQLDDLS
public SQLCreateTableStatement(){
}
public SQLCreateTableStatement(String dbType){
super (dbType);
}
public SQLName getName() {
if (tableSource == null) {
@@ -71,6 +76,14 @@ public class SQLCreateTableStatement extends SQLStatementImpl implements SQLDDLS
public List<SQLTableElement> getTableElementList() {
return tableElementList;
}
public boolean isIfNotExiists() {
return ifNotExiists;
}
public void setIfNotExiists(boolean ifNotExiists) {
this.ifNotExiists = ifNotExiists;
}
@Override
public void output(StringBuffer buf) {
@@ -37,6 +37,14 @@ public class SQLCreateTriggerStatement extends SQLStatementImpl {
private boolean forEachRow = false;
private SQLStatement body;
public SQLCreateTriggerStatement() {
}
public SQLCreateTriggerStatement(String dbType) {
super (dbType);
}
protected void accept0(SQLASTVisitor visitor) {
if (visitor.visit(this)) {
@@ -36,6 +36,10 @@ public class SQLCreateViewStatement extends SQLStatementImpl implements SQLDDLSt
public SQLCreateViewStatement(){
}
public SQLCreateViewStatement(String dbType){
super (dbType);
}
public boolean isOrReplace() {
return orReplace;
@@ -29,6 +29,10 @@ public class SQLDeleteStatement extends SQLStatementImpl {
public SQLDeleteStatement(){
}
public SQLDeleteStatement(String dbType){
super (dbType);
}
public SQLTableSource getTableSource() {
return tableSource;
@@ -23,6 +23,14 @@ public class SQLDropDatabaseStatement extends SQLStatementImpl implements SQLDDL
private SQLExpr database;
private boolean ifExists;
public SQLDropDatabaseStatement() {
}
public SQLDropDatabaseStatement(String dbType) {
super (dbType);
}
@Override
protected void accept0(SQLASTVisitor visitor) {
@@ -23,6 +23,14 @@ public class SQLDropFunctionStatement extends SQLStatementImpl implements SQLDDL
private SQLName name;
private boolean ifExists;
public SQLDropFunctionStatement() {
}
public SQLDropFunctionStatement(String dbType) {
super (dbType);
}
@Override
protected void accept0(SQLASTVisitor visitor) {
@@ -23,6 +23,14 @@ public class SQLDropIndexStatement extends SQLStatementImpl implements SQLDDLSta
private SQLExpr indexName;
private SQLExprTableSource tableName;
public SQLDropIndexStatement() {
}
public SQLDropIndexStatement(String dbType) {
super (dbType);
}
public SQLExpr getIndexName() {
return indexName;
@@ -23,6 +23,14 @@ public class SQLDropProcedureStatement extends SQLStatementImpl implements SQLDD
private SQLName name;
private boolean ifExists;
public SQLDropProcedureStatement() {
}
public SQLDropProcedureStatement(String dbType) {
super (dbType);
}
@Override
protected void accept0(SQLASTVisitor visitor) {
@@ -22,6 +22,14 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLDropSequenceStatement extends SQLStatementImpl implements SQLDDLStatement {
private SQLName name;
public SQLDropSequenceStatement() {
}
public SQLDropSequenceStatement(String dbType) {
super (dbType);
}
@Override
protected void accept0(SQLASTVisitor visitor) {
@@ -23,6 +23,14 @@ public class SQLDropTableSpaceStatement extends SQLStatementImpl implements SQLD
private SQLName name;
private boolean ifExists;
public SQLDropTableSpaceStatement() {
}
public SQLDropTableSpaceStatement(String dbType) {
super (dbType);
}
@Override
protected void accept0(SQLASTVisitor visitor) {
@@ -36,12 +36,25 @@ public class SQLDropTableStatement extends SQLStatementImpl implements SQLDDLSta
public SQLDropTableStatement(){
}
public SQLDropTableStatement(SQLName name){
this(new SQLExprTableSource(name));
public SQLDropTableStatement(String dbType){
super (dbType);
}
public SQLDropTableStatement(SQLName name, String dbType){
this(new SQLExprTableSource(name), dbType);
}
public SQLDropTableStatement(SQLName name){
this (name, null);
}
public SQLDropTableStatement(SQLExprTableSource tableSource){
this (tableSource, null);
}
public SQLDropTableStatement(SQLExprTableSource tableSource, String dbType){
this (dbType);
this.tableSources.add(tableSource);
}
@@ -22,6 +22,14 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLDropTriggerStatement extends SQLStatementImpl implements SQLDDLStatement {
private SQLName name;
public SQLDropTriggerStatement() {
}
public SQLDropTriggerStatement(String dbType) {
super (dbType);
}
public SQLName getName() {
return name;
@@ -25,6 +25,14 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLDropUserStatement extends SQLStatementImpl implements SQLDDLStatement {
private List<SQLExpr> users = new ArrayList<SQLExpr>(2);
public SQLDropUserStatement() {
}
public SQLDropUserStatement(String dbType) {
super (dbType);
}
public List<SQLExpr> getUsers() {
return users;
@@ -33,6 +33,10 @@ public class SQLDropViewStatement extends SQLStatementImpl implements SQLDDLStat
public SQLDropViewStatement(){
}
public SQLDropViewStatement(String dbType){
super (dbType);
}
public SQLDropViewStatement(SQLName name){
this(new SQLExprTableSource(name));
@@ -27,6 +27,14 @@ public class SQLExplainStatement extends SQLStatementImpl {
protected SQLStatement statement;
private List<SQLCommentHint> hints;
public SQLExplainStatement() {
}
public SQLExplainStatement(String dbType) {
super (dbType);
}
public SQLStatement getStatement() {
return statement;
@@ -28,6 +28,14 @@ public class SQLGrantStatement extends SQLStatementImpl {
private SQLExpr on;
private SQLExpr to;
public SQLGrantStatement() {
}
public SQLGrantStatement(String dbType) {
super (dbType);
}
// mysql
private ObjectType objectType;
@@ -22,6 +22,14 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLReleaseSavePointStatement extends SQLStatementImpl {
private SQLExpr name;
public SQLReleaseSavePointStatement() {
}
public SQLReleaseSavePointStatement(String dbType) {
super (dbType);
}
public SQLExpr getName() {
return name;
@@ -22,6 +22,14 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLRollbackStatement extends SQLStatementImpl {
private SQLName to;
public SQLRollbackStatement() {
}
public SQLRollbackStatement(String dbType) {
super (dbType);
}
@Override
protected void accept0(SQLASTVisitor visitor) {
@@ -22,6 +22,14 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLSavePointStatement extends SQLStatementImpl {
private SQLExpr name;
public SQLSavePointStatement() {
}
public SQLSavePointStatement(String dbType) {
super (dbType);
}
public SQLExpr getName() {
return name;
@@ -26,10 +26,19 @@ public class SQLSelectStatement extends SQLStatementImpl {
}
public SQLSelectStatement(String dbType){
super (dbType);
}
public SQLSelectStatement(SQLSelect select){
this.setSelect(select);
}
public SQLSelectStatement(SQLSelect select, String dbType){
this(dbType);
this.setSelect(select);
}
public SQLSelect getSelect() {
return this.select;
}
@@ -31,8 +31,17 @@ public class SQLSetStatement extends SQLStatementImpl {
public SQLSetStatement(){
}
public SQLSetStatement(String dbType){
super (dbType);
}
public SQLSetStatement(SQLExpr target, SQLExpr value){
this(target, value, null);
}
public SQLSetStatement(SQLExpr target, SQLExpr value, String dbType){
super (dbType);
this.items.add(new SQLAssignItem(target, value));
}
@@ -31,6 +31,14 @@ public class SQLTruncateStatement extends SQLStatementImpl {
private boolean only;
private Boolean restartIdentity;
private Boolean cascade;
public SQLTruncateStatement() {
}
public SQLTruncateStatement(String dbType) {
super (dbType);
}
public List<SQLExprTableSource> getTableSources() {
return tableSources;
@@ -33,6 +33,10 @@ public class SQLUpdateStatement extends SQLStatementImpl {
public SQLUpdateStatement(){
}
public SQLUpdateStatement(String dbType){
super (dbType);
}
public SQLTableSource getTableSource() {
return tableSource;
@@ -23,6 +23,14 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class SQLUseStatement extends SQLStatementImpl implements SQLStatement {
private SQLName database;
public SQLUseStatement() {
}
public SQLUseStatement(String dbType) {
super (dbType);
}
public SQLName getDatabase() {
return database;
@@ -18,8 +18,14 @@ package com.alibaba.druid.sql.dialect.db2.ast;
import com.alibaba.druid.sql.ast.SQLStatementImpl;
import com.alibaba.druid.sql.dialect.db2.visitor.DB2ASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.JdbcConstants;
public abstract class DB2StatementImpl extends SQLStatementImpl implements DB2Object {
public DB2StatementImpl() {
super(JdbcConstants.DB2);
}
@Override
protected void accept0(SQLASTVisitor visitor) {
if (visitor instanceof DB2ASTVisitor) {
@@ -18,10 +18,15 @@ package com.alibaba.druid.sql.dialect.mysql.ast.statement;
import com.alibaba.druid.sql.ast.statement.SQLAlterTableStatement;
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.JdbcConstants;
public class MySqlAlterTableStatement extends SQLAlterTableStatement {
private boolean ignore = false;
public MySqlAlterTableStatement() {
super (JdbcConstants.MYSQL);
}
@Override
protected void accept0(SQLASTVisitor visitor) {
@@ -18,10 +18,15 @@ package com.alibaba.druid.sql.dialect.mysql.ast.statement;
import com.alibaba.druid.sql.ast.statement.SQLCreateIndexStatement;
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.JdbcConstants;
public class MySqlCreateIndexStatement extends SQLCreateIndexStatement implements MySqlStatement {
private String using;
public MySqlCreateIndexStatement() {
super (JdbcConstants.MYSQL);
}
public String getUsing() {
return using;
@@ -31,11 +31,10 @@ import com.alibaba.druid.sql.ast.statement.SQLSelect;
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlObjectImpl;
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.JdbcConstants;
public class MySqlCreateTableStatement extends SQLCreateTableStatement implements MySqlStatement {
private boolean ifNotExiists = false;
private Map<String, SQLObject> tableOptions = new LinkedHashMap<String, SQLObject>();
protected SQLSelect query;
@@ -49,7 +48,7 @@ public class MySqlCreateTableStatement extends SQLCreateTableStatement implement
private SQLExprTableSource like;
public MySqlCreateTableStatement(){
super (JdbcConstants.MYSQL);
}
public SQLExprTableSource getLike() {
@@ -99,14 +98,6 @@ public class MySqlCreateTableStatement extends SQLCreateTableStatement implement
this.query = query;
}
public boolean isIfNotExiists() {
return ifNotExiists;
}
public void setIfNotExiists(boolean ifNotExiists) {
this.ifNotExiists = ifNotExiists;
}
@Override
protected void accept0(SQLASTVisitor visitor) {
if (visitor instanceof MySqlASTVisitor) {
@@ -22,6 +22,7 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock.L
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlOutputVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.JdbcConstants;
public class MySqlDeleteStatement extends SQLDeleteStatement {
@@ -33,6 +34,10 @@ public class MySqlDeleteStatement extends SQLDeleteStatement {
private SQLTableSource using;
private SQLOrderBy orderBy;
private Limit limit;
public MySqlDeleteStatement() {
super (JdbcConstants.MYSQL);
}
public boolean isLowPriority() {
return lowPriority;
@@ -19,6 +19,7 @@ import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.statement.SQLRollbackStatement;
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.JdbcConstants;
public class MySqlRollbackStatement extends SQLRollbackStatement implements MySqlStatement {
@@ -28,7 +29,7 @@ public class MySqlRollbackStatement extends SQLRollbackStatement implements MySq
private SQLExpr force;
public MySqlRollbackStatement(){
super (JdbcConstants.MYSQL);
}
public Boolean getChain() {
@@ -18,9 +18,14 @@ package com.alibaba.druid.sql.dialect.mysql.ast.statement;
import com.alibaba.druid.sql.ast.SQLStatementImpl;
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.JdbcConstants;
public abstract class MySqlStatementImpl extends SQLStatementImpl implements MySqlStatement {
public MySqlStatementImpl() {
super(JdbcConstants.MYSQL);
}
@Override
protected void accept0(SQLASTVisitor visitor) {
if (visitor instanceof MySqlASTVisitor) {
@@ -20,6 +20,7 @@ import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock.Limit;
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.JdbcConstants;
public class MySqlUpdateStatement extends SQLUpdateStatement implements MySqlStatement {
@@ -28,6 +29,10 @@ public class MySqlUpdateStatement extends SQLUpdateStatement implements MySqlSta
private boolean lowPriority = false;
private boolean ignore = false;
public MySqlUpdateStatement() {
super (JdbcConstants.MYSQL);
}
public Limit getLimit() {
return limit;
@@ -22,6 +22,7 @@ import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
import com.alibaba.druid.sql.ast.statement.SQLForeignKeyConstraint;
import com.alibaba.druid.sql.ast.statement.SQLSelect;
import com.alibaba.druid.sql.ast.statement.SQLTableConstraint;
import com.alibaba.druid.sql.ast.statement.SQLTableSource;
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlKey;
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlPrimaryKey;
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlUnique;
@@ -338,6 +339,29 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
stmt.getTableOptions().put("STATS_PERSISTENT", this.exprParser.expr());
continue;
}
if (identifierEquals("STATS_SAMPLE_PAGES")) {
lexer.nextToken();
if (lexer.token() == Token.EQ) {
lexer.nextToken();
}
stmt.getTableOptions().put("STATS_SAMPLE_PAGES", this.exprParser.expr());
continue;
}
if (lexer.token() == Token.UNION) {
lexer.nextToken();
if (lexer.token() == Token.EQ) {
lexer.nextToken();
}
accept(Token.LPAREN);
SQLTableSource tableSrc = this.createSQLSelectParser().parseTableSource();
stmt.getTableOptions().put("UNION", tableSrc);
accept(Token.RPAREN);
continue;
}
if (lexer.token() == Token.TABLESPACE) {
lexer.nextToken();
@@ -147,6 +147,7 @@ import com.alibaba.druid.sql.parser.ParserException;
import com.alibaba.druid.sql.parser.SQLSelectParser;
import com.alibaba.druid.sql.parser.SQLStatementParser;
import com.alibaba.druid.sql.parser.Token;
import com.alibaba.druid.util.JdbcConstants;
public class MySqlStatementParser extends SQLStatementParser {
@@ -191,7 +192,7 @@ public class MySqlStatementParser extends SQLStatementParser {
public SQLSelectStatement parseSelect() {
MySqlSelectParser selectParser = new MySqlSelectParser(this.exprParser);
return new SQLSelectStatement(selectParser.select());
return new SQLSelectStatement(selectParser.select(), JdbcConstants.MYSQL);
}
public SQLUpdateStatement parseUpdateStatement() {
@@ -2131,7 +2132,7 @@ public class MySqlStatementParser extends SQLStatementParser {
}
return stmt;
} else {
SQLSetStatement stmt = new SQLSetStatement();
SQLSetStatement stmt = new SQLSetStatement(getDbType());
parseAssignItems(stmt.getItems(), stmt);
@@ -2375,6 +2376,11 @@ public class MySqlStatementParser extends SQLStatementParser {
throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
} else if (identifierEquals("REMOVE")) {
throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
} else if (identifierEquals("ALGORITHM")) {
lexer.nextToken();
accept(Token.EQ);
stmt.getItems().add(new MySqlAlterTableOption("ALGORITHM", lexer.stringVal()));
lexer.nextToken();
} else if (identifierEquals(ENGINE)) {
lexer.nextToken();
accept(Token.EQ);
@@ -2531,7 +2537,7 @@ public class MySqlStatementParser extends SQLStatementParser {
accept(Token.DATABASE);
SQLCreateDatabaseStatement stmt = new SQLCreateDatabaseStatement();
SQLCreateDatabaseStatement stmt = new SQLCreateDatabaseStatement(JdbcConstants.MYSQL);
stmt.setName(this.exprParser.name());
if (lexer.token() == Token.DEFAULT) {
@@ -479,6 +479,11 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
print(' ');
option.getValue().accept(this);
continue;
} else if ("UNION".equals(key)) {
print(" = (");
option.getValue().accept(this);
print(')');
continue;
}
print(" = ");
@@ -27,6 +27,7 @@ import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
import com.alibaba.druid.sql.ast.statement.SQLTableSource;
import com.alibaba.druid.sql.ast.statement.SQLUnionQuery;
import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement;
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlForceIndexHint;
@@ -1157,7 +1158,15 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
@Override
public boolean visit(MySqlCreateTableStatement x) {
return super.visit((SQLCreateTableStatement) x);
boolean val = super.visit((SQLCreateTableStatement) x);
for (SQLObject option : x.getTableOptions().values()) {
if (option instanceof SQLTableSource) {
option.accept(this);
}
}
return val;
}
@Override
@@ -1342,7 +1351,7 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
@Override
public void endVisit(MySqlHintStatement x) {
}
@Override
@@ -25,23 +25,20 @@ import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
import com.alibaba.druid.sql.dialect.odps.visitor.OdpsASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.JdbcConstants;
public class OdpsCreateTableStatement extends SQLCreateTableStatement {
private boolean ifNotExiists = false;
private SQLExprTableSource like;
protected SQLExpr comment;
protected List<SQLColumnDefinition> partitionColumns = new ArrayList<SQLColumnDefinition>(2);
public boolean isIfNotExiists() {
return ifNotExiists;
}
public void setIfNotExiists(boolean ifNotExiists) {
this.ifNotExiists = ifNotExiists;
protected SQLExpr lifecycle;
public OdpsCreateTableStatement() {
super (JdbcConstants.ODPS);
}
public SQLExprTableSource getLike() {
@@ -67,7 +64,15 @@ public class OdpsCreateTableStatement extends SQLCreateTableStatement {
public List<SQLColumnDefinition> getPartitionColumns() {
return partitionColumns;
}
public SQLExpr getLifecycle() {
return lifecycle;
}
public void setLifecycle(SQLExpr lifecycle) {
this.lifecycle = lifecycle;
}
@Override
protected void accept0(SQLASTVisitor visitor) {
accept0((OdpsASTVisitor) visitor);
@@ -78,7 +83,9 @@ public class OdpsCreateTableStatement extends SQLCreateTableStatement {
this.acceptChild(visitor, tableSource);
this.acceptChild(visitor, tableElementList);
this.acceptChild(visitor, partitionColumns);
this.acceptChild(visitor, lifecycle);
}
visitor.endVisit(this);
}
}
}
@@ -23,12 +23,17 @@ import com.alibaba.druid.sql.ast.SQLStatementImpl;
import com.alibaba.druid.sql.ast.statement.SQLSubqueryTableSource;
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 {
private SQLSubqueryTableSource from;
private List<OdpsInsert> items = new ArrayList<OdpsInsert>();
public OdpsInsertStatement() {
super (JdbcConstants.ODPS);
}
public void setFrom(SQLSubqueryTableSource from) {
this.from = from;
@@ -0,0 +1,37 @@
package com.alibaba.druid.sql.dialect.odps.ast;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.ast.SQLStatementImpl;
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
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 {
private SQLExprTableSource tableSource;
public OdpsShowPartitionsStmt() {
super (JdbcConstants.ODPS);
}
public SQLExprTableSource getTableSource() {
return tableSource;
}
public void setTableSource(SQLExprTableSource tableSource) {
this.tableSource = tableSource;
}
@Override
protected void accept0(SQLASTVisitor visitor) {
accept0((OdpsASTVisitor) visitor);
}
protected void accept0(OdpsASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, tableSource);
}
visitor.endVisit(this);
}
}
@@ -0,0 +1,37 @@
package com.alibaba.druid.sql.dialect.odps.ast;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.ast.SQLStatementImpl;
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
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 {
private SQLExprTableSource tableSource;
public OdpsShowStatisticStmt() {
super (JdbcConstants.ODPS);
}
public SQLExprTableSource getTableSource() {
return tableSource;
}
public void setTableSource(SQLExprTableSource tableSource) {
this.tableSource = tableSource;
}
@Override
protected void accept0(SQLASTVisitor visitor) {
accept0((OdpsASTVisitor) visitor);
}
protected void accept0(OdpsASTVisitor visitor) {
if (visitor.visit(this)) {
acceptChild(visitor, tableSource);
}
visitor.endVisit(this);
}
}
@@ -105,6 +105,11 @@ public class OdpsCreateTableParser extends SQLCreateTableParser {
accept(Token.RPAREN);
}
if (identifierEquals("LIFECYCLE")) {
lexer.nextToken();
stmt.setLifecycle(this.exprParser.expr());
}
return stmt;
}
}
@@ -34,6 +34,7 @@ public class OdpsLexer extends Lexer {
map.putAll(Keywords.DEFAULT_KEYWORDS.getKeywords());
map.put("SHOW", Token.SHOW);
map.put("PARTITION", Token.PARTITION);
map.put("PARTITIONED", Token.PARTITIONED);
map.put("OVERWRITE", Token.OVERWRITE);
@@ -21,10 +21,14 @@ import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.ast.statement.SQLAssignItem;
import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
import com.alibaba.druid.sql.ast.statement.SQLSelect;
import com.alibaba.druid.sql.ast.statement.SQLSubqueryTableSource;
import com.alibaba.druid.sql.dialect.odps.ast.OdpsInsert;
import com.alibaba.druid.sql.dialect.odps.ast.OdpsInsertStatement;
import com.alibaba.druid.sql.dialect.odps.ast.OdpsShowPartitionsStmt;
import com.alibaba.druid.sql.dialect.odps.ast.OdpsShowStatisticStmt;
import com.alibaba.druid.sql.parser.ParserException;
import com.alibaba.druid.sql.parser.SQLCreateTableParser;
import com.alibaba.druid.sql.parser.SQLExprParser;
import com.alibaba.druid.sql.parser.SQLSelectParser;
@@ -134,4 +138,31 @@ public class OdpsStatementParser extends SQLStatementParser {
return insert;
}
public SQLStatement parseShow() {
accept(Token.SHOW);
if (identifierEquals("PARTITIONS")) {
lexer.nextToken();
OdpsShowPartitionsStmt stmt = new OdpsShowPartitionsStmt();
SQLExpr expr = this.exprParser.expr();
stmt.setTableSource(new SQLExprTableSource(expr));
return stmt;
}
if (identifierEquals("STATISTIC")) {
lexer.nextToken();
OdpsShowStatisticStmt stmt = new OdpsShowStatisticStmt();
SQLExpr expr = this.exprParser.expr();
stmt.setTableSource(new SQLExprTableSource(expr));
return stmt;
}
throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
}
}
@@ -18,6 +18,8 @@ package com.alibaba.druid.sql.dialect.odps.visitor;
import com.alibaba.druid.sql.dialect.odps.ast.OdpsCreateTableStatement;
import com.alibaba.druid.sql.dialect.odps.ast.OdpsInsert;
import com.alibaba.druid.sql.dialect.odps.ast.OdpsInsertStatement;
import com.alibaba.druid.sql.dialect.odps.ast.OdpsShowPartitionsStmt;
import com.alibaba.druid.sql.dialect.odps.ast.OdpsShowStatisticStmt;
import com.alibaba.druid.sql.dialect.odps.ast.OdpsUDTFSQLSelectItem;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
@@ -38,4 +40,12 @@ public interface OdpsASTVisitor extends SQLASTVisitor {
void endVisit(OdpsUDTFSQLSelectItem x);
boolean visit(OdpsUDTFSQLSelectItem x);
void endVisit(OdpsShowPartitionsStmt x);
boolean visit(OdpsShowPartitionsStmt x);
void endVisit(OdpsShowStatisticStmt x);
boolean visit(OdpsShowStatisticStmt x);
}
@@ -29,6 +29,8 @@ import com.alibaba.druid.sql.ast.statement.SQLSubqueryTableSource;
import com.alibaba.druid.sql.dialect.odps.ast.OdpsCreateTableStatement;
import com.alibaba.druid.sql.dialect.odps.ast.OdpsInsert;
import com.alibaba.druid.sql.dialect.odps.ast.OdpsInsertStatement;
import com.alibaba.druid.sql.dialect.odps.ast.OdpsShowPartitionsStmt;
import com.alibaba.druid.sql.dialect.odps.ast.OdpsShowStatisticStmt;
import com.alibaba.druid.sql.dialect.odps.ast.OdpsUDTFSQLSelectItem;
import com.alibaba.druid.sql.visitor.SQLASTOutputVisitor;
@@ -89,6 +91,12 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
}
print(")");
}
if (x.getLifecycle() != null) {
println();
print("LIFECYCLE ");
x.getLifecycle().accept(this);
}
return false;
}
@@ -299,4 +307,28 @@ public class OdpsOutputVisitor extends SQLASTOutputVisitor implements OdpsASTVis
return false;
}
@Override
public void endVisit(OdpsShowPartitionsStmt x) {
}
@Override
public boolean visit(OdpsShowPartitionsStmt x) {
print("SHOW PARTITIONS ");
x.getTableSource().accept(this);
return false;
}
@Override
public void endVisit(OdpsShowStatisticStmt x) {
}
@Override
public boolean visit(OdpsShowStatisticStmt x) {
print("SHOW STATISTIC ");
x.getTableSource().accept(this);
return false;
}
}
@@ -19,6 +19,8 @@ import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
import com.alibaba.druid.sql.dialect.odps.ast.OdpsCreateTableStatement;
import com.alibaba.druid.sql.dialect.odps.ast.OdpsInsert;
import com.alibaba.druid.sql.dialect.odps.ast.OdpsInsertStatement;
import com.alibaba.druid.sql.dialect.odps.ast.OdpsShowPartitionsStmt;
import com.alibaba.druid.sql.dialect.odps.ast.OdpsShowStatisticStmt;
import com.alibaba.druid.sql.dialect.odps.ast.OdpsUDTFSQLSelectItem;
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
@@ -65,5 +67,25 @@ public class OdpsSchemaStatVisitor extends SchemaStatVisitor implements OdpsASTV
return true;
}
@Override
public void endVisit(OdpsShowPartitionsStmt x) {
}
@Override
public boolean visit(OdpsShowPartitionsStmt x) {
return true;
}
@Override
public void endVisit(OdpsShowStatisticStmt x) {
}
@Override
public boolean visit(OdpsShowStatisticStmt x) {
return true;
}
}
@@ -18,11 +18,16 @@ package com.alibaba.druid.sql.dialect.oracle.ast.stmt;
import com.alibaba.druid.sql.ast.statement.SQLAlterTableStatement;
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.JdbcConstants;
public class OracleAlterTableStatement extends SQLAlterTableStatement implements OracleDDLStatement {
private boolean updateGlobalIndexes = false;
private boolean invalidateGlobalIndexes = false;
public OracleAlterTableStatement() {
super (JdbcConstants.ORACLE);
}
protected void accept0(SQLASTVisitor visitor) {
accept0((OracleASTVisitor) visitor);
@@ -20,6 +20,7 @@ import com.alibaba.druid.sql.ast.SQLName;
import com.alibaba.druid.sql.ast.statement.SQLCreateIndexStatement;
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.JdbcConstants;
public class OracleCreateIndexStatement extends SQLCreateIndexStatement implements OracleDDLStatement {
@@ -41,6 +42,10 @@ public class OracleCreateIndexStatement extends SQLCreateIndexStatement implemen
private Boolean enable = null;
private boolean computeStatistics = false;
public OracleCreateIndexStatement() {
super (JdbcConstants.ORACLE);
}
public SQLName getTablespace() {
return tablespace;
@@ -24,6 +24,7 @@ import com.alibaba.druid.sql.dialect.oracle.ast.clause.OracleLobStorageClause;
import com.alibaba.druid.sql.dialect.oracle.ast.clause.OracleStorageClause;
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.JdbcConstants;
public class OracleCreateTableStatement extends SQLCreateTableStatement implements OracleDDLStatement {
@@ -58,6 +59,10 @@ public class OracleCreateTableStatement extends SQLCreateTableStatement implemen
private SQLPartitioningClause partitioning;
private DeferredSegmentCreation deferredSegmentCreation;
public OracleCreateTableStatement() {
super (JdbcConstants.ORACLE);
}
public OracleLobStorageClause getLobStorage() {
return lobStorage;
@@ -23,6 +23,7 @@ import com.alibaba.druid.sql.ast.statement.SQLDeleteStatement;
import com.alibaba.druid.sql.dialect.oracle.ast.clause.OracleReturningClause;
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.JdbcConstants;
public class OracleDeleteStatement extends SQLDeleteStatement {
@@ -32,7 +33,7 @@ public class OracleDeleteStatement extends SQLDeleteStatement {
private OracleReturningClause returning = null;
public OracleDeleteStatement(){
super (JdbcConstants.ORACLE);
}
public OracleReturningClause getReturning() {
@@ -21,11 +21,16 @@ import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
import com.alibaba.druid.sql.ast.statement.SQLExplainStatement;
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.JdbcConstants;
public class OracleExplainStatement extends SQLExplainStatement implements OracleStatement {
private SQLCharExpr statementId;
private SQLExpr into;
public OracleExplainStatement() {
super (JdbcConstants.ORACLE);
}
@Override
public void accept0(OracleASTVisitor visitor) {
@@ -19,8 +19,13 @@ import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.SQLStatementImpl;
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.JdbcConstants;
public abstract class OracleStatementImpl extends SQLStatementImpl implements OracleStatement {
public OracleStatementImpl() {
super(JdbcConstants.ORACLE);
}
protected void accept0(SQLASTVisitor visitor) {
accept0((OracleASTVisitor) visitor);
@@ -23,6 +23,7 @@ import com.alibaba.druid.sql.ast.SQLHint;
import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement;
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.JdbcConstants;
public class OracleUpdateStatement extends SQLUpdateStatement implements OracleStatement {
@@ -35,7 +36,7 @@ public class OracleUpdateStatement extends SQLUpdateStatement implements OracleS
private List<SQLExpr> returningInto = new ArrayList<SQLExpr>();
public OracleUpdateStatement(){
super (JdbcConstants.ORACLE);
}
public List<SQLExpr> getReturning() {
@@ -105,6 +105,7 @@ import com.alibaba.druid.sql.parser.Lexer;
import com.alibaba.druid.sql.parser.ParserException;
import com.alibaba.druid.sql.parser.SQLStatementParser;
import com.alibaba.druid.sql.parser.Token;
import com.alibaba.druid.util.JdbcConstants;
public class OracleStatementParser extends SQLStatementParser {
@@ -163,7 +164,8 @@ public class OracleStatementParser extends SQLStatementParser {
}
if (lexer.token() == (Token.SELECT)) {
statementList.add(new SQLSelectStatement(new OracleSelectParser(this.exprParser).select()));
SQLSelectStatement stmt = new SQLSelectStatement(new OracleSelectParser(this.exprParser).select(), JdbcConstants.ORACLE);
statementList.add(stmt);
continue;
}
@@ -238,7 +240,7 @@ public class OracleStatementParser extends SQLStatementParser {
if (variant instanceof SQLBinaryOpExpr) {
SQLBinaryOpExpr binaryOpExpr = (SQLBinaryOpExpr) variant;
if (binaryOpExpr.getOperator() == SQLBinaryOperator.Assignment) {
SQLSetStatement stmt = new SQLSetStatement(binaryOpExpr.getLeft(), binaryOpExpr.getRight());
SQLSetStatement stmt = new SQLSetStatement(binaryOpExpr.getLeft(), binaryOpExpr.getRight(), getDbType());
statementList.add(stmt);
continue;
}
@@ -246,7 +248,7 @@ public class OracleStatementParser extends SQLStatementParser {
accept(Token.COLONEQ);
SQLExpr value = this.exprParser.expr();
SQLSetStatement stmt = new SQLSetStatement(variant, value);
SQLSetStatement stmt = new SQLSetStatement(variant, value, getDbType());
statementList.add(stmt);
continue;
}
@@ -265,20 +265,7 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
}
public boolean visit(OracleSelect x) {
setCurrentTable(x);
if (x.getOrderBy() != null) {
x.getOrderBy().setParent(x);
}
accept(x.getWithSubQuery());
accept(x.getQuery());
setCurrentTable(x, (String) x.getQuery().getAttribute("table"));
accept(x.getOrderBy());
return false;
return visit((SQLSelect) x);
}
public void endVisit(SQLSelect x) {
@@ -23,6 +23,7 @@ import com.alibaba.druid.sql.ast.statement.SQLDeleteStatement;
import com.alibaba.druid.sql.dialect.postgresql.ast.PGWithClause;
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.JdbcConstants;
public class PGDeleteStatement extends SQLDeleteStatement implements PGSQLStatement {
@@ -31,6 +32,10 @@ public class PGDeleteStatement extends SQLDeleteStatement implements PGSQLStatem
private List<SQLName> using = new ArrayList<SQLName>(2);
private boolean returning;
private String alias;
public PGDeleteStatement() {
super (JdbcConstants.POSTGRESQL);
}
public boolean isReturning() {
return returning;
@@ -19,11 +19,13 @@ import java.util.ArrayList;
import java.util.List;
import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLObjectImpl;
import com.alibaba.druid.sql.ast.SQLOrderBy;
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
import com.alibaba.druid.sql.dialect.postgresql.ast.PGSQLObjectImpl;
import com.alibaba.druid.sql.dialect.postgresql.ast.PGWithClause;
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitor;
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGOutputVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public class PGSelectQueryBlock extends SQLSelectQueryBlock {
@@ -247,5 +249,63 @@ public class PGSelectQueryBlock extends SQLSelectQueryBlock {
visitor.endVisit(this);
}
}
public static class PGLimit extends SQLObjectImpl implements SQLExpr {
public PGLimit(){
}
private SQLExpr rowCount;
private SQLExpr offset;
public SQLExpr getRowCount() {
return rowCount;
}
public void setRowCount(SQLExpr rowCount) {
if (rowCount != null) {
rowCount.setParent(this);
}
this.rowCount = rowCount;
}
public SQLExpr getOffset() {
return offset;
}
public void setOffset(SQLExpr offset) {
if (offset != null) {
offset.setParent(this);
}
this.offset = offset;
}
@Override
protected void accept0(SQLASTVisitor visitor) {
if (visitor instanceof PGASTVisitor) {
PGASTVisitor pgVisitor = (PGASTVisitor) visitor;
if (pgVisitor.visit(this)) {
if (pgVisitor instanceof PGOutputVisitor)
{
PGOutputVisitor pgv = (PGOutputVisitor) pgVisitor;
pgv.print(this.rowCount.toString());
if (this.offset != null)
{
pgv.print(" OFFSET ");
pgv.print(this.offset.toString());
}
}
else
{
acceptChild(visitor, offset);
acceptChild(visitor, rowCount);
}
}
pgVisitor.endVisit(this);
}
}
}
}
@@ -20,16 +20,18 @@ import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
import com.alibaba.druid.sql.dialect.postgresql.ast.PGWithClause;
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.JdbcConstants;
public class PGSelectStatement extends SQLSelectStatement implements PGSQLStatement {
private PGWithClause with;
public PGSelectStatement(){
super(JdbcConstants.POSTGRESQL);
}
public PGSelectStatement(SQLSelect select){
super(select);
super(select, JdbcConstants.POSTGRESQL);
}
public PGWithClause getWith() {
@@ -24,6 +24,7 @@ import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement;
import com.alibaba.druid.sql.dialect.postgresql.ast.PGWithClause;
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.JdbcConstants;
public class PGUpdateStatement extends SQLUpdateStatement implements PGSQLStatement {
@@ -34,6 +35,10 @@ public class PGUpdateStatement extends SQLUpdateStatement implements PGSQLStatem
private List<SQLExpr> returning = new ArrayList<SQLExpr>(2);
private SQLTableSource from;
public PGUpdateStatement(){
super (JdbcConstants.POSTGRESQL);
}
public SQLTableSource getFrom() {
return from;
@@ -27,6 +27,10 @@ import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGUpdateStatement;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public interface PGASTVisitor extends SQLASTVisitor {
boolean visit(PGSelectQueryBlock.PGLimit x);
void endVisit(PGSelectQueryBlock.PGLimit x);
void endVisit(PGSelectQueryBlock x);
@@ -24,6 +24,7 @@ import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGInsertStatement;
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock;
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.FetchClause;
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.ForClause;
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.PGLimit;
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.WindowClause;
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectStatement;
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGUpdateStatement;
@@ -156,4 +157,14 @@ public class PGASTVisitorAdapter extends SQLASTVisitorAdapter implements PGASTVi
return true;
}
@Override
public boolean visit(PGLimit x) {
return true;
}
@Override
public void endVisit(PGLimit x) {
}
}
@@ -27,6 +27,7 @@ import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGInsertStatement;
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock;
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.FetchClause;
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.ForClause;
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.PGLimit;
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.WindowClause;
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectStatement;
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGUpdateStatement;
@@ -470,4 +471,14 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
}
@Override
public boolean visit(PGLimit x) {
return true;
}
@Override
public void endVisit(PGLimit x) {
}
}
@@ -30,6 +30,7 @@ import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGInsertStatement;
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock;
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.FetchClause;
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.ForClause;
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.PGLimit;
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock.WindowClause;
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectStatement;
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGUpdateStatement;
@@ -264,4 +265,14 @@ public class PGSchemaStatVisitor extends SchemaStatVisitor implements PGASTVisit
public boolean visit(PGFunctionTableSource x) {
return true;
}
@Override
public boolean visit(PGLimit x) {
return false;
}
@Override
public void endVisit(PGLimit x) {
}
}
@@ -22,12 +22,17 @@ import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerStatement;
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerTop;
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.JdbcConstants;
public class SQLServerUpdateStatement extends SQLUpdateStatement implements SQLServerStatement {
private SQLServerTop top;
private SQLTableSource from;
private SQLServerOutput output;
public SQLServerUpdateStatement(){
super (JdbcConstants.SQL_SERVER);
}
public SQLServerTop getTop() {
return top;
@@ -374,7 +374,7 @@ public class SQLServerStatementParser extends SQLStatementParser {
}
if (lexer.token() == Token.VARIANT) {
SQLSetStatement stmt = new SQLSetStatement();
SQLSetStatement stmt = new SQLSetStatement(getDbType());
parseAssignItems(stmt.getItems(), stmt);
return stmt;
} else {
@@ -115,6 +115,6 @@ public class SQLCreateTableParser extends SQLDDLParser {
}
protected SQLCreateTableStatement newCreateStatement() {
return new SQLCreateTableStatement();
return new SQLCreateTableStatement(getDbType());
}
}
@@ -87,10 +87,18 @@ public class SQLExprParser extends SQLParser {
public SQLExprParser(String sql){
super(sql);
}
public SQLExprParser(String sql, String dbType){
super(sql, dbType);
}
public SQLExprParser(Lexer lexer){
super(lexer);
}
public SQLExprParser(Lexer lexer, String dbType){
super(lexer, dbType);
}
public SQLExpr expr() {
if (lexer.token() == Token.STAR) {
@@ -19,19 +19,34 @@ public class SQLParser {
protected final Lexer lexer;
public SQLParser(String sql){
this(new Lexer(sql));
protected String dbType;
public SQLParser(String sql, String dbType){
this(new Lexer(sql), dbType);
this.lexer.nextToken();
}
public SQLParser(String sql){
this(sql, null);
}
public SQLParser(Lexer lexer){
this(lexer, null);
}
public SQLParser(Lexer lexer, String dbType){
this.lexer = lexer;
this.dbType = dbType;
}
public final Lexer getLexer() {
return lexer;
}
public String getDbType() {
return dbType;
}
protected boolean identifierEquals(String text) {
return lexer.token() == Token.IDENTIFIER && lexer.stringVal().equalsIgnoreCase(text);
}
@@ -143,7 +158,7 @@ public class SQLParser {
alias += ('.' + lexer.token().name());
lexer.nextToken();
}
return alias;
}
@@ -187,7 +202,7 @@ public class SQLParser {
return alias;
}
protected void printError(Token token){
protected void printError(Token token) {
String arround;
if (lexer.mark >= 0 && (lexer.text.length() > lexer.mark + 30)) {
if (lexer.mark - 5 > 0) {
@@ -205,7 +220,7 @@ public class SQLParser {
} else {
arround = lexer.text;
}
// throw new
// ParserException("syntax error, error arround:'"+arround+"',expect "
// + token + ", actual " + lexer.token() + " "
@@ -213,7 +228,7 @@ public class SQLParser {
throw new ParserException("syntax error, error in :'" + arround + "',expect " + token + ", actual "
+ lexer.token() + " " + lexer.stringVal());
}
public void accept(Token token) {
if (lexer.token() == token) {
lexer.nextToken();
@@ -226,7 +241,7 @@ public class SQLParser {
public void match(Token token) {
if (lexer.token() != token) {
throw new ParserException("syntax error, expect " + token + ", actual " + lexer.token() + " "
+ lexer.stringVal());
+ lexer.stringVal());
}
}
@@ -202,6 +202,7 @@ public class SQLSelectParser extends SQLParser {
for (;;) {
SQLWithSubqueryClause.Entry entry = new SQLWithSubqueryClause.Entry();
entry.setParent(withQueryClause);
entry.setName((SQLIdentifierExpr) this.exprParser.name());
if (lexer.token() == Token.LPAREN) {
@@ -90,11 +90,15 @@ public class SQLStatementParser extends SQLParser {
protected int parseValuesSize = 3;
public SQLStatementParser(String sql){
this(new SQLExprParser(sql));
this(sql, null);
}
public SQLStatementParser(String sql, String dbType){
this(new SQLExprParser(sql, dbType));
}
public SQLStatementParser(SQLExprParser exprParser){
super(exprParser.getLexer());
super(exprParser.getLexer(), exprParser.getDbType());
this.exprParser = exprParser;
}
@@ -318,7 +322,7 @@ public class SQLStatementParser extends SQLParser {
lexer.nextToken();
}
SQLRollbackStatement stmt = new SQLRollbackStatement();
SQLRollbackStatement stmt = new SQLRollbackStatement(getDbType());
if (lexer.token() == Token.TO) {
lexer.nextToken();
@@ -342,14 +346,14 @@ public class SQLStatementParser extends SQLParser {
public SQLUseStatement parseUse() {
accept(Token.USE);
SQLUseStatement stmt = new SQLUseStatement();
SQLUseStatement stmt = new SQLUseStatement(getDbType());
stmt.setDatabase(this.exprParser.name());
return stmt;
}
public SQLGrantStatement parseGrant() {
accept(Token.GRANT);
SQLGrantStatement stmt = new SQLGrantStatement();
SQLGrantStatement stmt = new SQLGrantStatement(getDbType());
for (;;) {
String privilege = null;
@@ -622,7 +626,7 @@ public class SQLStatementParser extends SQLParser {
acceptIdentifier("OPTION");
stmt.setAdminOption(true);
}
if (lexer.token() == Token.IDENTIFIED) {
lexer.nextToken();
accept(Token.BY);
@@ -634,7 +638,7 @@ public class SQLStatementParser extends SQLParser {
public SQLStatement parseSavePoint() {
acceptIdentifier("SAVEPOINT");
SQLSavePointStatement stmt = new SQLSavePointStatement();
SQLSavePointStatement stmt = new SQLSavePointStatement(getDbType());
stmt.setName(this.exprParser.name());
return stmt;
}
@@ -642,7 +646,7 @@ public class SQLStatementParser extends SQLParser {
public SQLStatement parseReleaseSavePoint() {
acceptIdentifier("RELEASE");
acceptIdentifier("SAVEPOINT");
SQLReleaseSavePointStatement stmt = new SQLReleaseSavePointStatement();
SQLReleaseSavePointStatement stmt = new SQLReleaseSavePointStatement(getDbType());
stmt.setName(this.exprParser.name());
return stmt;
}
@@ -755,7 +759,7 @@ public class SQLStatementParser extends SQLParser {
accept(Token.DROP);
}
SQLDropTableStatement stmt = new SQLDropTableStatement();
SQLDropTableStatement stmt = new SQLDropTableStatement(getDbType());
if (identifierEquals("TEMPORARY")) {
lexer.nextToken();
@@ -819,7 +823,7 @@ public class SQLStatementParser extends SQLParser {
SQLName name = this.exprParser.name();
SQLDropSequenceStatement stmt = new SQLDropSequenceStatement();
SQLDropSequenceStatement stmt = new SQLDropSequenceStatement(getDbType());
stmt.setName(name);
return stmt;
}
@@ -833,7 +837,7 @@ public class SQLStatementParser extends SQLParser {
SQLName name = this.exprParser.name();
SQLDropTriggerStatement stmt = new SQLDropTriggerStatement();
SQLDropTriggerStatement stmt = new SQLDropTriggerStatement(getDbType());
stmt.setName(name);
return stmt;
}
@@ -843,7 +847,7 @@ public class SQLStatementParser extends SQLParser {
accept(Token.DROP);
}
SQLDropViewStatement stmt = new SQLDropViewStatement();
SQLDropViewStatement stmt = new SQLDropViewStatement(getDbType());
accept(Token.VIEW);
@@ -884,7 +888,7 @@ public class SQLStatementParser extends SQLParser {
accept(Token.DROP);
}
SQLDropDatabaseStatement stmt = new SQLDropDatabaseStatement();
SQLDropDatabaseStatement stmt = new SQLDropDatabaseStatement(getDbType());
accept(Token.DATABASE);
@@ -899,67 +903,67 @@ public class SQLStatementParser extends SQLParser {
return stmt;
}
protected SQLDropFunctionStatement parseDropFunction(boolean acceptDrop) {
if (acceptDrop) {
accept(Token.DROP);
}
SQLDropFunctionStatement stmt = new SQLDropFunctionStatement();
SQLDropFunctionStatement stmt = new SQLDropFunctionStatement(getDbType());
accept(Token.FUNCTION);
if (lexer.token() == Token.IF) {
lexer.nextToken();
accept(Token.EXISTS);
stmt.setIfExists(true);
}
SQLName name = this.exprParser.name();
stmt.setName(name);
return stmt;
}
protected SQLDropTableSpaceStatement parseDropTablespace(boolean acceptDrop) {
if (acceptDrop) {
accept(Token.DROP);
}
SQLDropTableSpaceStatement stmt = new SQLDropTableSpaceStatement();
SQLDropTableSpaceStatement stmt = new SQLDropTableSpaceStatement(getDbType());
accept(Token.TABLESPACE);
if (lexer.token() == Token.IF) {
lexer.nextToken();
accept(Token.EXISTS);
stmt.setIfExists(true);
}
SQLName name = this.exprParser.name();
stmt.setName(name);
return stmt;
}
protected SQLDropProcedureStatement parseDropProcedure(boolean acceptDrop) {
if (acceptDrop) {
accept(Token.DROP);
}
SQLDropProcedureStatement stmt = new SQLDropProcedureStatement();
SQLDropProcedureStatement stmt = new SQLDropProcedureStatement(getDbType());
accept(Token.PROCEDURE);
if (lexer.token() == Token.IF) {
lexer.nextToken();
accept(Token.EXISTS);
stmt.setIfExists(true);
}
SQLName name = this.exprParser.name();
stmt.setName(name);
return stmt;
}
@@ -968,7 +972,7 @@ public class SQLStatementParser extends SQLParser {
if (lexer.token() == Token.TABLE) {
lexer.nextToken();
}
SQLTruncateStatement stmt = new SQLTruncateStatement();
SQLTruncateStatement stmt = new SQLTruncateStatement(getDbType());
if (lexer.token() == Token.ONLY) {
lexer.nextToken();
@@ -1093,7 +1097,7 @@ public class SQLStatementParser extends SQLParser {
public SQLDropUserStatement parseDropUser() {
accept(Token.USER);
SQLDropUserStatement stmt = new SQLDropUserStatement();
SQLDropUserStatement stmt = new SQLDropUserStatement(getDbType());
for (;;) {
SQLExpr expr = this.exprParser.expr();
stmt.getUsers().add(expr);
@@ -1109,7 +1113,7 @@ public class SQLStatementParser extends SQLParser {
public SQLStatement parseDropIndex() {
accept(Token.INDEX);
SQLDropIndexStatement stmt = new SQLDropIndexStatement();
SQLDropIndexStatement stmt = new SQLDropIndexStatement(getDbType());
stmt.setIndexName(this.exprParser.name());
if (lexer.token() == Token.ON) {
@@ -1126,9 +1130,9 @@ public class SQLStatementParser extends SQLParser {
lexer.nextToken();
brace = true;
}
SQLCallStatement stmt = new SQLCallStatement();
SQLCallStatement stmt = new SQLCallStatement(getDbType());
if (lexer.token() == Token.QUES) {
lexer.nextToken();
accept(Token.EQ);
@@ -1137,7 +1141,6 @@ public class SQLStatementParser extends SQLParser {
acceptIdentifier("CALL");
stmt.setProcedureName(exprParser.name());
if (lexer.token() == Token.LPAREN) {
@@ -1156,7 +1159,7 @@ public class SQLStatementParser extends SQLParser {
public SQLStatement parseSet() {
accept(Token.SET);
SQLSetStatement stmt = new SQLSetStatement();
SQLSetStatement stmt = new SQLSetStatement(getDbType());
parseAssignItems(stmt.getItems(), stmt);
@@ -1234,7 +1237,7 @@ public class SQLStatementParser extends SQLParser {
public SQLStatement parseCreateTrigger() {
accept(Token.TRIGGER);
SQLCreateTriggerStatement stmt = new SQLCreateTriggerStatement();
SQLCreateTriggerStatement stmt = new SQLCreateTriggerStatement(getDbType());
stmt.setName(this.exprParser.name());
if (identifierEquals("BEFORE")) {
@@ -1296,7 +1299,7 @@ public class SQLStatementParser extends SQLParser {
accept(Token.DATABASE);
SQLCreateDatabaseStatement stmt = new SQLCreateDatabaseStatement();
SQLCreateDatabaseStatement stmt = new SQLCreateDatabaseStatement(getDbType());
stmt.setName(this.exprParser.name());
return stmt;
}
@@ -1314,7 +1317,7 @@ public class SQLStatementParser extends SQLParser {
accept(Token.CREATE);
}
SQLCreateIndexStatement stmt = new SQLCreateIndexStatement();
SQLCreateIndexStatement stmt = new SQLCreateIndexStatement(getDbType());
if (lexer.token() == Token.UNIQUE) {
lexer.nextToken();
if (identifierEquals("CLUSTERED")) {
@@ -1418,11 +1421,11 @@ public class SQLStatementParser extends SQLParser {
}
protected SQLUpdateStatement createUpdateStatement() {
return new SQLUpdateStatement();
return new SQLUpdateStatement(getDbType());
}
public SQLDeleteStatement parseDeleteStatement() {
SQLDeleteStatement deleteStatement = new SQLDeleteStatement();
SQLDeleteStatement deleteStatement = new SQLDeleteStatement(getDbType());
if (lexer.token() == Token.DELETE) {
lexer.nextToken();
@@ -1455,7 +1458,7 @@ public class SQLStatementParser extends SQLParser {
}
public SQLCreateViewStatement parseCreateView() {
SQLCreateViewStatement createView = new SQLCreateViewStatement();
SQLCreateViewStatement createView = new SQLCreateViewStatement(getDbType());
if (lexer.token() == Token.CREATE) {
lexer.nextToken();
@@ -1537,10 +1540,10 @@ public class SQLStatementParser extends SQLParser {
if (lexer.token() == Token.FOR) {
lexer.nextToken();
}
SQLExplainStatement explain = new SQLExplainStatement();
if(lexer.token == Token.HINT) {
SQLExplainStatement explain = new SQLExplainStatement(getDbType());
if (lexer.token == Token.HINT) {
explain.setHints(this.exprParser.parseHints());
}
@@ -1582,7 +1585,6 @@ public class SQLStatementParser extends SQLParser {
return item;
}
public boolean isParseCompleteValues() {
return parseCompleteValues;
}
@@ -83,6 +83,7 @@ import com.alibaba.druid.sql.ast.statement.SQLTableElement;
import com.alibaba.druid.sql.ast.statement.SQLTruncateStatement;
import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement;
import com.alibaba.druid.sql.ast.statement.SQLUseStatement;
import com.alibaba.druid.sql.ast.statement.SQLWithSubqueryClause;
import com.alibaba.druid.stat.TableStat;
import com.alibaba.druid.stat.TableStat.Column;
import com.alibaba.druid.stat.TableStat.Condition;
@@ -872,6 +873,32 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
public void endVisit(SQLSelectStatement x) {
}
@Override
public boolean visit(SQLWithSubqueryClause.Entry x) {
String alias = x.getName().toString();
Map<String, String> aliasMap = getAliasMap();
SQLWithSubqueryClause with = (SQLWithSubqueryClause) x.getParent();
if (Boolean.TRUE == with.getRecursive()) {
if (aliasMap != null && alias != null) {
aliasMap.put(alias, null);
subQueryMap.put(alias, x.getSubQuery().getQuery());
}
x.getSubQuery().accept(this);
} else {
x.getSubQuery().accept(this);
if (aliasMap != null && alias != null) {
aliasMap.put(alias, null);
subQueryMap.put(alias, x.getSubQuery().getQuery());
}
}
return false;
}
public boolean visit(SQLSubqueryTableSource x) {
x.getSelect().accept(this);
@@ -964,6 +991,7 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
x.getOrderBy().setParent(x);
}
accept(x.getWithSubQuery());
accept(x.getQuery());
String originalTable = getCurrentTable();