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 case dbvedb: 098 switch (setStatementType){ 099 case variable: 100 variableName = node.getVariableName(); 101 variableNameList = node.getVariableNameList(); 102 variableValue = node.getVariableValue(); 103 variableValueList = node.getVariableValueList(); 104 if (variableName.toString().equalsIgnoreCase("search_path")){ 105 if (getSqlEnv() != null) { 106 getSqlEnv().setDefaultSchemaName(variableValueList.getExpression(0).toString()); 107 } 108 } 109 break; 110 case reset: 111 variableName = node.getVariableName(); 112 variableName.setDbObjectType(EDbObjectType.variable); 113 break; 114 default: 115 break; 116 } 117 118 break; 119 case dbvbigquery: 120 variableName = node.getVariableName(); 121 variableValue = node.getVariableValue(); 122 variableValue.doParse(this,ESqlClause.unknown); 123 124 variableNameList = node.getVariableNameList(); 125 variableValueList = node.getVariableValueList(); 126 if (variableValueList != null){ 127 variableValueList.doParse(this,ESqlClause.unknown); 128 } 129 130 break; 131 case dbvsnowflake: 132 variableName = node.getVariableName(); 133 if (variableName != null){ 134 variableValue = node.getVariableValue(); 135 variableValue.doParse(this,ESqlClause.unknown); 136 } 137 138 variableNameList = node.getVariableNameList(); 139 if (variableNameList != null){ 140 variableValueList = node.getVariableValueList(); 141 if (variableValueList != null){ 142 variableValueList.doParse(this,ESqlClause.unknown); 143 } 144 } 145 146 break; 147 default: 148 variableName = node.getVariableName(); 149 variableNameList = node.getVariableNameList(); 150 variableValue = node.getVariableValue(); 151 variableValueList = node.getVariableValueList(); 152 if (variableValue != null) { 153 variableValue.doParse(this, ESqlClause.unknown); 154 } 155 if (variableValueList != null) { 156 variableValueList.doParse(this, ESqlClause.unknown); 157 } 158 break; 159 } 160 161 162 return 0; 163 } 164 public void accept(TParseTreeVisitor v){ 165 v.preVisit(this); 166 v.postVisit(this); 167 } 168 public void acceptChildren(TParseTreeVisitor v){ 169 v.preVisit(this); 170 if (variableValue != null) { 171 variableValue.acceptChildren(v); 172 } 173 if (variableValueList != null) { 174 variableValueList.acceptChildren(v); 175 } 176 if (assignments != null) { 177 assignments.acceptChildren(v); 178 } 179 v.postVisit(this); 180 } 181 182}