1 package com.daffodilwoods.daffodildb.server.sql99.expression. 2 stringvalueexpression; 3 4 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*; 5 import com.daffodilwoods.daffodildb.server.serversystem.*; 6 import com.daffodilwoods.daffodildb.server.sql99.common.*; 7 import com.daffodilwoods.daffodildb.server.sql99.expression.rowvalueexpression.*; 8 import com.daffodilwoods.daffodildb.server.sql99.token.*; 9 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 10 import com.daffodilwoods.daffodildb.utils.*; 11 import com.daffodilwoods.daffodildb.utils.field.*; 12 import com.daffodilwoods.database.resource.*; 13 import com.daffodilwoods.database.utility.*; 14 import com.daffodilwoods.daffodildb.server.sql99.expression.numericvalueexpression.AbstractNumericValueFunction; 15 16 public class asciivaluemethod extends AbstractNumericValueFunction implements charactervaluefunction, IntegerPool { 17 18 public Srightparen_1874859514 _Srightparen_18748595140; 19 public charactervalueexpression _charactervalueexpression1; 20 public Sleftparen653880241 _Sleftparen6538802412; 21 public SNONRESERVEDWORD136444255 _SNONRESERVEDWORD1364442553; 22 23 public Object run(Object object) throws com.daffodilwoods.database.resource. 24 DException { 25 FieldBase result = (FieldBase) _charactervalueexpression1.run(object); 26 return (result.isNull()) ? 27 new FieldLiteral(FieldUtility.NULLBUFFERRANGE, INTEGER) 28 : getResult(result.getObject(), getDataType(result)); 29 } 30 31 public ColumnDetails[] getChildColumnDetails() throws DException { 32 return columnDetails; 33 } 34 35 protected String getNameOfColumn(ColumnDetails[] columnDetails) throws 36 DException { 37 String nameOfColumn = ""; 38 for (int i = 0; i < columnDetails.length; ++i) { 39 nameOfColumn += columnDetails[i].getColumn(); 40 } 41 return nameOfColumn; 42 } 43 44 public ParameterInfo[] getParameterInfo() throws DException { 45 ParameterInfo[] param =_charactervalueexpression1.getParameterInfo(); 46 for (int i = 0; i < param.length; i++) { 47 if (param[i].getQuestionMark()) { 48 param[i].setDataType(Datatypes.CHARACTER); 49 param[i].setName("ASCII Arg"); 50 return param; 51 } 52 } 53 return getThisParametersInfo(); 54 } 55 56 private ParameterInfo[] getThisParametersInfo() throws DException { 57 ParameterInfo parameterInfo = new ParameterInfo(); 58 parameterInfo.setName(toString()); 59 parameterInfo.setDataType(Datatypes.INTEGER); 60 return new ParameterInfo[] {parameterInfo}; 61 } 62 63 83 84 private Object getResult(Object object, int type) throws DException { 85 switch (type) { 86 case BYTE: 87 case TINYINT: 88 case INTEGER: 89 case INT: 90 case REAL: 91 case DOUBLE: 92 case FLOAT: 93 case DOUBLEPRECISION: 94 case LONG: 95 case BIGINT: 96 case SHORT: 97 case SMALLINT: 98 case BIGDECIMAL: 99 case DEC: 100 case DECIMAL: 101 case NUMERIC: 102 Number number = (Number ) object; 103 return ascii(number.toString()); 104 case CHARACTER: 105 case VARCHAR: 106 case CHAR: 107 case CHARACTERVARYING: 108 String string = (String ) object; 109 return ascii(string); 110 default: 111 throw new DException("DSE4108", new Object [] {StaticClass.getDataTypeName(type), "ASCII"}); 112 } 113 } 114 115 144 145 private Object ascii(String string) throws DException { 146 if (!qualifyForOperation(string)) { 147 return new FieldLiteral(FieldUtility.NULLBUFFERRANGE, INTEGER); 148 } 149 return new FieldLiteral(new Integer ( (int) string.charAt(0)), Datatype.INTEGER); 150 } 151 152 private boolean qualifyForOperation(String string) throws DException { 153 if (string == null || string.length() == 0) { 154 return false; 155 } 156 return true; 157 } 158 159 public AbstractRowValueExpression[] getChilds() { 160 AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] { 161 (AbstractRowValueExpression) (_charactervalueexpression1)}; 162 return childs; 163 164 } 165 166 public String getType() throws DException { 167 return (String ) _SNONRESERVEDWORD1364442553.run(null); 168 } 169 170 public String toString() { 171 StringBuffer sb = new StringBuffer (); 172 sb.append(" "); 173 sb.append(_SNONRESERVEDWORD1364442553); 174 sb.append(" "); 175 sb.append(_Sleftparen6538802412); 176 sb.append(" "); 177 sb.append(_charactervalueexpression1); 178 sb.append(" "); 179 sb.append(_Srightparen_18748595140); 180 return sb.toString(); 181 } 182 183 public Object clone() throws CloneNotSupportedException { 184 asciivaluemethod tempClass = new asciivaluemethod(); 185 tempClass._Srightparen_18748595140 = (Srightparen_1874859514) 186 _Srightparen_18748595140.clone(); 187 tempClass._charactervalueexpression1 = (charactervalueexpression) 188 _charactervalueexpression1.clone(); 189 tempClass._Sleftparen6538802412 = (Sleftparen653880241) 190 _Sleftparen6538802412.clone(); 191 tempClass._SNONRESERVEDWORD1364442553 = (SNONRESERVEDWORD136444255) 192 _SNONRESERVEDWORD1364442553.clone(); 193 return tempClass; 194 } 195 196 public ByteComparison getByteComparison(Object object) throws DException { 197 ByteComparison byteComparison = new ByteComparison(false, new int[] {INTEGER}); 198 byteComparison.setSize(getColumnSize(object)); 199 return byteComparison; 200 } 201 202 public _Reference[] checkSemantic(_ServerSession parent) throws DException { 203 _Reference[] ref = super.checkSemantic(parent); 204 if(ref!=null) { 205 return ref; 206 } 207 int type = _charactervalueexpression1.getByteComparison(parent).getDataTypes()[0]; 208 switch (type) { 209 case -1: 210 case BYTE: 211 case TINYINT: 212 case INTEGER: 213 case INT: 214 case REAL: 215 case DOUBLE: 216 case FLOAT: 217 case DOUBLEPRECISION: 218 case LONG: 219 case BIGINT: 220 case SHORT: 221 case SMALLINT: 222 case BIGDECIMAL: 223 case DEC: 224 case DECIMAL: 225 case NUMERIC: 226 case CHARACTER: 227 case VARCHAR: 228 case CHAR: 229 case CHARACTERVARYING: 230 return ref; 231 default: 232 throw new DException("DSE4108", new Object [] {StaticClass.getDataTypeName(type), "ASCII"}); 233 } 234 } 235 public int getColumnSize(Object object) throws DException { 236 return Datatypes.INTSIZE; 237 } 238 239 } 240 | Popular Tags |