001package gudusoft.gsqlparser.stmt;
002
003import gudusoft.gsqlparser.*;
004import gudusoft.gsqlparser.nodes.TConstant;
005import gudusoft.gsqlparser.nodes.TExpressionList;
006import gudusoft.gsqlparser.nodes.TObjectName;
007import gudusoft.gsqlparser.nodes.TParseTreeVisitor;
008
009
010/**
011 * The RAISE statement stops normal execution of a PL/SQL block or subprogram and transfers control to an exception handler.
012 * Used in the following database:
013 * <br> AWS Athena
014 * <br> Greenplum
015 * <br> Netezza
016 * <br> Postgresql
017 * <br> Presto
018 * <br> Redshift
019 * <br> Snowflake
020 * <br> Vertica
021 */
022public class TRaiseStmt extends TCustomSqlStatement {
023    public TRaiseStmt(){
024        this(EDbVendor.dbvoracle);
025    }
026
027     public TRaiseStmt(EDbVendor dbvendor){
028        super(dbvendor);
029        sqlstatementtype = ESqlStatementType.sst_raisestmt;
030        }
031
032    void buildsql() {
033    }
034
035    void clear() {
036    }
037
038    String getasprettytext() {
039        return "";
040    }
041
042    void iterate(TVisitorAbs pvisitor) {
043    }
044
045    private TObjectName exceptionName = null;
046
047    /**
048     *
049     * @return A predefined or user-defined exception.
050     */
051    public TObjectName getExceptionName() {
052        return exceptionName;
053    }
054
055    private TExpressionList exprList;
056
057    public void setExprList(TExpressionList exprList) {
058        this.exprList = exprList;
059    }
060
061    public TExpressionList getExprList() {
062
063        return exprList;
064    }
065
066    private TObjectName conditionName;
067
068    public void setConditionName(TObjectName conditionName) {
069        this.conditionName = conditionName;
070    }
071
072    public TObjectName getConditionName() {
073
074        return conditionName;
075    }
076
077    public void setFormatString(TConstant formatString) {
078        this.formatString = formatString;
079    }
080
081    public TConstant getFormatString() {
082
083        return formatString;
084    }
085
086    private TConstant formatString;
087
088    private TExpressionList options;
089
090
091    public TExpressionList getOptions() {
092
093        return options;
094    }
095
096    private TConstant sqlState;
097
098    public void setSqlState(TConstant sqlState) {
099        this.sqlState = sqlState;
100    }
101
102    public TConstant getSqlState() {
103
104        return sqlState;
105    }
106
107    private ERaiseLevel raiseLevel;
108
109    public ERaiseLevel getRaiseLevel() {
110        return raiseLevel;
111    }
112
113    public void init(Object arg1,Object arg2){
114        init(arg1);
115        options = (TExpressionList)arg2;
116    }
117
118    public void init(Object arg1)
119    {
120        if (arg1 instanceof TObjectName){
121            exceptionName  = (TObjectName)arg1;
122        }else if (arg1 instanceof TSourceToken){
123            TSourceToken st  = (TSourceToken)arg1;
124            if (dbvendor == EDbVendor.dbvpostgresql){
125                switch (st.tokencode) {
126                    case TBaseType.rrw_debug:
127                        raiseLevel = ERaiseLevel.debug;
128                        break;
129                    case TBaseType.rrw_log:
130                        raiseLevel = ERaiseLevel.log;
131                        break;
132                    case TBaseType.rrw_postgresql_info:
133                        raiseLevel = ERaiseLevel.info;
134                        break;
135                    case TBaseType.rrw_notice:
136                        raiseLevel = ERaiseLevel.notice;
137                        break;
138                    case TBaseType.rrw_warning:
139                        raiseLevel = ERaiseLevel.warning;
140                        break;
141                    case TBaseType.rrw_exception:
142                        raiseLevel = ERaiseLevel.exception;
143                        break;
144                    default:
145                        break;
146                }
147            }else{
148                if (st.toString().equalsIgnoreCase("debug")){
149                    raiseLevel = ERaiseLevel.notice;
150                }else if (st.toString().equalsIgnoreCase("log")){
151                    raiseLevel = ERaiseLevel.log;
152                }else if (st.toString().equalsIgnoreCase("info")){
153                    raiseLevel = ERaiseLevel.info;
154                }else if (st.toString().equalsIgnoreCase("notice")){
155                    raiseLevel = ERaiseLevel.notice;
156                }else if (st.toString().equalsIgnoreCase("warning")){
157                    raiseLevel = ERaiseLevel.warning;
158                }else if (st.toString().equalsIgnoreCase("exception")){
159                    raiseLevel = ERaiseLevel.exception;
160                }
161            }
162        }
163    }
164
165    public int doParseStatement(TCustomSqlStatement psql) {
166        super.doParseStatement(psql);
167        return 0;
168    }
169
170    public void accept(TParseTreeVisitor v){
171        v.preVisit(this);
172        v.postVisit(this);
173    }
174    public void acceptChildren(TParseTreeVisitor v){
175        v.preVisit(this);
176        v.postVisit(this);
177    }
178
179    public void setExceptionName(TObjectName exceptionName) {
180        this.exceptionName = exceptionName;
181    }
182
183    public void setOptions(TExpressionList options) {
184        this.options = options;
185    }
186
187    public void setRaiseLevel(ERaiseLevel raiseLevel) {
188        this.raiseLevel = raiseLevel;
189    }
190}