2
2
// This software is subject to the terms of the Eclipse Public License v1.0
3
3
// Agreement, available at the following URL:
4
4
// http://www.eclipse.org/legal/epl-v10.html.
5
- // Copyright (C) 2007-2010 Julian Hyde
5
+ // Copyright (C) 2007-2011 Julian Hyde
6
6
// All Rights Reserved.
7
7
// You must accept the terms of that agreement to use this software.
8
8
*/
@@ -101,11 +101,15 @@ public boolean wasNull() throws SQLException {
101
101
}
102
102
103
103
public String getString (int columnIndex ) throws SQLException {
104
- return String .valueOf (getColumn (columnIndex - 1 ));
104
+ Object o = getColumn (columnIndex - 1 );
105
+ return o == null ? null : o .toString ();
105
106
}
106
107
107
108
public boolean getBoolean (int columnIndex ) throws SQLException {
108
109
Object o = getColumn (columnIndex - 1 );
110
+ if (o == null ) {
111
+ return false ;
112
+ }
109
113
if (o instanceof Boolean ) {
110
114
return (Boolean ) o ;
111
115
} else if (o instanceof String ) {
@@ -115,40 +119,81 @@ public boolean getBoolean(int columnIndex) throws SQLException {
115
119
}
116
120
}
117
121
122
+ private Number convertToNumber (Object o ) {
123
+ if (o instanceof Number ) {
124
+ return (Number )o ;
125
+ } else {
126
+ return new BigDecimal (o .toString ());
127
+ }
128
+ }
129
+
118
130
public byte getByte (int columnIndex ) throws SQLException {
119
131
Object o = getColumn (columnIndex - 1 );
120
- return ((Number ) o ).byteValue ();
132
+ if (o == null ) {
133
+ return 0 ;
134
+ }
135
+ return convertToNumber (o ).byteValue ();
121
136
}
122
137
123
138
public short getShort (int columnIndex ) throws SQLException {
124
139
Object o = getColumn (columnIndex - 1 );
125
- return ((Number ) o ).shortValue ();
140
+ if (o == null ) {
141
+ return 0 ;
142
+ }
143
+ return convertToNumber (o ).shortValue ();
126
144
}
127
145
128
146
public int getInt (int columnIndex ) throws SQLException {
129
147
Object o = getColumn (columnIndex - 1 );
130
- return ((Number ) o ).intValue ();
148
+ if (o == null ) {
149
+ return 0 ;
150
+ }
151
+ return convertToNumber (o ).intValue ();
131
152
}
132
153
133
154
public long getLong (int columnIndex ) throws SQLException {
134
155
Object o = getColumn (columnIndex - 1 );
156
+ if (o == null ) {
157
+ return 0 ;
158
+ }
135
159
return ((Number ) o ).longValue ();
136
160
}
137
161
138
162
public float getFloat (int columnIndex ) throws SQLException {
139
163
Object o = getColumn (columnIndex - 1 );
140
- return ((Number ) o ).floatValue ();
164
+ if (o == null ) {
165
+ return 0 ;
166
+ }
167
+ return convertToNumber (o ).floatValue ();
141
168
}
142
169
143
170
public double getDouble (int columnIndex ) throws SQLException {
144
171
Object o = getColumn (columnIndex - 1 );
145
- return ((Number ) o ).doubleValue ();
172
+ if (o == null ) {
173
+ return 0 ;
174
+ }
175
+ return convertToNumber (o ).doubleValue ();
146
176
}
147
177
148
178
public BigDecimal getBigDecimal (
149
- int columnIndex , int scale ) throws SQLException
179
+ int columnIndex ,
180
+ int scale )
181
+ throws SQLException
150
182
{
151
- throw new UnsupportedOperationException ();
183
+ Object o = getColumn (columnIndex - 1 );
184
+ if (o == null ) {
185
+ return null ;
186
+ }
187
+ BigDecimal bd ;
188
+ if (o instanceof BigDecimal ) {
189
+ bd = (BigDecimal )o ;
190
+ } else {
191
+ bd = new BigDecimal (o .toString ());
192
+ }
193
+ if (bd .scale () != scale ) {
194
+ bd = bd .setScale (scale );
195
+ }
196
+ return bd ;
152
197
}
153
198
154
199
public byte [] getBytes (int columnIndex ) throws SQLException {
@@ -185,7 +230,7 @@ public InputStream getBinaryStream(int columnIndex) throws SQLException {
185
230
186
231
public String getString (String columnLabel ) throws SQLException {
187
232
Object o = getColumn (columnLabel );
188
- return String . valueOf ( o );
233
+ return o == null ? null : o . toString ( );
189
234
}
190
235
191
236
public boolean getBoolean (String columnLabel ) throws SQLException {
@@ -201,38 +246,71 @@ public boolean getBoolean(String columnLabel) throws SQLException {
201
246
202
247
public byte getByte (String columnLabel ) throws SQLException {
203
248
Object o = getColumn (columnLabel );
204
- return ((Number ) o ).byteValue ();
249
+ if (o == null ) {
250
+ return 0 ;
251
+ }
252
+ return convertToNumber (o ).byteValue ();
205
253
}
206
254
207
255
public short getShort (String columnLabel ) throws SQLException {
208
256
Object o = getColumn (columnLabel );
209
- return ((Number ) o ).shortValue ();
257
+ if (o == null ) {
258
+ return 0 ;
259
+ }
260
+ return convertToNumber (o ).shortValue ();
210
261
}
211
262
212
263
public int getInt (String columnLabel ) throws SQLException {
213
264
Object o = getColumn (columnLabel );
214
- return ((Number ) o ).intValue ();
265
+ if (o == null ) {
266
+ return 0 ;
267
+ }
268
+ return convertToNumber (o ).intValue ();
215
269
}
216
270
217
271
public long getLong (String columnLabel ) throws SQLException {
218
272
Object o = getColumn (columnLabel );
219
- return ((Number ) o ).longValue ();
273
+ if (o == null ) {
274
+ return 0 ;
275
+ }
276
+ return convertToNumber (o ).longValue ();
220
277
}
221
278
222
279
public float getFloat (String columnLabel ) throws SQLException {
223
280
Object o = getColumn (columnLabel );
224
- return ((Number ) o ).floatValue ();
281
+ if (o == null ) {
282
+ return 0 ;
283
+ }
284
+ return convertToNumber (o ).floatValue ();
225
285
}
226
286
227
287
public double getDouble (String columnLabel ) throws SQLException {
228
288
Object o = getColumn (columnLabel );
229
- return ((Number ) o ).doubleValue ();
289
+ if (o == null ) {
290
+ return 0 ;
291
+ }
292
+ return convertToNumber (o ).doubleValue ();
230
293
}
231
294
232
295
public BigDecimal getBigDecimal (
233
- String columnLabel , int scale ) throws SQLException
296
+ String columnLabel ,
297
+ int scale )
298
+ throws SQLException
234
299
{
235
- throw new UnsupportedOperationException ();
300
+ Object o = getColumn (columnLabel );
301
+ if (o == null ) {
302
+ return null ;
303
+ }
304
+ BigDecimal bd ;
305
+ if (o instanceof BigDecimal ) {
306
+ bd = (BigDecimal )o ;
307
+ } else {
308
+ bd = new BigDecimal (o .toString ());
309
+ }
310
+ if (bd .scale () != scale ) {
311
+ bd = bd .setScale (scale );
312
+ }
313
+ return bd ;
236
314
}
237
315
238
316
public byte [] getBytes (String columnLabel ) throws SQLException {
@@ -286,15 +364,19 @@ public ResultSetMetaData getMetaData() throws SQLException {
286
364
}
287
365
288
366
public Object getObject (int columnIndex ) throws SQLException {
289
- throw new UnsupportedOperationException ( );
367
+ return getColumn ( columnIndex - 1 );
290
368
}
291
369
292
370
public Object getObject (String columnLabel ) throws SQLException {
293
- throw new UnsupportedOperationException ( );
371
+ return getColumn ( columnLabel );
294
372
}
295
373
296
374
public int findColumn (String columnLabel ) throws SQLException {
297
- throw new UnsupportedOperationException ();
375
+ int column = headerList .indexOf (columnLabel );
376
+ if (column < 0 ) {
377
+ throw new SQLException ("Column not found: " + columnLabel );
378
+ }
379
+ return column ;
298
380
}
299
381
300
382
public Reader getCharacterStream (int columnIndex ) throws SQLException {
@@ -306,11 +388,31 @@ public Reader getCharacterStream(String columnLabel) throws SQLException {
306
388
}
307
389
308
390
public BigDecimal getBigDecimal (int columnIndex ) throws SQLException {
309
- throw new UnsupportedOperationException ();
391
+ Object o = getColumn (columnIndex - 1 );
392
+ if (o == null ) {
393
+ return null ;
394
+ }
395
+ BigDecimal bd ;
396
+ if (o instanceof BigDecimal ) {
397
+ bd = (BigDecimal )o ;
398
+ } else {
399
+ bd = new BigDecimal (o .toString ());
400
+ }
401
+ return bd ;
310
402
}
311
403
312
404
public BigDecimal getBigDecimal (String columnLabel ) throws SQLException {
313
- throw new UnsupportedOperationException ();
405
+ Object o = getColumn (columnLabel );
406
+ if (o == null ) {
407
+ return null ;
408
+ }
409
+ BigDecimal bd ;
410
+ if (o instanceof BigDecimal ) {
411
+ bd = (BigDecimal )o ;
412
+ } else {
413
+ bd = new BigDecimal (o .toString ());
414
+ }
415
+ return bd ;
314
416
}
315
417
316
418
public boolean isBeforeFirst () throws SQLException {
0 commit comments