aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBarry Lind <barry@xythos.com>2001-11-12 19:59:46 +0000
committerBarry Lind <barry@xythos.com>2001-11-12 19:59:46 +0000
commit7a9ef7ee0945d6f5a35416fb4b9d99dd25aaab7f (patch)
tree94d2e96cdfaf4fc66b16aa957ebec64484239920 /src
parent3c879e373897b332877caac55e4aff97332cf887 (diff)
downloadpostgresql-7a9ef7ee0945d6f5a35416fb4b9d99dd25aaab7f.tar.gz
postgresql-7a9ef7ee0945d6f5a35416fb4b9d99dd25aaab7f.zip
fixed bug in ResultSet. Version 1.29 backed out two previous fixes (1.26 and 1.25). This checkin add back those two previous fixes. Problem reported by Daniel Germain
Diffstat (limited to 'src')
-rw-r--r--src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java8
-rw-r--r--src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java41
2 files changed, 46 insertions, 3 deletions
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java
index 07d5a998e64..348b84a657b 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java
@@ -445,7 +445,13 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
String s = getString(columnIndex);
if (s == null)
return null;
- return java.sql.Date.valueOf(s);
+ // 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);
+ }
}
/**
diff --git a/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java
index 4c2c61ce043..c5a64296245 100644
--- a/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java
+++ b/src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java
@@ -1554,14 +1554,26 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
{
if (s == null)
return null;
- return java.sql.Date.valueOf(s);
+ // 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);
+ }
}
public static Time toTime(String s) throws SQLException
{
if (s == null)
return null; // SQL NULL
- return java.sql.Time.valueOf(s);
+ // 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);
+ }
}
public static Timestamp toTimestamp(String s, ResultSet resultSet) throws SQLException
@@ -1598,9 +1610,17 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
resultSet.sbuf.setLength(0);
resultSet.sbuf.append(s);
+ //we are looking to see if the backend has appended on a timezone.
+ //currently postgresql will return +/-HH:MM or +/-HH for timezone offset
+ //(i.e. -06, or +06:30, note the expectation of the leading zero for the
+ //hours, and the use of the : for delimiter between hours and minutes)
+ //if the backend ISO format changes in the future this code will
+ //need to be changed as well
char sub = resultSet.sbuf.charAt(resultSet.sbuf.length() - 3);
if (sub == '+' || sub == '-')
{
+ //we have found timezone info of format +/-HH
+
resultSet.sbuf.setLength(resultSet.sbuf.length() - 3);
if (subsecond)
{
@@ -1610,6 +1630,23 @@ 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 == '-')
+ {
+ //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));
+ }
+ } else if (subsecond) {
+ resultSet.sbuf.append('0');
+ }
}
else if (subsecond)
{