001package gudusoft.gsqlparser.stmt;
002
003import gudusoft.gsqlparser.*;
004import gudusoft.gsqlparser.nodes.*;
005
006/**
007 * SQL alter table statement.
008 * <br>
009 * <p>table altered: {@link #getTableName()}</p>
010 * <p>alter options: {@link #getAlterTableOptionList()}</p>
011 *
012 */
013
014public class TAlterTableStatement extends TAlterRelation {
015    public TAlterTableStatement(EDbVendor dbvendor) {
016        super(dbvendor);
017        sqlstatementtype = ESqlStatementType.sstaltertable;
018    }
019
020    private TObjectName tableName;
021    public void setTableName(TObjectName tableName) {
022        this.tableName = tableName;
023    }
024
025    /**
026     * The name of the table to be altered.
027     * @return the name of the table to be altered.
028     */
029    public TObjectName getTableName() {
030        return tableName;
031    }
032    /**
033     * MySQL, table option
034     * @return mysql table options
035     */
036    public TPTNodeList<TMySQLCreateTableOption> getMySQLTableOptionList() {
037        return mySQLTableOptionList;
038    }
039
040    private TPTNodeList <TMySQLCreateTableOption> mySQLTableOptionList;
041
042    public void setMySQLTableOptionList(TPTNodeList<TMySQLCreateTableOption> mySQLTableOptionList) {
043        this.mySQLTableOptionList = mySQLTableOptionList;
044    }
045    public int doParseStatement(TCustomSqlStatement psql) {
046        if (rootNode == null) return -1;
047        TAlterTableSqlNode alterTableNode = (TAlterTableSqlNode)rootNode;
048        super.doParseStatement(psql);
049        this.tableName = alterTableNode.getTableName();
050        this.setTargetTable(analyzeTablename(tableName));
051        getTargetTable().setEffectType(ETableEffectType.tetAlter);
052        mySQLTableOptionList = alterTableNode.getMySQLTableOptionList();
053        this.alterTableOptionList = alterTableNode.getAlterTableOptionList();
054        if (this.alterTableOptionList != null){
055            this.alterTableOptionList.doParse(this, ESqlClause.unknown);
056        }
057
058//        this.tableElementList = alterTableNode.getTableElementList();
059//        if (this.tableElementList != null){
060//            this.tableElementList.doParse(this,ESqlClause.unknown);
061//        }
062        return 0;
063    }
064
065
066    public void accept(TParseTreeVisitor v){
067        v.preVisit(this);
068
069        v.postVisit(this);
070    }
071
072    public void acceptChildren(TParseTreeVisitor v){
073        v.preVisit(this);
074        if (this.alterTableOptionList != null){
075            for(int i=0;i<alterTableOptionList.size();i++){
076                alterTableOptionList.getAlterTableOption(i).acceptChildren(v);
077            }
078        }
079
080        if (mySQLTableOptionList != null){
081            mySQLTableOptionList.acceptChildren(v);
082        }
083
084        v.postVisit(this);
085    }
086}