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 if (!(rootNode instanceof TSetSqlNode)) { 075 TSourceToken errorToken = rootNode.getStartToken(); 076 if ((errorToken == null) && (sourcetokenlist.size() > 0)) { 077 errorToken = sourcetokenlist.get(0); 078 } 079 if (errorToken != null) { 080 parseerrormessagehandle(new TSyntaxError(errorToken, 081 "invalid SET statement", EErrorType.sperror, 082 TBaseType.MSG_ERROR_SYNTAX_ERROR, this)); 083 } else { 084 parseerrormessagehandle(new TSyntaxError("SET", 0, 0, 085 "invalid SET statement", EErrorType.sperror, 086 TBaseType.MSG_ERROR_SYNTAX_ERROR, this, -1)); 087 } 088 return TBaseType.MSG_ERROR_SYNTAX_ERROR; 089 } 090 TSetSqlNode node = (TSetSqlNode)rootNode; 091 setStatementType = node.getSetStatementType(); 092 093 switch (dbvendor){ 094 case dbvmysql: 095 assignments = node.getAssignments(); 096 if (setStatementType == ESetStatementType.variable){ 097 for (int i=0;i<assignments.size();i++){ 098 assignments.getElement(i).getParameterValue().doParse(this,ESqlClause.setVariable); 099 } 100 } 101 102 103 characterSetName = node.getCharacterSetName(); 104 collationName = node.getCollationName(); 105 userName = node.getUserName(); 106 password = node.getPassword(); 107 isolationLevel = node.getIsolationLevel(); 108 109 break; 110 case dbvgreenplum: 111 case dbvpostgresql: 112 case dbvgaussdb: 113 case dbvedb: 114 switch (setStatementType){ 115 case variable: 116 variableName = node.getVariableName(); 117 variableNameList = node.getVariableNameList(); 118 variableValue = node.getVariableValue(); 119 variableValueList = node.getVariableValueList(); 120 if (variableName.toString().equalsIgnoreCase("search_path")){ 121 if (getSqlEnv() != null) { 122 getSqlEnv().setDefaultSchemaName(variableValueList.getExpression(0).toString()); 123 } 124 } 125 break; 126 case reset: 127 variableName = node.getVariableName(); 128 variableName.setDbObjectType(EDbObjectType.variable); 129 break; 130 default: 131 break; 132 } 133 134 break; 135 case dbvbigquery: 136 variableName = node.getVariableName(); 137 variableValue = node.getVariableValue(); 138 variableValue.doParse(this,ESqlClause.unknown); 139 140 variableNameList = node.getVariableNameList(); 141 variableValueList = node.getVariableValueList(); 142 if (variableValueList != null){ 143 variableValueList.doParse(this,ESqlClause.unknown); 144 } 145 146 break; 147 case dbvsnowflake: 148 variableName = node.getVariableName(); 149 if (variableName != null){ 150 variableValue = node.getVariableValue(); 151 variableValue.doParse(this,ESqlClause.unknown); 152 } 153 154 variableNameList = node.getVariableNameList(); 155 if (variableNameList != null){ 156 variableValueList = node.getVariableValueList(); 157 if (variableValueList != null){ 158 variableValueList.doParse(this,ESqlClause.unknown); 159 } 160 } 161 162 break; 163 default: 164 variableName = node.getVariableName(); 165 variableNameList = node.getVariableNameList(); 166 variableValue = node.getVariableValue(); 167 variableValueList = node.getVariableValueList(); 168 if (variableValue != null) { 169 variableValue.doParse(this, ESqlClause.unknown); 170 } 171 if (variableValueList != null) { 172 variableValueList.doParse(this, ESqlClause.unknown); 173 } 174 break; 175 } 176 177 178 return 0; 179 } 180 public void accept(TParseTreeVisitor v){ 181 v.preVisit(this); 182 v.postVisit(this); 183 } 184 public void acceptChildren(TParseTreeVisitor v){ 185 v.preVisit(this); 186 if (variableValue != null) { 187 variableValue.acceptChildren(v); 188 } 189 if (variableValueList != null) { 190 variableValueList.acceptChildren(v); 191 } 192 if (assignments != null) { 193 assignments.acceptChildren(v); 194 } 195 v.postVisit(this); 196 } 197 198}