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.numericvalueexpression.*; 8 import com.daffodilwoods.daffodildb.server.sql99.expression.rowvalueexpression.*; 9 import com.daffodilwoods.daffodildb.server.sql99.token.*; 10 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 11 import com.daffodilwoods.daffodildb.utils.*; 12 import com.daffodilwoods.daffodildb.utils.field.*; 13 import com.daffodilwoods.database.resource.*; 14 import in.co.daffodil.db.jdbc.DatabaseProperties; 15 16 public class charfunction extends AbstractStringValueExpression implements charactervaluefunction { 17 18 public parennumericvalueexpression _parennumericvalueexpression0; 19 public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439221; 20 21 public Object run(Object object) throws com.daffodilwoods.database.resource. 22 DException { 23 FieldBase result = (FieldBase) _parennumericvalueexpression0.run(object); 24 return (result.isNull()) ? new FieldStringLiteral(FieldUtility.NULLBUFFERRANGE, CHARACTER) 25 : getResult(result); 26 } 27 28 public ColumnDetails[] getChildColumnDetails() throws DException { 29 return columnDetails; 30 } 31 32 protected String getNameOfColumn(ColumnDetails[] columnDetails) throws 33 DException { 34 String nameOfColumn = ""; 35 for (int i = 0; i < columnDetails.length; ++i) { 36 nameOfColumn += columnDetails[i].getColumn(); 37 } 38 return nameOfColumn; 39 } 40 41 public ParameterInfo[] getParameterInfo() throws DException { 42 ParameterInfo[] param =_parennumericvalueexpression0.getParameterInfo(); 43 for (int i = 0; i < param.length; i++) { 44 if (param[i].getQuestionMark()) { 45 param[i].setDataType(Datatypes.INTEGER); 46 param[i].setName("CHAR Arg"); 47 return param; 48 } 49 } 50 return getThisParameterInfo(); 51 } 52 53 protected ParameterInfo[] getThisParameterInfo() throws DException { 54 ParameterInfo parameterInfo = new ParameterInfo(); 55 parameterInfo.setName(toString()); 56 parameterInfo.setDataType(Datatypes.CHARACTER); 57 return new ParameterInfo[] { 58 parameterInfo}; 59 } 60 61 62 82 83 private Object getResult(FieldBase object) throws DException { 84 int type = getDataType(object); 85 switch (type) { 86 case BYTE: 87 case TINYINT: 88 case SHORT: 89 case SMALLINT: 90 case INTEGER: 91 case INT: 92 case REAL: 93 case LONG: 94 case BIGINT: 95 case BIGDECIMAL: 96 case DEC: 97 case DECIMAL: 98 case NUMERIC: 99 case DOUBLE: 100 case FLOAT: 101 case DOUBLEPRECISION: 102 return toChar( ( (Number ) object.getObject()).intValue()); 103 case CHARACTER :case VARCHAR: case CHAR: case CHARACTERVARYING: 104 String string = (String ) object.getObject(); 105 int value = 0; 106 try { 107 value = new Integer (string).intValue(); 108 } 109 catch (NumberFormatException ex) { 110 throw new DException("DSE773",null); 111 } 112 return toChar(value); 113 default: 114 throw new DException("DSE4108", new Object [] {StaticClass.getDataTypeName(type), "CHAR"}); 115 } 116 } 117 118 private Object toChar(int code) throws DException { 119 if (code < 0 || code > 255) { 120 return new FieldStringLiteral(FieldUtility.NULLBUFFERRANGE, CHARACTER); 121 } 122 return new FieldStringLiteral(new Character ( (char) code).toString(), Datatype.CHARACTER); } 124 125 public AbstractRowValueExpression[] getChilds() { 126 AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] { 127 (AbstractRowValueExpression) (_parennumericvalueexpression0)}; 128 return childs; 129 } 130 131 public String getType() throws DException { 132 return (String ) _SRESERVEDWORD12065439221.run(null); 133 } 134 135 public String toString() { 136 StringBuffer sb = new StringBuffer (); 137 sb.append(" "); 138 sb.append(_SRESERVEDWORD12065439221); 139 sb.append(" "); 140 sb.append(_parennumericvalueexpression0); 141 return sb.toString(); 142 } 143 144 public Object clone() throws CloneNotSupportedException { 145 charfunction tempClass = new charfunction(); 146 tempClass._parennumericvalueexpression0 = (parennumericvalueexpression) 147 _parennumericvalueexpression0.clone(); 148 tempClass._SRESERVEDWORD12065439221 = (SRESERVEDWORD1206543922) 149 _SRESERVEDWORD12065439221.clone(); 150 return tempClass; 151 } 152 153 public ByteComparison getByteComparison(Object object) throws DException { 154 ByteComparison byteComparison =new ByteComparison(false, new int[] {CHARACTER}); 155 byteComparison.setSize(getColumnSize(object)); 156 return byteComparison; 157 } 158 159 public _Reference[] checkSemantic(_ServerSession parent) throws DException { 160 _Reference[] ref = super.checkSemantic(parent); 161 if(ref!=null) { 162 return ref; 163 } 164 int type = _parennumericvalueexpression0.getByteComparison(parent).getDataTypes()[0]; 165 if (type == -1 || type <= 15) { 166 return ref; 167 } 168 throw new DException("DSE4108", new Object [] {StaticClass.getDataTypeName(type), "CHAR"}); 169 } 170 171 172 public int getColumnSize(Object object) throws DException { 173 177 return 1; 178 188 } 189 190 } 191 | Popular Tags |