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 | * ExpressionFunctionReturnP1.java |
29 | * --------------- |
30 | * Author: Volker Berlin |
31 | * |
32 | * Created on 23.01.2005 |
33 | */ |
34 | package smallsql.database; |
35 | |
36 | /** |
37 | * Super Class for functions which extends the metadata from the first parameter. |
38 | * @author Volker Berlin |
39 | */ |
40 | abstract class ExpressionFunctionReturnP1 extends ExpressionFunction { |
41 | |
42 | |
43 | boolean isNull() throws Exception{ |
44 | return param1.isNull(); |
45 | } |
46 | |
47 | |
48 | Object getObject() throws Exception{ |
49 | if(isNull()) return null; |
50 | int dataType = getDataType(); |
51 | switch(dataType){ |
52 | case SQLTokenizer.BIT: |
53 | case SQLTokenizer.BOOLEAN: |
54 | return getBoolean() ? Boolean.TRUE : Boolean.FALSE; |
55 | case SQLTokenizer.BINARY: |
56 | case SQLTokenizer.VARBINARY: |
57 | return getBytes(); |
58 | case SQLTokenizer.TINYINT: |
59 | case SQLTokenizer.SMALLINT: |
60 | case SQLTokenizer.INT: |
61 | return new Integer( getInt() ); |
62 | case SQLTokenizer.BIGINT: |
63 | return new Long( getLong() ); |
64 | case SQLTokenizer.REAL: |
65 | return new Float( getFloat() ); |
66 | case SQLTokenizer.FLOAT: |
67 | case SQLTokenizer.DOUBLE: |
68 | return new Double( getDouble() ); |
69 | case SQLTokenizer.MONEY: |
70 | case SQLTokenizer.SMALLMONEY: |
71 | return Money.createFromUnscaledValue( getMoney() ); |
72 | case SQLTokenizer.NUMERIC: |
73 | case SQLTokenizer.DECIMAL: |
74 | return getNumeric(); |
75 | case SQLTokenizer.CHAR: |
76 | case SQLTokenizer.NCHAR: |
77 | case SQLTokenizer.VARCHAR: |
78 | case SQLTokenizer.NVARCHAR: |
79 | case SQLTokenizer.LONGNVARCHAR: |
80 | case SQLTokenizer.LONGVARCHAR: |
81 | return getString(); |
82 | case SQLTokenizer.LONGVARBINARY: |
83 | return getBytes(); |
84 | case SQLTokenizer.DATE: |
85 | case SQLTokenizer.TIME: |
86 | case SQLTokenizer.TIMESTAMP: |
87 | case SQLTokenizer.SMALLDATETIME: |
88 | return new DateTime( getLong(), dataType ); |
89 | case SQLTokenizer.UNIQUEIDENTIFIER: |
90 | return getBytes(); |
91 | default: throw createUnspportedDataType(param1.getDataType()); |
92 | } |
93 | } |
94 | |
95 | |
96 | int getDataType() { |
97 | return param1.getDataType(); |
98 | } |
99 | |
100 | |
101 | int getPrecision() { |
102 | return param1.getPrecision(); |
103 | } |
104 | |
105 | |
106 | final int getScale(){ |
107 | return param1.getScale(); |
108 | } |
109 | } |