001package gudusoft.gsqlparser.stmt;
002
003import gudusoft.gsqlparser.*;
004import gudusoft.gsqlparser.nodes.*;
005
006
007public class TSetStmt extends TCustomSqlStatement {
008    private TObjectName variableName;
009    private TObjectNameList variableNameList;
010    private TExpression variableValue;
011    private TExpressionList variableValueList;
012    private ESetStatementType setStatementType;
013
014    private TObjectName characterSetName;
015    private TObjectName collationName;
016    private TObjectName userName;
017    private TObjectName password;
018    private ETransactionIsolationLevel isolationLevel;
019
020    public TObjectName getCharacterSetName() {
021        return characterSetName;
022    }
023
024    public TObjectName getCollationName() {
025        return collationName;
026    }
027
028    public TObjectName getUserName() {
029        return userName;
030    }
031
032    public TObjectName getPassword() {
033        return password;
034    }
035
036    public ETransactionIsolationLevel getIsolationLevel() {
037        return isolationLevel;
038    }
039
040    public ESetStatementType getSetStatementType() {
041        return setStatementType;
042    }
043
044    public TObjectName getVariableName() {
045        return variableName;
046    }
047
048    public TObjectNameList getVariableNameList() {
049        return variableNameList;
050    }
051
052    public TExpression getVariableValue() {
053        return variableValue;
054    }
055
056    public TExpressionList getVariableValueList() {
057        return variableValueList;
058    }
059
060    public TSetStmt(EDbVendor dbvendor) {
061        super(dbvendor);
062        sqlstatementtype = ESqlStatementType.sstset;
063    }
064
065    private TPTNodeList<TSetAssignment> assignments;
066
067    public TPTNodeList<TSetAssignment> getAssignments() {
068        return assignments;
069    }
070
071    public int doParseStatement(TCustomSqlStatement psql) {
072        if (rootNode == null) return -1;
073        super.doParseStatement(psql);
074        TSetSqlNode node = (TSetSqlNode)rootNode;
075        setStatementType = node.getSetStatementType();
076
077        switch (dbvendor){
078            case dbvmysql:
079                assignments = node.getAssignments();
080                if (setStatementType == ESetStatementType.variable){
081                    for (int i=0;i<assignments.size();i++){
082                        assignments.getElement(i).getParameterValue().doParse(this,ESqlClause.setVariable);
083                    }
084                }
085
086
087                characterSetName = node.getCharacterSetName();
088                collationName = node.getCollationName();
089                userName = node.getUserName();
090                password = node.getPassword();
091                isolationLevel = node.getIsolationLevel();
092
093                break;
094            case dbvgreenplum:
095            case dbvpostgresql:
096            case dbvgaussdb:
097                switch (setStatementType){
098                    case variable:
099                        variableName = node.getVariableName();
100                        variableNameList = node.getVariableNameList();
101                        variableValue = node.getVariableValue();
102                        variableValueList = node.getVariableValueList();
103                        if (variableName.toString().equalsIgnoreCase("search_path")){
104                            if (getSqlEnv() != null)  {
105                                getSqlEnv().setDefaultSchemaName(variableValueList.getExpression(0).toString());
106                            }
107                        }
108                        break;
109                    case reset:
110                        variableName = node.getVariableName();
111                        variableName.setDbObjectType(EDbObjectType.variable);
112                        break;
113                    default:
114                        break;
115                }
116
117                break;
118            case dbvbigquery:
119                variableName = node.getVariableName();
120                variableValue = node.getVariableValue();
121                variableValue.doParse(this,ESqlClause.unknown);
122
123                variableNameList = node.getVariableNameList();
124                variableValueList = node.getVariableValueList();
125                if (variableValueList != null){
126                    variableValueList.doParse(this,ESqlClause.unknown);
127                }
128
129                break;
130            case dbvsnowflake:
131                variableName = node.getVariableName();
132                if (variableName != null){
133                    variableValue = node.getVariableValue();
134                    variableValue.doParse(this,ESqlClause.unknown);
135                }
136
137                variableNameList = node.getVariableNameList();
138                if (variableNameList != null){
139                    variableValueList = node.getVariableValueList();
140                    if (variableValueList != null){
141                        variableValueList.doParse(this,ESqlClause.unknown);
142                    }
143                }
144
145                break;
146            default:
147                variableName = node.getVariableName();
148                variableNameList = node.getVariableNameList();
149                variableValue = node.getVariableValue();
150                variableValueList = node.getVariableValueList();
151                if (variableValue != null) {
152                    variableValue.doParse(this, ESqlClause.unknown);
153                }
154                if (variableValueList != null) {
155                    variableValueList.doParse(this, ESqlClause.unknown);
156                }
157                break;
158        }
159
160
161        return 0;
162    }
163    public void accept(TParseTreeVisitor v){
164        v.preVisit(this);
165        v.postVisit(this);
166    }
167    public void acceptChildren(TParseTreeVisitor v){
168        v.preVisit(this);
169        if (variableValue != null) {
170            variableValue.acceptChildren(v);
171        }
172        if (variableValueList != null) {
173            variableValueList.acceptChildren(v);
174        }
175        if (assignments != null) {
176            assignments.acceptChildren(v);
177        }
178        v.postVisit(this);
179    }
180
181}