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 java.util.ArrayList ; 15 import java.util.Arrays ; 16 import in.co.daffodil.db.jdbc.DatabaseProperties; 17 18 public class insertfunction extends AbstractStringValueExpression implements charactervaluefunction { 19 public Srightparen_1874859514 _Srightparen_18748595140; 20 public charactervalueexpression _charactervalueexpression1; 21 public Scomma94843605 _Scomma948436052; 22 public numericvalueexpression _numericvalueexpression3; 23 public Scomma94843605 _Scomma948436054; 24 public numericvalueexpression _numericvalueexpression5; 25 public Scomma94843605 _Scomma948436056; 26 public charactervalueexpression _charactervalueexpression7; 27 public Sleftparen653880241 _Sleftparen6538802418; 28 public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439229; 29 30 public Object run(Object object) throws com.daffodilwoods.database.resource. 31 DException { 32 33 FieldBase result1 = (FieldBase) _charactervalueexpression7.run(object); 34 if (result1.isNull()) { 35 return new FieldStringLiteral(FieldUtility.NULLBUFFERRANGE, CHARACTER); 36 } 37 FieldBase result4 = (FieldBase) _charactervalueexpression1.run(object); 38 if (result4.isNull()) { 39 return new FieldStringLiteral(FieldUtility.NULLBUFFERRANGE, CHARACTER); 40 } 41 FieldBase result2 = (FieldBase) _numericvalueexpression5.run(object); 42 if (result2.isNull()) { 43 return new FieldStringLiteral(FieldUtility.NULLBUFFERRANGE, CHARACTER); 44 } 45 FieldBase result3 = (FieldBase) _numericvalueexpression3.run(object); 46 if (result3.isNull()) { 47 return new FieldStringLiteral(FieldUtility.NULLBUFFERRANGE, CHARACTER); 48 } 49 return getResult(getDataType(result1), getDataType(result4), 50 result1.getObject(), getCount(result2.getObject(), 51 getDataType(result2)), getCount(result3.getObject(), 52 getDataType(result3)), result4.getObject()); 53 54 } 55 56 public ColumnDetails[] getChildColumnDetails() throws DException { 57 return columnDetails; 58 } 59 60 public ParameterInfo[] getParameterInfo() throws DException { 61 ArrayList list =new ArrayList (); 62 ParameterInfo[] param1 = _charactervalueexpression7.getParameterInfo(); 63 for (int i = 0; i < param1.length; i++) { 64 if (param1[i].getQuestionMark()) { 65 param1[i].setDataType(Datatypes.CHARACTER); 66 param1[i].setName("INSERT Arg1"); 67 list.addAll(Arrays.asList(param1)); 68 } 69 } 70 ParameterInfo[] param2 = _numericvalueexpression5.getParameterInfo(); 71 for (int i = 0; i < param2.length; i++) { 72 if (param2[i].getQuestionMark()) { 73 param2[i].setDataType(Datatypes.INTEGER); 74 param2[i].setName("INSERT Arg2"); 75 list.addAll(Arrays.asList(param2)); 76 } 77 } 78 ParameterInfo[] param3 = _numericvalueexpression3.getParameterInfo(); 79 for (int i = 0; i < param3.length; i++) { 80 if (param3[i].getQuestionMark()) { 81 param3[i].setDataType(Datatypes.INTEGER); 82 param3[i].setName("INSERT Arg3"); 83 list.addAll(Arrays.asList(param3)); 84 } 85 } 86 ParameterInfo[] param4 = _charactervalueexpression1.getParameterInfo(); 87 for (int i = 0; i <param4.length; i++) { 88 if (param4[i].getQuestionMark()) { 89 param4[i].setDataType(Datatypes.CHARACTER); 90 param4[i].setName("INSERT Arg4"); 91 list.addAll(Arrays.asList(param4)); 92 } 93 } 94 ParameterInfo[] param = new ParameterInfo[list.size()]; 95 list.toArray(param); 96 for (int i = 0; i < param.length; i++) { 97 if(param[i].getQuestionMark()) 98 return param; 99 } 100 return getThisParameterInfo(); 101 } 102 103 protected ParameterInfo[] getThisParameterInfo() throws DException { 104 ParameterInfo parameterInfo = new ParameterInfo(); 105 parameterInfo.setName(toString()); 106 parameterInfo.setDataType(Datatypes.CHARACTER); 107 return new ParameterInfo[] { 108 parameterInfo}; 109 } 110 111 protected String getNameOfColumn(ColumnDetails[] columnDetails) throws 112 DException { 113 String nameOfColumn = ""; 114 for (int i = 0; i < columnDetails.length; ++i) { 115 nameOfColumn += columnDetails[i].getColumn(); 116 } 117 return nameOfColumn; 118 } 119 120 138 139 private Object getResult(int type1, int type2, Object result1, 140 Integer result2, Integer result3, Object result4) throws 141 DException { 142 int second = result2.intValue(); 143 int third = result3.intValue(); 144 switch (type1) { 145 case DATE: 146 throw new DException("DSE4106", new Object [] {"DATE"}); 147 case TIME: 148 throw new DException("DSE4106", new Object [] {"TIME"}); 149 case TIMESTAMP: 150 throw new DException("DSE4106", new Object [] {"TIMESTAMP"}); 151 default: 152 switch (type2) { 153 case DATE: 154 throw new DException("DSE4108", new Object [] {"date", "insert"}); 155 case TIME: 156 throw new DException("DSE4108", new Object [] {"time", "insert"}); 157 case TIMESTAMP: 158 throw new DException("DSE4108", new Object [] {"timestamp", "insert"}); 159 default: 160 return new FieldStringLiteral(insert(result1.toString(), second, third, result4.toString()), Datatype.CHARACTER); 161 } 162 } 163 } 164 165 private Integer getCount(Object object, int type) throws DException { 166 switch (type) { 167 case BYTE: 168 case TINYINT: 169 case INTEGER: 170 case INT: 171 case REAL: 172 case DOUBLE: 173 case FLOAT: 174 case DOUBLEPRECISION: 175 case LONG: 176 case BIGINT: 177 case SHORT: 178 case SMALLINT: 179 case BIGDECIMAL: 180 case DEC: 181 case DECIMAL: 182 case NUMERIC: 183 Number operand = (Number ) object; 184 return new Integer (operand.intValue()); 185 case CHARACTER: 186 case VARCHAR: 187 case CHAR: 188 case CHARACTERVARYING: 189 String string = (String ) object; 190 Double d = null; 191 try { 192 d = new Double (string); 193 } catch (Exception e) { 194 throw new DException("DSE4104", null); 195 } 196 return new Integer (d.intValue()); 197 default: 198 throw new DException("DSE419", new Object [] {"INSERTFUNCTION"}); 199 } 200 } 201 202 232 233 private String insert(String string1, int start, int length, String string2) throws 234 DException { 235 if (!qualifyForOperation(string1)) { 236 return string2; 237 } 238 if (!qualifyForOperation(string2)) { 239 return string1; 240 } 241 if (string1.length() <= (start - 1)) { 242 return string1; 243 } 244 if (start < 0 || length < 0) { 245 throw new DException("DSE1160", null); 246 } 247 start = start - 1; 248 if (start < 0) { 249 throw new DException("DSE1160", null); 250 } 251 if (string1.length() <= (start + length)) { 252 return string1.substring(0, start).concat(string2); 253 } 254 String tempString = string1.substring(start + length); 255 string1 = string1.substring(0, start); 256 return string1 + string2 + tempString; 257 } 258 259 private boolean qualifyForOperation(String string) throws DException { 260 if (string == null || string.length() == 0) { 261 return false; 262 } 263 return true; 264 } 265 266 public AbstractRowValueExpression[] getChilds() { 267 AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] { 268 (AbstractRowValueExpression) (_charactervalueexpression7), 269 (AbstractRowValueExpression) (_numericvalueexpression5), 270 (AbstractRowValueExpression) (_numericvalueexpression3), 271 (AbstractRowValueExpression) (_charactervalueexpression1)}; 272 return childs; 273 274 } 275 276 public String getType() throws DException { 277 return (String ) _SRESERVEDWORD12065439229.run(null); 278 } 279 280 public String toString() { 281 StringBuffer sb = new StringBuffer (); 282 sb.append(" "); 283 sb.append(_SRESERVEDWORD12065439229); 284 sb.append(" "); 285 sb.append(_Sleftparen6538802418); 286 sb.append(" "); 287 sb.append(_charactervalueexpression7); 288 sb.append(" "); 289 sb.append(_Scomma948436056); 290 sb.append(" "); 291 sb.append(_numericvalueexpression5); 292 sb.append(" "); 293 sb.append(_Scomma948436054); 294 sb.append(" "); 295 sb.append(_numericvalueexpression3); 296 sb.append(" "); 297 sb.append(_Scomma948436052); 298 sb.append(" "); 299 sb.append(_charactervalueexpression1); 300 sb.append(" "); 301 sb.append(_Srightparen_18748595140); 302 return sb.toString(); 303 } 304 305 public Object clone() throws CloneNotSupportedException { 306 insertfunction tempClass = new insertfunction(); 307 tempClass._Srightparen_18748595140 = (Srightparen_1874859514) 308 _Srightparen_18748595140.clone(); 309 tempClass._charactervalueexpression1 = (charactervalueexpression) 310 _charactervalueexpression1.clone(); 311 tempClass._Scomma948436052 = (Scomma94843605) _Scomma948436052.clone(); 312 tempClass._numericvalueexpression3 = (numericvalueexpression) 313 _numericvalueexpression3.clone(); 314 tempClass._Scomma948436054 = (Scomma94843605) _Scomma948436054.clone(); 315 tempClass._numericvalueexpression5 = (numericvalueexpression) 316 _numericvalueexpression5.clone(); 317 tempClass._Scomma948436056 = (Scomma94843605) _Scomma948436056.clone(); 318 tempClass._charactervalueexpression7 = (charactervalueexpression) 319 _charactervalueexpression7.clone(); 320 tempClass._Sleftparen6538802418 = (Sleftparen653880241) 321 _Sleftparen6538802418.clone(); 322 tempClass._SRESERVEDWORD12065439229 = (SRESERVEDWORD1206543922) 323 _SRESERVEDWORD12065439229.clone(); 324 return tempClass; 325 } 326 327 public _Reference[] checkSemantic(_ServerSession parent) throws DException { 328 _Reference[] ref = super.checkSemantic(parent); 329 if(ref!=null) { 330 return ref; 331 } 332 int type1 = _charactervalueexpression7.getByteComparison(parent).getDataTypes()[0]; 333 int type2 = _charactervalueexpression1.getByteComparison(parent).getDataTypes()[0]; 334 switch (type1) { 335 case DATE: 336 throw new DException("DSE4106", new Object [] {"DATE"}); 337 case TIME: 338 throw new DException("DSE4106", new Object [] {"TIME"}); 339 case TIMESTAMP: 340 throw new DException("DSE4106", new Object [] {"TIMESTAMP"}); 341 case -1: 342 default: 343 switch (type2) { 344 case DATE: 345 throw new DException("DSE4108", new Object [] {"date", "insert"}); 346 case TIME: 347 throw new DException("DSE4108", new Object [] {"time", "insert"}); 348 case TIMESTAMP: 349 throw new DException("DSE4108", new Object [] {"timestamp", "insert"}); 350 case -1: 351 default: 352 return ref; 353 } 354 } 355 } 356 357 public int getColumnSize(Object object) throws DException{ 358 ColumnDetails[] columnDetails = getChildColumnDetails(); 359 if (columnDetails[0].getQuestion()) { 360 return DatabaseProperties.maxCharLiteralLength; 361 } 362 else if (columnDetails[0].getType() != TypeConstants.CONSTANT || 363 columnDetails[0].getSize() != -5) { 364 return columnDetails[0].getSize(); 365 } 366 else { 367 FieldBase field = (FieldBase) _charactervalueexpression7.run(object); 368 field.setDatatype(columnDetails[0].getDatatype()); 369 return field.getLength(); 370 } 371 } 372 373 } 374 | Popular Tags |