mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser. bug fixed for issue #2446
This commit is contained in:
@@ -56,6 +56,7 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
|
||||
protected String cachedSelectList; // optimized for SelectListCache
|
||||
protected long cachedSelectListHash; // optimized for SelectListCache
|
||||
|
||||
protected List<SQLCommentHint> hints;
|
||||
protected String dbType;
|
||||
|
||||
public SQLSelectQueryBlock(){
|
||||
@@ -322,6 +323,16 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
|
||||
return sortBy;
|
||||
}
|
||||
|
||||
public void addSortBy(SQLSelectOrderByItem item) {
|
||||
if (sortBy == null) {
|
||||
sortBy = new ArrayList<SQLSelectOrderByItem>();
|
||||
}
|
||||
if (item != null) {
|
||||
item.setParent(this);
|
||||
}
|
||||
this.sortBy.add(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
@@ -333,6 +344,8 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
|
||||
acceptChild(visitor, this.connectBy);
|
||||
acceptChild(visitor, this.groupBy);
|
||||
acceptChild(visitor, this.orderBy);
|
||||
acceptChild(visitor, this.distributeBy);
|
||||
acceptChild(visitor, this.sortBy);
|
||||
acceptChild(visitor, this.waitTime);
|
||||
acceptChild(visitor, this.limit);
|
||||
}
|
||||
@@ -676,6 +689,29 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
|
||||
return cachedSelectListHash;
|
||||
}
|
||||
|
||||
public List<SQLCommentHint> getHintsDirect() {
|
||||
return hints;
|
||||
}
|
||||
|
||||
public List<SQLCommentHint> getHints() {
|
||||
if (hints == null) {
|
||||
hints = new ArrayList<SQLCommentHint>(2);
|
||||
}
|
||||
return hints;
|
||||
}
|
||||
|
||||
public void setHints(List<SQLCommentHint> hints) {
|
||||
this.hints = hints;
|
||||
}
|
||||
|
||||
public int getHintsSize() {
|
||||
if (hints == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return hints.size();
|
||||
}
|
||||
|
||||
public String getDbType() {
|
||||
return dbType;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright 1999-2018 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.SQLHint;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLListExpr;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by wenshao on 23/02/2017.
|
||||
*/
|
||||
public class SQLValuesTableSource extends SQLTableSourceImpl {
|
||||
private List<SQLListExpr> values = new ArrayList<SQLListExpr>();
|
||||
private List<SQLName> columns = new ArrayList<SQLName>();
|
||||
|
||||
public List<SQLListExpr> getValues() {
|
||||
return values;
|
||||
}
|
||||
|
||||
public List<SQLName> getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, values);
|
||||
acceptChild(visitor, columns);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLValuesTableSource clone() {
|
||||
|
||||
SQLValuesTableSource x = new SQLValuesTableSource();
|
||||
|
||||
x.setAlias(this.alias);
|
||||
|
||||
for (SQLListExpr e : this.values) {
|
||||
SQLListExpr e2 = e.clone();
|
||||
e2.setParent(x);
|
||||
x.getValues().add(e2);
|
||||
}
|
||||
|
||||
for (SQLName e : this.columns) {
|
||||
SQLName e2 = e.clone();
|
||||
e2.setParent(x);
|
||||
x.getColumns().add(e2);
|
||||
}
|
||||
|
||||
if (this.flashback != null) {
|
||||
x.setFlashback(this.flashback.clone());
|
||||
}
|
||||
|
||||
if (this.hints != null) {
|
||||
for (SQLHint e : this.hints) {
|
||||
SQLHint e2 = e.clone();
|
||||
e2.setParent(x);
|
||||
x.getHints().add(e2);
|
||||
}
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user