1 34 package smallsql.database; 35 36 abstract class ExpressionFunctionReturnP1Number extends ExpressionFunctionReturnP1 { 37 38 39 final boolean getBoolean() throws Exception { 40 return getDouble() != 0; 41 } 42 43 44 final int getInt() throws Exception { 45 return Utils.long2int(getLong()); 46 } 47 48 49 final long getLong() throws Exception { 50 return Utils.double2long(getDouble()); 51 } 52 53 54 final float getFloat() throws Exception { 55 return (float)getDouble(); 56 } 57 58 59 MutableNumeric getNumeric() throws Exception { 60 if(param1.isNull()) return null; 61 switch(getDataType()){ 62 case SQLTokenizer.INT: 63 return new MutableNumeric(getInt()); 64 case SQLTokenizer.BIGINT: 65 return new MutableNumeric(getLong()); 66 case SQLTokenizer.MONEY: 67 return new MutableNumeric(getMoney(), 4); 68 case SQLTokenizer.DECIMAL: 69 MutableNumeric num = param1.getNumeric(); 70 num.floor(); 71 return num; 72 case SQLTokenizer.DOUBLE: 73 return new MutableNumeric(getDouble()); 74 default: 75 throw new Error (); 76 } 77 } 78 79 80 long getMoney() throws Exception { 81 return Utils.doubleToMoney(getDouble()); 82 } 83 84 85 String getString() throws Exception { 86 if(isNull()) return null; 87 return getObject().toString(); 88 } 89 90 91 final int getDataType() { 92 return ExpressionArithmetic.getBestNumberDataType(param1.getDataType()); 93 } 94 95 96 97 98 } 99 | Popular Tags |