001package gudusoft.gsqlparser.stmt;
002
003import gudusoft.gsqlparser.EDbVendor;
004import gudusoft.gsqlparser.ESqlStatementType;
005import gudusoft.gsqlparser.TSourceToken;
006import gudusoft.gsqlparser.TVisitorAbs;
007import gudusoft.gsqlparser.TCustomSqlStatement;
008import gudusoft.gsqlparser.nodes.TDropViewSqlNode;
009import gudusoft.gsqlparser.nodes.TObjectName;
010import gudusoft.gsqlparser.nodes.TParseTreeVisitor;
011import gudusoft.gsqlparser.nodes.TObjectNameList;
012
013/**
014 * remove a view or an object view from the database.
015 */
016public class TDropViewSqlStatement extends TCustomSqlStatement {
017    public TDropViewSqlStatement(EDbVendor dbvendor) {
018        super(dbvendor);
019        sqlstatementtype = ESqlStatementType.sstdropview;
020    }
021
022    private boolean ifExists;
023    private TSourceToken dropBehavior;
024
025    public void setIfExists(boolean ifExists) {
026        this.ifExists = ifExists;
027    }
028
029    public boolean isIfExists() {
030        return ifExists;
031    }
032
033    public TSourceToken getDropBehavior() {
034        return dropBehavior;
035    }
036
037    void buildsql() {
038    }
039
040    void clear() {
041    }
042
043    String getasprettytext() {
044        return "";
045    }
046
047    void iterate(TVisitorAbs pvisitor) {
048    }
049
050    public int doParseStatement(TCustomSqlStatement psql) {
051        if (rootNode == null) return -1;
052        TDropViewSqlNode dropViewNode = (TDropViewSqlNode)rootNode;
053        super.doParseStatement(psql);
054
055        this.viewName = dropViewNode.getViewName();
056        this.viewNameList = dropViewNode.getViewNameList();
057        this.ifExists = dropViewNode.isIfExists();
058        this.dropBehavior = dropViewNode.getDropBehavior();
059        if (this.viewNameList != null){
060           this.viewName = this.viewNameList.getObjectName(0);
061        }
062        return 0;
063    }
064
065    /**
066     *
067     * @return the name of the view to be dropped.
068     */
069    public TObjectName getViewName() {
070        return viewName;
071    }
072
073    private TObjectName viewName = null;
074
075
076
077    private TObjectNameList viewNameList = null;
078
079    /**
080     *
081     * @return list of views to be drop, used in sql server.
082     */
083    public TObjectNameList getViewNameList() {
084        return viewNameList;
085    }
086
087    public void accept(TParseTreeVisitor v){
088        v.preVisit(this);
089        v.postVisit(this);
090    }
091
092    public void acceptChildren(TParseTreeVisitor v){
093        v.preVisit(this);
094        v.postVisit(this);
095    }
096
097    public void setViewName(TObjectName viewName) {
098        this.viewName = viewName;
099    }
100
101    public void setViewNameList(TObjectNameList viewNameList) {
102        this.viewNameList = viewNameList;
103    }
104}