| 1 | /* ============================================================= |
| 2 | * SmallSQL : a free Java DBMS library for the Java(tm) platform |
| 3 | * ============================================================= |
| 4 | * |
| 5 | * (C) Copyright 2004-2006, by Volker Berlin. |
| 6 | * |
| 7 | * Project Info: http://www.smallsql.de/ |
| 8 | * |
| 9 | * This library is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU Lesser General Public License as published by |
| 11 | * the Free Software Foundation; either version 2.1 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This library is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 16 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
| 17 | * License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Lesser General Public |
| 20 | * License along with this library; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
| 22 | * USA. |
| 23 | * |
| 24 | * [Java is a trademark or registered trademark of Sun Microsystems, Inc. |
| 25 | * in the United States and other countries.] |
| 26 | * |
| 27 | * --------------- |
| 28 | * ExpressionFunctionIIF.java |
| 29 | * --------------- |
| 30 | * Author: Volker Berlin |
| 31 | * |
| 32 | * Created on 11.04.2004 |
| 33 | */ |
| 34 | package smallsql.database; |
| 35 | |
| 36 | |
| 37 | /** |
| 38 | * @author Volker Berlin |
| 39 | */ |
| 40 | final class ExpressionFunctionIIF extends ExpressionFunction { |
| 41 | |
| 42 | |
| 43 | int getFunction() { |
| 44 | return SQLTokenizer.IIF; |
| 45 | } |
| 46 | |
| 47 | |
| 48 | boolean isNull() throws Exception { |
| 49 | if(param1.getBoolean()) |
| 50 | return param2.isNull(); |
| 51 | return param3.isNull(); |
| 52 | } |
| 53 | |
| 54 | |
| 55 | boolean getBoolean() throws Exception { |
| 56 | if(param1.getBoolean()) |
| 57 | return param2.getBoolean(); |
| 58 | return param3.getBoolean(); |
| 59 | } |
| 60 | |
| 61 | |
| 62 | int getInt() throws Exception { |
| 63 | if(param1.getBoolean()) |
| 64 | return param2.getInt(); |
| 65 | return param3.getInt(); |
| 66 | } |
| 67 | |
| 68 | |
| 69 | long getLong() throws Exception { |
| 70 | if(param1.getBoolean()) |
| 71 | return param2.getLong(); |
| 72 | return param3.getLong(); |
| 73 | } |
| 74 | |
| 75 | |
| 76 | float getFloat() throws Exception { |
| 77 | if(param1.getBoolean()) |
| 78 | return param2.getFloat(); |
| 79 | return param3.getFloat(); |
| 80 | } |
| 81 | |
| 82 | |
| 83 | double getDouble() throws Exception { |
| 84 | if(param1.getBoolean()) |
| 85 | return param2.getDouble(); |
| 86 | return param3.getDouble(); |
| 87 | } |
| 88 | |
| 89 | |
| 90 | long getMoney() throws Exception { |
| 91 | if(param1.getBoolean()) |
| 92 | return param2.getMoney(); |
| 93 | return param3.getMoney(); |
| 94 | } |
| 95 | |
| 96 | |
| 97 | MutableNumeric getNumeric() throws Exception { |
| 98 | if(param1.getBoolean()) |
| 99 | return param2.getNumeric(); |
| 100 | return param3.getNumeric(); |
| 101 | } |
| 102 | |
| 103 | |
| 104 | Object getObject() throws Exception { |
| 105 | if(param1.getBoolean()) |
| 106 | return param2.getObject(); |
| 107 | return param3.getObject(); |
| 108 | } |
| 109 | |
| 110 | |
| 111 | String getString() throws Exception { |
| 112 | if(param1.getBoolean()) |
| 113 | return param2.getString(); |
| 114 | return param3.getString(); |
| 115 | } |
| 116 | |
| 117 | |
| 118 | final int getDataType() { |
| 119 | return ExpressionArithmetic.getDataType(param2, param3); |
| 120 | } |
| 121 | |
| 122 | |
| 123 | final int getPrecision(){ |
| 124 | return Math.max( param2.getPrecision(), param3.getPrecision() ); |
| 125 | } |
| 126 | |
| 127 | |
| 128 | final int getScale(){ |
| 129 | return Math.max( param2.getScale(), param3.getScale() ); |
| 130 | } |
| 131 | |
| 132 | } |