001package gudusoft.gsqlparser.stmt;
002
003import gudusoft.gsqlparser.*;
004import gudusoft.gsqlparser.nodes.*;
005
006/**
007 * move a table or object table to the recycle bin or to remove the table and all its data from the database entirely.
008 */
009
010public class TDropTableSqlStatement extends TCustomSqlStatement {
011    public TDropTableSqlStatement(EDbVendor dbvendor) {
012        super(dbvendor);
013        sqlstatementtype = ESqlStatementType.sstdroptable;
014    }
015
016    void buildsql() {
017    }
018
019    void clear() {
020    }
021
022    String getasprettytext() {
023        return "";
024    }
025
026    void iterate(TVisitorAbs pvisitor) {
027    }
028
029    private boolean cascade;
030    private boolean restrict;
031
032    public void setCascade(boolean cascade) {
033        this.cascade = cascade;
034    }
035
036    public void setRestrict(boolean restrict) {
037        this.restrict = restrict;
038    }
039
040    public void setIfExists(boolean ifExists) {
041        this.ifExists = ifExists;
042    }
043
044    public boolean isIfExists() {
045
046        return ifExists;
047    }
048
049    public boolean isRestrict() {
050        return restrict;
051    }
052
053    public boolean isCascade() {
054        return cascade;
055    }
056
057    private boolean ifExists;
058    private ETableKind tableKind;
059
060    public ETableKind getTableKind() {
061        return tableKind;
062    }
063
064    public int doParseStatement(TCustomSqlStatement psql) {
065        if (rootNode == null) return -1;
066        TDropTableSqlNode dropTableNode = (TDropTableSqlNode)rootNode;
067        super.doParseStatement(psql);
068        this.tableNameList = dropTableNode.getTableNameList();
069        tableKind = dropTableNode.getTableKind();
070        ifExists = dropTableNode.isIfExists();
071        restrict = dropTableNode.isRestrict();
072        cascade = dropTableNode.isCascade();
073        TTable lcTable;
074        if (this.tableNameList != null){
075           this.tableName = this.tableNameList.getObjectName(0);
076            for(int i=0;i<tableNameList.size();i++){
077                lcTable = analyzeTablename(tableNameList.getObjectName(i));
078                lcTable.setEffectType(ETableEffectType.tetDrop);
079                if (i == 0){
080                    setTargetTable(lcTable);
081                }
082            }
083        }else{
084            this.tableName = dropTableNode.getTableName();
085            lcTable = analyzeTablename(tableName);
086            lcTable.setEffectType(ETableEffectType.tetDrop);
087            setTargetTable(lcTable);
088        //this.tableName.setObjectType(TObjectName.ttobjTable);
089        }
090        return 0;
091    }
092
093    private TObjectName tableName;
094
095    /**
096     *
097     * @return the name of the table to be dropped. check {@link #getTableNameList} if there are list of tables to be drop.
098     */
099    public TObjectName getTableName() {
100            return tableName;
101    }
102
103    private TObjectNameList tableNameList = null;
104
105    /**
106     *
107     * @return list of tables to be drop, used in sql server.
108     */
109    public TObjectNameList getTableNameList() {
110        return tableNameList;
111    }
112
113    public void accept(TParseTreeVisitor v){
114        v.preVisit(this);
115        v.postVisit(this);
116    }
117
118    public void acceptChildren(TParseTreeVisitor v){
119        v.preVisit(this);
120        v.postVisit(this);
121    }
122
123    public void setTableName(TObjectName tableName) {
124        this.tableName = tableName;
125    }
126
127    public void setTableNameList(TObjectNameList tableNameList) {
128        this.tableNameList = tableNameList;
129    }
130}