Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8ceb0e5

Browse files
committedJan 10, 2011
Fix bug 3152775, "EmptyResultSet bugs". (Patch contributed by sjoynt.)
git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@397 c6a108a4-781c-0410-a6c6-c2d559e19af0
1 parent f741893 commit 8ceb0e5

File tree

1 file changed

+125
-23
lines changed

1 file changed

+125
-23
lines changed
 

‎src/org/olap4j/driver/xmla/EmptyResultSet.java

+125-23
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// This software is subject to the terms of the Eclipse Public License v1.0
33
// Agreement, available at the following URL:
44
// http://www.eclipse.org/legal/epl-v10.html.
5-
// Copyright (C) 2007-2010 Julian Hyde
5+
// Copyright (C) 2007-2011 Julian Hyde
66
// All Rights Reserved.
77
// You must accept the terms of that agreement to use this software.
88
*/
@@ -101,11 +101,15 @@ public boolean wasNull() throws SQLException {
101101
}
102102

103103
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();
105106
}
106107

107108
public boolean getBoolean(int columnIndex) throws SQLException {
108109
Object o = getColumn(columnIndex - 1);
110+
if (o == null) {
111+
return false;
112+
}
109113
if (o instanceof Boolean) {
110114
return (Boolean) o;
111115
} else if (o instanceof String) {
@@ -115,40 +119,81 @@ public boolean getBoolean(int columnIndex) throws SQLException {
115119
}
116120
}
117121

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+
118130
public byte getByte(int columnIndex) throws SQLException {
119131
Object o = getColumn(columnIndex - 1);
120-
return ((Number) o).byteValue();
132+
if (o == null) {
133+
return 0;
134+
}
135+
return convertToNumber(o).byteValue();
121136
}
122137

123138
public short getShort(int columnIndex) throws SQLException {
124139
Object o = getColumn(columnIndex - 1);
125-
return ((Number) o).shortValue();
140+
if (o == null) {
141+
return 0;
142+
}
143+
return convertToNumber(o).shortValue();
126144
}
127145

128146
public int getInt(int columnIndex) throws SQLException {
129147
Object o = getColumn(columnIndex - 1);
130-
return ((Number) o).intValue();
148+
if (o == null) {
149+
return 0;
150+
}
151+
return convertToNumber(o).intValue();
131152
}
132153

133154
public long getLong(int columnIndex) throws SQLException {
134155
Object o = getColumn(columnIndex - 1);
156+
if (o == null) {
157+
return 0;
158+
}
135159
return ((Number) o).longValue();
136160
}
137161

138162
public float getFloat(int columnIndex) throws SQLException {
139163
Object o = getColumn(columnIndex - 1);
140-
return ((Number) o).floatValue();
164+
if (o == null) {
165+
return 0;
166+
}
167+
return convertToNumber(o).floatValue();
141168
}
142169

143170
public double getDouble(int columnIndex) throws SQLException {
144171
Object o = getColumn(columnIndex - 1);
145-
return ((Number) o).doubleValue();
172+
if (o == null) {
173+
return 0;
174+
}
175+
return convertToNumber(o).doubleValue();
146176
}
147177

148178
public BigDecimal getBigDecimal(
149-
int columnIndex, int scale) throws SQLException
179+
int columnIndex,
180+
int scale)
181+
throws SQLException
150182
{
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;
152197
}
153198

154199
public byte[] getBytes(int columnIndex) throws SQLException {
@@ -185,7 +230,7 @@ public InputStream getBinaryStream(int columnIndex) throws SQLException {
185230

186231
public String getString(String columnLabel) throws SQLException {
187232
Object o = getColumn(columnLabel);
188-
return String.valueOf(o);
233+
return o == null ? null : o.toString();
189234
}
190235

191236
public boolean getBoolean(String columnLabel) throws SQLException {
@@ -201,38 +246,71 @@ public boolean getBoolean(String columnLabel) throws SQLException {
201246

202247
public byte getByte(String columnLabel) throws SQLException {
203248
Object o = getColumn(columnLabel);
204-
return ((Number) o).byteValue();
249+
if (o == null) {
250+
return 0;
251+
}
252+
return convertToNumber(o).byteValue();
205253
}
206254

207255
public short getShort(String columnLabel) throws SQLException {
208256
Object o = getColumn(columnLabel);
209-
return ((Number) o).shortValue();
257+
if (o == null) {
258+
return 0;
259+
}
260+
return convertToNumber(o).shortValue();
210261
}
211262

212263
public int getInt(String columnLabel) throws SQLException {
213264
Object o = getColumn(columnLabel);
214-
return ((Number) o).intValue();
265+
if (o == null) {
266+
return 0;
267+
}
268+
return convertToNumber(o).intValue();
215269
}
216270

217271
public long getLong(String columnLabel) throws SQLException {
218272
Object o = getColumn(columnLabel);
219-
return ((Number) o).longValue();
273+
if (o == null) {
274+
return 0;
275+
}
276+
return convertToNumber(o).longValue();
220277
}
221278

222279
public float getFloat(String columnLabel) throws SQLException {
223280
Object o = getColumn(columnLabel);
224-
return ((Number) o).floatValue();
281+
if (o == null) {
282+
return 0;
283+
}
284+
return convertToNumber(o).floatValue();
225285
}
226286

227287
public double getDouble(String columnLabel) throws SQLException {
228288
Object o = getColumn(columnLabel);
229-
return ((Number) o).doubleValue();
289+
if (o == null) {
290+
return 0;
291+
}
292+
return convertToNumber(o).doubleValue();
230293
}
231294

232295
public BigDecimal getBigDecimal(
233-
String columnLabel, int scale) throws SQLException
296+
String columnLabel,
297+
int scale)
298+
throws SQLException
234299
{
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;
236314
}
237315

238316
public byte[] getBytes(String columnLabel) throws SQLException {
@@ -286,15 +364,19 @@ public ResultSetMetaData getMetaData() throws SQLException {
286364
}
287365

288366
public Object getObject(int columnIndex) throws SQLException {
289-
throw new UnsupportedOperationException();
367+
return getColumn(columnIndex - 1);
290368
}
291369

292370
public Object getObject(String columnLabel) throws SQLException {
293-
throw new UnsupportedOperationException();
371+
return getColumn(columnLabel);
294372
}
295373

296374
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;
298380
}
299381

300382
public Reader getCharacterStream(int columnIndex) throws SQLException {
@@ -306,11 +388,31 @@ public Reader getCharacterStream(String columnLabel) throws SQLException {
306388
}
307389

308390
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;
310402
}
311403

312404
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;
314416
}
315417

316418
public boolean isBeforeFirst() throws SQLException {

0 commit comments

Comments
 (0)
Please sign in to comment.