1 33 package smallsql.database; 34 35 36 public class ExpressionName extends Expression { 37 38 private String tableAlias; 39 private DataSource fromEntry; 40 private int colIdx; 41 private TableView table; 42 private Column column; 43 44 ExpressionName(String name){ 46 super(NAME); 47 setName( name ); 48 } 49 50 54 ExpressionName(int type){ 55 super(type); 56 } 58 59 void setNameAfterTableAlias(String name){ 60 tableAlias = getName(); 61 setName( name ); 62 } 63 64 67 public boolean equals(Object expr){ 68 if(!super.equals(expr)) return false; 69 if(!(expr instanceof ExpressionName)) return false; 70 if( ((ExpressionName)expr).fromEntry != fromEntry) return false; 71 return true; 72 } 73 74 boolean isNull() throws Exception { 75 return fromEntry.isNull(colIdx); 76 } 77 78 boolean getBoolean() throws Exception { 79 return fromEntry.getBoolean(colIdx); 80 } 81 82 int getInt() throws Exception { 83 return fromEntry.getInt(colIdx); 84 } 85 86 long getLong() throws Exception { 87 return fromEntry.getLong(colIdx); 88 } 89 90 float getFloat() throws Exception { 91 return fromEntry.getFloat(colIdx); 92 } 93 94 double getDouble() throws Exception { 95 return fromEntry.getDouble(colIdx); 96 } 97 98 long getMoney() throws Exception { 99 return fromEntry.getMoney(colIdx); 100 } 101 102 MutableNumeric getNumeric() throws Exception { 103 return fromEntry.getNumeric(colIdx); 104 } 105 106 Object getObject() throws Exception { 107 return fromEntry.getObject(colIdx); 108 } 109 110 String getString() throws Exception { 111 return fromEntry.getString(colIdx); 112 } 113 114 byte[] getBytes() throws Exception { 115 return fromEntry.getBytes(colIdx); 116 } 117 118 int getDataType(){ 119 switch(getType()){ 120 case NAME: 121 case GROUP_BY: 122 return fromEntry.getDataType(colIdx); 123 case FIRST: 124 case LAST: 125 case MAX: 126 case MIN: 127 case SUM: 128 return getParams()[0].getDataType(); 129 case COUNT: 130 return SQLTokenizer.INT; 131 default: throw new Error (); 132 } 133 } 134 135 139 void setFrom( DataSource fromEntry, int colIdx, TableView table ){ 140 this.fromEntry = fromEntry; 141 this.colIdx = colIdx; 142 this.table = table; 143 this.column = table.columns.get(colIdx); 145 } 146 147 151 void setFrom( DataSource fromEntry, int colIdx, Column column ){ 152 this.fromEntry = fromEntry; 153 this.colIdx = colIdx; 154 this.column = column; 155 } 156 157 String getTableAlias(){ return tableAlias; } 158 159 163 final TableView getTable(){ 164 return table; 165 } 166 167 171 final int getColumnIndex(){ 172 return colIdx; 173 } 174 175 176 final Column getColumn(){ 177 return column; 178 } 179 180 181 final public String toString(){ 182 if(tableAlias == null) return String.valueOf(getAlias()); 183 return tableAlias + "." + getAlias(); 184 } 185 186 187 192 193 String getTableName(){ 194 if(table != null){ 195 return table.getName(); 196 } 197 return null; 198 } 199 200 int getPrecision(){ 201 return column.getPrecision(); 202 } 203 204 int getScale(){ 205 return column.getScale(); 206 } 207 208 int getDisplaySize(){ 209 return column.getDisplaySize(); 210 } 211 212 boolean isAutoIncrement(){ 213 return column.isAutoIncrement(); 214 } 215 216 boolean isCaseSensitive(){ 217 return column.isCaseSensitive(); 218 } 219 220 boolean isNullable(){ 221 return column.isNullable(); 222 } 223 224 boolean isDefinitelyWritable(){ 225 return true; 226 } 227 228 } | Popular Tags |