mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser for postgresql
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright 1999-2011 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.expr;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExprImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLBinaryExpr extends SQLExprImpl implements SQLLiteralExpr {
|
||||
|
||||
private String value;
|
||||
|
||||
public SQLBinaryExpr(){
|
||||
|
||||
}
|
||||
|
||||
public SQLBinaryExpr(String value){
|
||||
super();
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void accept0(SQLASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public void output(StringBuffer buf) {
|
||||
buf.append("b'");
|
||||
buf.append(value);
|
||||
buf.append('\'');
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((value == null) ? 0 : value.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
SQLBinaryExpr other = (SQLBinaryExpr) obj;
|
||||
if (value == null) {
|
||||
if (other.value != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!value.equals(other.value)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
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;
|
||||
|
||||
@@ -23,10 +24,19 @@ public class SQLAlterTableAlterColumn extends SQLObjectImpl implements SQLAlterT
|
||||
|
||||
private SQLColumnDefinition column;
|
||||
|
||||
private boolean setNotNull;
|
||||
|
||||
private boolean dropNotNull;
|
||||
|
||||
private SQLExpr setDefault;
|
||||
|
||||
private boolean dropDefault;
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, column);
|
||||
acceptChild(visitor, setDefault);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
@@ -39,4 +49,36 @@ public class SQLAlterTableAlterColumn extends SQLObjectImpl implements SQLAlterT
|
||||
this.column = column;
|
||||
}
|
||||
|
||||
public boolean isSetNotNull() {
|
||||
return setNotNull;
|
||||
}
|
||||
|
||||
public void setSetNotNull(boolean setNotNull) {
|
||||
this.setNotNull = setNotNull;
|
||||
}
|
||||
|
||||
public boolean isDropNotNull() {
|
||||
return dropNotNull;
|
||||
}
|
||||
|
||||
public void setDropNotNull(boolean dropNotNull) {
|
||||
this.dropNotNull = dropNotNull;
|
||||
}
|
||||
|
||||
public SQLExpr getSetDefault() {
|
||||
return setDefault;
|
||||
}
|
||||
|
||||
public void setSetDefault(SQLExpr setDefault) {
|
||||
this.setDefault = setDefault;
|
||||
}
|
||||
|
||||
public boolean isDropDefault() {
|
||||
return dropDefault;
|
||||
}
|
||||
|
||||
public void setDropDefault(boolean dropDefault) {
|
||||
this.dropDefault = dropDefault;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ public class SQLAlterTableDropColumnItem extends SQLObjectImpl implements SQLAlt
|
||||
|
||||
private List<SQLName> columns = new ArrayList<SQLName>();
|
||||
|
||||
private boolean cascade = false;
|
||||
|
||||
public SQLAlterTableDropColumnItem(){
|
||||
|
||||
}
|
||||
@@ -42,4 +44,12 @@ public class SQLAlterTableDropColumnItem extends SQLObjectImpl implements SQLAlt
|
||||
return columns;
|
||||
}
|
||||
|
||||
public boolean isCascade() {
|
||||
return cascade;
|
||||
}
|
||||
|
||||
public void setCascade(boolean cascade) {
|
||||
this.cascade = cascade;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
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 SQLAlterTableRename extends SQLObjectImpl implements SQLAlterTableItem {
|
||||
|
||||
protected SQLExpr to;
|
||||
|
||||
public SQLExpr getTo() {
|
||||
return to;
|
||||
}
|
||||
|
||||
public void setTo(SQLExpr to) {
|
||||
this.to = to;
|
||||
to.setParent(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, to);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user