001package gudusoft.gsqlparser.nodes; 002 003import gudusoft.gsqlparser.ESqlClause; 004import gudusoft.gsqlparser.TBaseType; 005import gudusoft.gsqlparser.TCustomSqlStatement; 006 007/** 008* SQL Server declare variable 009*/ 010public class TDeclareVariable extends TParseTreeNode { 011 012 private TObjectNameList variableNameList = null; 013 014 public TObjectNameList getVariableNameList() { 015 return variableNameList; 016 } 017 018 private TObjectName variableName = null; 019 private int variableType = TBaseType.declare_varaible_normal; 020 private TTypeName datatype = null; 021 private TExpression defaultValue = null; 022 private TTableElementList tableTypeDefinitions = null; 023 024 public void setTableTypeDefinitions(TTableElementList tableTypeDefinitions) { 025 this.tableTypeDefinitions = tableTypeDefinitions; 026 } 027 028 public void setVariableType(int variableType) { 029 this.variableType = variableType; 030 } 031 032 public TTableElementList getTableTypeDefinitions() { 033 034 return tableTypeDefinitions; 035 } 036 037 public void setDefaultValue(TExpression defaultValue) { 038 this.defaultValue = defaultValue; 039 } 040 041 public TTypeName getDatatype() { 042 043 return datatype; 044 } 045 046 public TExpression getDefaultValue() { 047 return defaultValue; 048 } 049 050 public TObjectName getVariableName() { 051 return variableName; 052 } 053 054 public int getVariableType() { 055 return variableType; 056 } 057 058 public void init(Object arg1){ 059 if (arg1 instanceof TObjectName){ 060 this.variableName = (TObjectName)arg1; 061 }else if (arg1 instanceof TObjectNameList){ 062 this.variableNameList = (TObjectNameList)arg1; 063 this.variableName = variableNameList.getObjectName(0); 064 } 065 066 } 067 068 public void setDatatype(TTypeName datatype) { 069 this.datatype = datatype; 070 } 071 072 public void init(Object arg1,Object arg2){ 073 init(arg1); 074 if (arg2 != null){ 075 076 TTypeName o = (TTypeName)arg2; 077 if (o.toString().equalsIgnoreCase("cursor")){ 078 this.variableType = TBaseType.declare_varaible_cursor; 079 }else{ 080 this.variableType = TBaseType.declare_varaible_normal; 081 this.datatype = (TTypeName)arg2; 082 } 083 }else{ 084 this.variableType = TBaseType.declare_varaible_table; 085 } 086 087 } 088 089 public void doParse(TCustomSqlStatement psql, ESqlClause plocation){ 090 if (getDefaultValue() != null){ 091 getDefaultValue().doParse(psql,plocation); 092 } 093 } 094 095 096 public void accept(TParseTreeVisitor v){ 097 v.preVisit(this); 098 v.postVisit(this); 099 } 100 101 public void acceptChildren(TParseTreeVisitor v){ 102 v.preVisit(this); 103 if (this.getVariableNameList() != null){ 104 this.getVariableNameList().acceptChildren(v); 105 } 106 else if (this.getVariableName() != null){ 107 this.getVariableName().acceptChildren(v); 108 } 109 110 if (this.getDatatype() != null){ 111 this.getDatatype().acceptChildren(v); 112 } 113 if (this.getDefaultValue() != null){ 114 this.getDefaultValue().acceptChildren(v); 115 } 116 v.postVisit(this); 117 } 118 119 public void setVariableName(TObjectName variableName) { 120 this.variableName = variableName; 121 } 122}