Skip to content

Commit

Permalink
Fix bug 3152775, "EmptyResultSet bugs". (Patch contributed by sjoynt.)
Browse files Browse the repository at this point in the history
git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@397 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
julianhyde committed Jan 10, 2011
1 parent f741893 commit 8ceb0e5
Showing 1 changed file with 125 additions and 23 deletions.
148 changes: 125 additions & 23 deletions src/org/olap4j/driver/xmla/EmptyResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This software is subject to the terms of the Eclipse Public License v1.0
// Agreement, available at the following URL:
// http://www.eclipse.org/legal/epl-v10.html.
// Copyright (C) 2007-2010 Julian Hyde
// Copyright (C) 2007-2011 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand Down Expand Up @@ -101,11 +101,15 @@ public boolean wasNull() throws SQLException {
}

public String getString(int columnIndex) throws SQLException {
return String.valueOf(getColumn(columnIndex - 1));
Object o = getColumn(columnIndex - 1);
return o == null ? null : o.toString();
}

public boolean getBoolean(int columnIndex) throws SQLException {
Object o = getColumn(columnIndex - 1);
if (o == null) {
return false;
}
if (o instanceof Boolean) {
return (Boolean) o;
} else if (o instanceof String) {
Expand All @@ -115,40 +119,81 @@ public boolean getBoolean(int columnIndex) throws SQLException {
}
}

private Number convertToNumber(Object o) {
if (o instanceof Number) {
return (Number)o;
} else {
return new BigDecimal(o.toString());
}
}

public byte getByte(int columnIndex) throws SQLException {
Object o = getColumn(columnIndex - 1);
return ((Number) o).byteValue();
if (o == null) {
return 0;
}
return convertToNumber(o).byteValue();
}

public short getShort(int columnIndex) throws SQLException {
Object o = getColumn(columnIndex - 1);
return ((Number) o).shortValue();
if (o == null) {
return 0;
}
return convertToNumber(o).shortValue();
}

public int getInt(int columnIndex) throws SQLException {
Object o = getColumn(columnIndex - 1);
return ((Number) o).intValue();
if (o == null) {
return 0;
}
return convertToNumber(o).intValue();
}

public long getLong(int columnIndex) throws SQLException {
Object o = getColumn(columnIndex - 1);
if (o == null) {
return 0;
}
return ((Number) o).longValue();
}

public float getFloat(int columnIndex) throws SQLException {
Object o = getColumn(columnIndex - 1);
return ((Number) o).floatValue();
if (o == null) {
return 0;
}
return convertToNumber(o).floatValue();
}

public double getDouble(int columnIndex) throws SQLException {
Object o = getColumn(columnIndex - 1);
return ((Number) o).doubleValue();
if (o == null) {
return 0;
}
return convertToNumber(o).doubleValue();
}

public BigDecimal getBigDecimal(
int columnIndex, int scale) throws SQLException
int columnIndex,
int scale)
throws SQLException
{
throw new UnsupportedOperationException();
Object o = getColumn(columnIndex - 1);
if (o == null) {
return null;
}
BigDecimal bd;
if (o instanceof BigDecimal) {
bd = (BigDecimal)o;
} else {
bd = new BigDecimal(o.toString());
}
if (bd.scale() != scale) {
bd = bd.setScale(scale);
}
return bd;
}

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

public String getString(String columnLabel) throws SQLException {
Object o = getColumn(columnLabel);
return String.valueOf(o);
return o == null ? null : o.toString();
}

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

public byte getByte(String columnLabel) throws SQLException {
Object o = getColumn(columnLabel);
return ((Number) o).byteValue();
if (o == null) {
return 0;
}
return convertToNumber(o).byteValue();
}

public short getShort(String columnLabel) throws SQLException {
Object o = getColumn(columnLabel);
return ((Number) o).shortValue();
if (o == null) {
return 0;
}
return convertToNumber(o).shortValue();
}

public int getInt(String columnLabel) throws SQLException {
Object o = getColumn(columnLabel);
return ((Number) o).intValue();
if (o == null) {
return 0;
}
return convertToNumber(o).intValue();
}

public long getLong(String columnLabel) throws SQLException {
Object o = getColumn(columnLabel);
return ((Number) o).longValue();
if (o == null) {
return 0;
}
return convertToNumber(o).longValue();
}

public float getFloat(String columnLabel) throws SQLException {
Object o = getColumn(columnLabel);
return ((Number) o).floatValue();
if (o == null) {
return 0;
}
return convertToNumber(o).floatValue();
}

public double getDouble(String columnLabel) throws SQLException {
Object o = getColumn(columnLabel);
return ((Number) o).doubleValue();
if (o == null) {
return 0;
}
return convertToNumber(o).doubleValue();
}

public BigDecimal getBigDecimal(
String columnLabel, int scale) throws SQLException
String columnLabel,
int scale)
throws SQLException
{
throw new UnsupportedOperationException();
Object o = getColumn(columnLabel);
if (o == null) {
return null;
}
BigDecimal bd;
if (o instanceof BigDecimal) {
bd = (BigDecimal)o;
} else {
bd = new BigDecimal(o.toString());
}
if (bd.scale() != scale) {
bd = bd.setScale(scale);
}
return bd;
}

public byte[] getBytes(String columnLabel) throws SQLException {
Expand Down Expand Up @@ -286,15 +364,19 @@ public ResultSetMetaData getMetaData() throws SQLException {
}

public Object getObject(int columnIndex) throws SQLException {
throw new UnsupportedOperationException();
return getColumn(columnIndex - 1);
}

public Object getObject(String columnLabel) throws SQLException {
throw new UnsupportedOperationException();
return getColumn(columnLabel);
}

public int findColumn(String columnLabel) throws SQLException {
throw new UnsupportedOperationException();
int column = headerList.indexOf(columnLabel);
if (column < 0) {
throw new SQLException("Column not found: " + columnLabel);
}
return column;
}

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

public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
throw new UnsupportedOperationException();
Object o = getColumn(columnIndex - 1);
if (o == null) {
return null;
}
BigDecimal bd;
if (o instanceof BigDecimal) {
bd = (BigDecimal)o;
} else {
bd = new BigDecimal(o.toString());
}
return bd;
}

public BigDecimal getBigDecimal(String columnLabel) throws SQLException {
throw new UnsupportedOperationException();
Object o = getColumn(columnLabel);
if (o == null) {
return null;
}
BigDecimal bd;
if (o instanceof BigDecimal) {
bd = (BigDecimal)o;
} else {
bd = new BigDecimal(o.toString());
}
return bd;
}

public boolean isBeforeFirst() throws SQLException {
Expand Down

0 comments on commit 8ceb0e5

Please sign in to comment.