mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser, bug fixed for parent is null
This commit is contained in:
@@ -54,6 +54,13 @@ public class SQLDataTypeImpl extends SQLObjectImpl implements SQLDataType {
|
||||
public List<SQLExpr> getArguments() {
|
||||
return this.arguments;
|
||||
}
|
||||
|
||||
public void addArgument(SQLExpr argument) {
|
||||
if (argument != null) {
|
||||
argument.setParent(this);
|
||||
}
|
||||
this.arguments.add(argument);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
@@ -76,6 +76,13 @@ public class SQLPartition extends SQLObjectImpl {
|
||||
public List<SQLSubPartition> getSubPartitions() {
|
||||
return subPartitions;
|
||||
}
|
||||
|
||||
public void addSubPartition(SQLSubPartition partition) {
|
||||
if (partition != null) {
|
||||
partition.setParent(this);
|
||||
}
|
||||
this.subPartitions.add(partition);
|
||||
}
|
||||
|
||||
public SQLExpr getIndexDirectory() {
|
||||
return indexDirectory;
|
||||
|
||||
@@ -33,6 +33,13 @@ public abstract class SQLPartitionBy extends SQLObjectImpl {
|
||||
public List<SQLPartition> getPartitions() {
|
||||
return partitions;
|
||||
}
|
||||
|
||||
public void addPartition(SQLPartition partition) {
|
||||
if (partition != null) {
|
||||
partition.setParent(this);
|
||||
}
|
||||
this.partitions.add(partition);
|
||||
}
|
||||
|
||||
public SQLSubPartitionBy getSubPartitionBy() {
|
||||
return subPartitionBy;
|
||||
|
||||
@@ -53,4 +53,10 @@ public class SQLPartitionByList extends SQLPartitionBy {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public void addColumn(SQLName column) {
|
||||
if (column != null) {
|
||||
column.setParent(this);
|
||||
}
|
||||
this.columns.add(column);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,9 +32,12 @@ public class SQLPartitionByRange extends SQLPartitionBy {
|
||||
public List<SQLName> getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public void setColumns(List<SQLName> columns) {
|
||||
this.columns = columns;
|
||||
|
||||
public void addColumn(SQLName column) {
|
||||
if (column != null) {
|
||||
column.setParent(this);
|
||||
}
|
||||
this.columns.add(column);
|
||||
}
|
||||
|
||||
public SQLExpr getInterval() {
|
||||
|
||||
@@ -33,6 +33,13 @@ public class SQLPartitionValue extends SQLObjectImpl {
|
||||
public List<SQLExpr> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void addItem(SQLExpr item) {
|
||||
if (item != null) {
|
||||
item.setParent(this);
|
||||
}
|
||||
this.items.add(item);
|
||||
}
|
||||
|
||||
public Operator getOperator() {
|
||||
return operator;
|
||||
|
||||
@@ -75,6 +75,13 @@ public class SQLAggregateExpr extends SQLExprImpl implements Serializable {
|
||||
public List<SQLExpr> getArguments() {
|
||||
return this.arguments;
|
||||
}
|
||||
|
||||
public void addArgument(SQLExpr argument) {
|
||||
if (argument != null) {
|
||||
argument.setParent(this);
|
||||
}
|
||||
this.arguments.add(argument);
|
||||
}
|
||||
|
||||
public SQLOver getOver() {
|
||||
return over;
|
||||
|
||||
@@ -29,6 +29,13 @@ public class SQLGroupingSetExpr extends SQLExprImpl {
|
||||
public List<SQLExpr> getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public void addParameter(SQLExpr parameter) {
|
||||
if (parameter != null) {
|
||||
parameter.setParent(this);
|
||||
}
|
||||
this.parameters.add(parameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
|
||||
@@ -29,6 +29,13 @@ public class SQLListExpr extends SQLExprImpl {
|
||||
public List<SQLExpr> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void addItem(SQLExpr item) {
|
||||
if (item != null) {
|
||||
item.setParent(this);
|
||||
}
|
||||
this.items.add(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
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.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLAlterDatabaseStatement extends SQLStatementImpl {
|
||||
|
||||
private SQLName name;
|
||||
|
||||
private boolean upgradeDataDirectoryName;
|
||||
|
||||
public SQLAlterDatabaseStatement() {
|
||||
|
||||
}
|
||||
|
||||
public SQLAlterDatabaseStatement(String dbType) {
|
||||
this.setDbType(dbType);
|
||||
}
|
||||
|
||||
public SQLName getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(SQLName name) {
|
||||
if (name != null) {
|
||||
name.setParent(this);
|
||||
}
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean isUpgradeDataDirectoryName() {
|
||||
return upgradeDataDirectoryName;
|
||||
}
|
||||
|
||||
public void setUpgradeDataDirectoryName(boolean upgradeDataDirectoryName) {
|
||||
this.upgradeDataDirectoryName = upgradeDataDirectoryName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, name);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,13 @@ public class SQLAlterTableAddColumn extends SQLObjectImpl implements SQLAlterTab
|
||||
public List<SQLColumnDefinition> getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public void addColumn(SQLColumnDefinition column) {
|
||||
if (column != null) {
|
||||
column.setParent(this);
|
||||
}
|
||||
this.columns.add(column);
|
||||
}
|
||||
|
||||
public SQLName getFirstColumn() {
|
||||
return firstColumn;
|
||||
|
||||
@@ -57,6 +57,13 @@ public class SQLAlterTableAddIndex extends SQLObjectImpl implements SQLAlterTabl
|
||||
public List<SQLSelectOrderByItem> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void addItem(SQLSelectOrderByItem item) {
|
||||
if (item != null) {
|
||||
item.setParent(this);
|
||||
}
|
||||
this.items.add(item);
|
||||
}
|
||||
|
||||
public SQLName getName() {
|
||||
return name;
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 1999-2101 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.SQLObjectImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLAlterTableConvertCharSet extends SQLObjectImpl implements SQLAlterTableItem {
|
||||
|
||||
private SQLExpr charset;
|
||||
private SQLExpr collate;
|
||||
|
||||
public SQLAlterTableConvertCharSet() {
|
||||
|
||||
}
|
||||
|
||||
public SQLExpr getCharset() {
|
||||
return charset;
|
||||
}
|
||||
|
||||
public void setCharset(SQLExpr charset) {
|
||||
if (charset != null) {
|
||||
charset.setParent(this);
|
||||
}
|
||||
this.charset = charset;
|
||||
}
|
||||
|
||||
public SQLExpr getCollate() {
|
||||
return collate;
|
||||
}
|
||||
|
||||
public void setCollate(SQLExpr collate) {
|
||||
if (collate != null) {
|
||||
collate.setParent(this);
|
||||
}
|
||||
this.collate = collate;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, charset);
|
||||
acceptChild(visitor, collate);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -43,6 +43,13 @@ public class SQLAlterTableDropColumnItem extends SQLObjectImpl implements SQLAlt
|
||||
public List<SQLName> getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public void addColumn(SQLName column) {
|
||||
if (column != null) {
|
||||
column.setParent(this);
|
||||
}
|
||||
this.columns.add(column);
|
||||
}
|
||||
|
||||
public boolean isCascade() {
|
||||
return cascade;
|
||||
|
||||
@@ -25,22 +25,55 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
public class SQLAlterTableStatement extends SQLStatementImpl implements SQLDDLStatement {
|
||||
|
||||
private SQLExprTableSource tableSource;
|
||||
private List<SQLAlterTableItem> items = new ArrayList<SQLAlterTableItem>();
|
||||
|
||||
public SQLAlterTableStatement() {
|
||||
|
||||
private List<SQLAlterTableItem> items = new ArrayList<SQLAlterTableItem>();
|
||||
|
||||
// for mysql
|
||||
private boolean ignore = false;
|
||||
|
||||
private boolean updateGlobalIndexes = false;
|
||||
private boolean invalidateGlobalIndexes = false;
|
||||
|
||||
public SQLAlterTableStatement(){
|
||||
|
||||
}
|
||||
|
||||
public SQLAlterTableStatement(String dbType) {
|
||||
super (dbType);
|
||||
|
||||
public SQLAlterTableStatement(String dbType){
|
||||
super(dbType);
|
||||
}
|
||||
|
||||
public boolean isIgnore() {
|
||||
return ignore;
|
||||
}
|
||||
|
||||
public void setIgnore(boolean ignore) {
|
||||
this.ignore = ignore;
|
||||
}
|
||||
|
||||
public boolean isUpdateGlobalIndexes() {
|
||||
return updateGlobalIndexes;
|
||||
}
|
||||
|
||||
public void setUpdateGlobalIndexes(boolean updateGlobalIndexes) {
|
||||
this.updateGlobalIndexes = updateGlobalIndexes;
|
||||
}
|
||||
|
||||
public boolean isInvalidateGlobalIndexes() {
|
||||
return invalidateGlobalIndexes;
|
||||
}
|
||||
|
||||
public void setInvalidateGlobalIndexes(boolean invalidateGlobalIndexes) {
|
||||
this.invalidateGlobalIndexes = invalidateGlobalIndexes;
|
||||
}
|
||||
|
||||
public List<SQLAlterTableItem> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<SQLAlterTableItem> items) {
|
||||
this.items = items;
|
||||
public void addItem(SQLAlterTableItem item) {
|
||||
if (item != null) {
|
||||
item.setParent(this);
|
||||
}
|
||||
this.items.add(item);
|
||||
}
|
||||
|
||||
public SQLExprTableSource getTableSource() {
|
||||
|
||||
@@ -99,6 +99,13 @@ public class SQLColumnDefinition extends SQLObjectImpl implements SQLTableElemen
|
||||
public List<SQLColumnConstraint> getConstraints() {
|
||||
return constraints;
|
||||
}
|
||||
|
||||
public void addConstraint(SQLColumnConstraint constraint) {
|
||||
if (constraint != null) {
|
||||
constraint.setParent(this);
|
||||
}
|
||||
this.constraints.add(constraint);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void output(StringBuffer buf) {
|
||||
|
||||
@@ -59,8 +59,11 @@ public class SQLCreateIndexStatement extends SQLStatementImpl implements SQLDDLS
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<SQLSelectOrderByItem> items) {
|
||||
this.items = items;
|
||||
public void addItem(SQLSelectOrderByItem item) {
|
||||
if (item != null) {
|
||||
item.setParent(this);
|
||||
}
|
||||
this.items.add(item);
|
||||
}
|
||||
|
||||
public SQLName getName() {
|
||||
|
||||
@@ -82,6 +82,13 @@ public class SQLCreateViewStatement extends SQLStatementImpl implements SQLDDLSt
|
||||
public List<Column> getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public void addColumn(Column column) {
|
||||
if (column != null) {
|
||||
column.setParent(this);
|
||||
}
|
||||
this.columns.add(column);
|
||||
}
|
||||
|
||||
public boolean isIfNotExists() {
|
||||
return ifNotExists;
|
||||
|
||||
@@ -61,9 +61,12 @@ public class SQLDropTableStatement extends SQLStatementImpl implements SQLDDLSta
|
||||
public List<SQLExprTableSource> getTableSources() {
|
||||
return tableSources;
|
||||
}
|
||||
|
||||
public void setTableSources(List<SQLExprTableSource> tableSources) {
|
||||
this.tableSources = tableSources;
|
||||
|
||||
public void addPartition(SQLExprTableSource tableSource) {
|
||||
if (tableSource != null) {
|
||||
tableSource.setParent(this);
|
||||
}
|
||||
this.tableSources.add(tableSource);
|
||||
}
|
||||
|
||||
public void setName(SQLName name) {
|
||||
|
||||
@@ -38,8 +38,11 @@ public class SQLDropUserStatement extends SQLStatementImpl implements SQLDDLStat
|
||||
return users;
|
||||
}
|
||||
|
||||
public void setUsers(List<SQLExpr> users) {
|
||||
this.users = users;
|
||||
public void addUser(SQLExpr user) {
|
||||
if (user != null) {
|
||||
user.setParent(this);
|
||||
}
|
||||
this.users.add(user);
|
||||
}
|
||||
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
|
||||
@@ -49,9 +49,12 @@ public class SQLDropViewStatement extends SQLStatementImpl implements SQLDDLStat
|
||||
public List<SQLExprTableSource> getTableSources() {
|
||||
return tableSources;
|
||||
}
|
||||
|
||||
public void setTableSources(List<SQLExprTableSource> tableSources) {
|
||||
this.tableSources = tableSources;
|
||||
|
||||
public void addPartition(SQLExprTableSource tableSource) {
|
||||
if (tableSource != null) {
|
||||
tableSource.setParent(this);
|
||||
}
|
||||
this.tableSources.add(tableSource);
|
||||
}
|
||||
|
||||
public void setName(SQLName name) {
|
||||
|
||||
@@ -77,6 +77,13 @@ public abstract class SQLInsertInto extends SQLObjectImpl {
|
||||
public List<SQLExpr> getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public void addColumn(SQLExpr column) {
|
||||
if (column != null) {
|
||||
column.setParent(this);
|
||||
}
|
||||
this.columns.add(column);
|
||||
}
|
||||
|
||||
public ValuesClause getValues() {
|
||||
return values;
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLObjectImpl;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
@@ -32,6 +32,13 @@ public class SQLUnique extends SQLConstraintImpl implements SQLUniqueConstraint,
|
||||
public List<SQLExpr> getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public void addColumn(SQLExpr column) {
|
||||
if (column != null) {
|
||||
column.setParent(this);
|
||||
}
|
||||
this.columns.add(column);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
|
||||
@@ -31,6 +31,13 @@ public class SQLWithSubqueryClause extends SQLObjectImpl {
|
||||
public List<Entry> getEntries() {
|
||||
return entries;
|
||||
}
|
||||
|
||||
public void addEntry(Entry entrie) {
|
||||
if (entrie != null) {
|
||||
entrie.setParent(this);
|
||||
}
|
||||
this.entries.add(entrie);
|
||||
}
|
||||
|
||||
public Boolean getRecursive() {
|
||||
return recursive;
|
||||
|
||||
Reference in New Issue
Block a user