diff options
Diffstat (limited to 'src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java')
-rw-r--r-- | src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java | 186 |
1 files changed, 99 insertions, 87 deletions
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java index 804d9a2c77..765fb46146 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java @@ -321,40 +321,40 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu wasNullFlag = (this_row[columnIndex - 1] == null); if (!wasNullFlag) { - if (binaryCursor) - { - //If the data is already binary then just return it - return this_row[columnIndex - 1]; - } - else if (connection.haveMinimumCompatibleVersion("7.2")) - { - //Version 7.2 supports the bytea datatype for byte arrays - if (fields[columnIndex - 1].getPGType().equals("bytea")) + if (binaryCursor) { - return PGbytea.toBytes(getString(columnIndex)); + //If the data is already binary then just return it + return this_row[columnIndex - 1]; } - else + else if (connection.haveMinimumCompatibleVersion("7.2")) { - return this_row[columnIndex - 1]; - } - } - else - { - //Version 7.1 and earlier supports LargeObjects for byte arrays - // Handle OID's as BLOBS - if ( fields[columnIndex - 1].getOID() == 26) - { - LargeObjectManager lom = connection.getLargeObjectAPI(); - LargeObject lob = lom.open(getInt(columnIndex)); - byte buf[] = lob.read(lob.size()); - lob.close(); - return buf; + //Version 7.2 supports the bytea datatype for byte arrays + if (fields[columnIndex - 1].getPGType().equals("bytea")) + { + return PGbytea.toBytes(getString(columnIndex)); + } + else + { + return this_row[columnIndex - 1]; + } } else { - return this_row[columnIndex - 1]; + //Version 7.1 and earlier supports LargeObjects for byte arrays + // Handle OID's as BLOBS + if ( fields[columnIndex - 1].getOID() == 26) + { + LargeObjectManager lom = connection.getLargeObjectAPI(); + LargeObject lob = lom.open(getInt(columnIndex)); + byte buf[] = lob.read(lob.size()); + lob.close(); + return buf; + } + else + { + return this_row[columnIndex - 1]; + } } - } } return null; } @@ -742,44 +742,44 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu switch (field.getSQLType()) { - case Types.BIT: - return new Boolean(getBoolean(columnIndex)); - case Types.SMALLINT: - return new Integer(getInt(columnIndex)); - case Types.INTEGER: - return new Integer(getInt(columnIndex)); - case Types.BIGINT: - return new Long(getLong(columnIndex)); - case Types.NUMERIC: - return getBigDecimal - (columnIndex, (field.getMod() == -1) ? -1 : ((field.getMod() - 4) & 0xffff)); - case Types.REAL: - return new Float(getFloat(columnIndex)); - case Types.DOUBLE: - return new Double(getDouble(columnIndex)); - case Types.CHAR: - case Types.VARCHAR: - return getString(columnIndex); - case Types.DATE: - return getDate(columnIndex); - case Types.TIME: - return getTime(columnIndex); - case Types.TIMESTAMP: - return getTimestamp(columnIndex); - case Types.BINARY: - case Types.VARBINARY: - return getBytes(columnIndex); - default: - String type = field.getPGType(); - // if the backend doesn't know the type then coerce to String - if (type.equals("unknown")) - { + case Types.BIT: + return new Boolean(getBoolean(columnIndex)); + case Types.SMALLINT: + return new Integer(getInt(columnIndex)); + case Types.INTEGER: + return new Integer(getInt(columnIndex)); + case Types.BIGINT: + return new Long(getLong(columnIndex)); + case Types.NUMERIC: + return getBigDecimal + (columnIndex, (field.getMod() == -1) ? -1 : ((field.getMod() - 4) & 0xffff)); + case Types.REAL: + return new Float(getFloat(columnIndex)); + case Types.DOUBLE: + return new Double(getDouble(columnIndex)); + case Types.CHAR: + case Types.VARCHAR: return getString(columnIndex); - } - else - { - return connection.getObject(field.getPGType(), getString(columnIndex)); - } + case Types.DATE: + return getDate(columnIndex); + case Types.TIME: + return getTime(columnIndex); + case Types.TIMESTAMP: + return getTimestamp(columnIndex); + case Types.BINARY: + case Types.VARBINARY: + return getBytes(columnIndex); + default: + String type = field.getPGType(); + // if the backend doesn't know the type then coerce to String + if (type.equals("unknown")) + { + return getString(columnIndex); + } + else + { + return connection.getObject(field.getPGType(), getString(columnIndex)); + } } } @@ -1082,7 +1082,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu if (current_row < 0 || current_row >= rows_size) return 0; - + return current_row + 1; } @@ -1565,10 +1565,13 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu return null; // length == 10: SQL Date // length > 10: SQL Timestamp, assumes PGDATESTYLE=ISO - try { - return java.sql.Date.valueOf((s.length() == 10) ? s : s.substring(0,10)); - } catch (NumberFormatException e) { - throw new PSQLException("postgresql.res.baddate", s); + try + { + return java.sql.Date.valueOf((s.length() == 10) ? s : s.substring(0, 10)); + } + catch (NumberFormatException e) + { + throw new PSQLException("postgresql.res.baddate", s); } } @@ -1578,10 +1581,13 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu return null; // SQL NULL // length == 8: SQL Time // length > 8: SQL Timestamp - try { - return java.sql.Time.valueOf((s.length() == 8) ? s : s.substring(11,19)); - } catch (NumberFormatException e) { - throw new PSQLException("postgresql.res.badtime",s); + try + { + return java.sql.Time.valueOf((s.length() == 8) ? s : s.substring(11, 19)); + } + catch (NumberFormatException e) + { + throw new PSQLException("postgresql.res.badtime", s); } } @@ -1628,7 +1634,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu char sub = resultSet.sbuf.charAt(resultSet.sbuf.length() - 3); if (sub == '+' || sub == '-') { - //we have found timezone info of format +/-HH + //we have found timezone info of format +/-HH resultSet.sbuf.setLength(resultSet.sbuf.length() - 3); if (subsecond) @@ -1639,22 +1645,28 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu { resultSet.sbuf.append("GMT").append(s.substring(s.length() - 3)).append(":00"); } - } else if (sub == ':') { - //we may have found timezone info of format +/-HH:MM, or there is no - //timezone info at all and this is the : preceding the seconds - char sub2 = resultSet.sbuf.charAt(resultSet.sbuf.length()-5); - if (sub2 == '+' || sub2 == '-') + } + else if (sub == ':') + { + //we may have found timezone info of format +/-HH:MM, or there is no + //timezone info at all and this is the : preceding the seconds + char sub2 = resultSet.sbuf.charAt(resultSet.sbuf.length() - 5); + if (sub2 == '+' || sub2 == '-') { - //we have found timezone info of format +/-HH:MM - resultSet.sbuf.setLength(resultSet.sbuf.length()-5); - if (subsecond) + //we have found timezone info of format +/-HH:MM + resultSet.sbuf.setLength(resultSet.sbuf.length() - 5); + if (subsecond) { - resultSet.sbuf.append('0').append("GMT").append(s.substring(s.length()-5)); - } else { - resultSet.sbuf.append("GMT").append(s.substring(s.length()-5)); + resultSet.sbuf.append('0').append("GMT").append(s.substring(s.length() - 5)); } - } else if (subsecond) { - resultSet.sbuf.append('0'); + else + { + resultSet.sbuf.append("GMT").append(s.substring(s.length() - 5)); + } + } + else if (subsecond) + { + resultSet.sbuf.append('0'); } } else if (subsecond) |