Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7a9ef7e

Browse files
author
Barry Lind
committed
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
1 parent3c879e3 commit7a9ef7e

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

‎src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,13 @@ public java.sql.Date getDate(int columnIndex) throws SQLException
445445
Strings =getString(columnIndex);
446446
if (s ==null)
447447
returnnull;
448-
returnjava.sql.Date.valueOf(s);
448+
// length == 10: SQL Date
449+
// length > 10: SQL Timestamp, assumes PGDATESTYLE=ISO
450+
try {
451+
returnjava.sql.Date.valueOf((s.length() ==10) ?s :s.substring(0,10));
452+
}catch (NumberFormatExceptione) {
453+
thrownewPSQLException("postgresql.res.baddate",s);
454+
}
449455
}
450456

451457
/**

‎src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,14 +1554,26 @@ public static java.sql.Date toDate(String s) throws SQLException
15541554
{
15551555
if (s ==null)
15561556
returnnull;
1557-
returnjava.sql.Date.valueOf(s);
1557+
// length == 10: SQL Date
1558+
// length > 10: SQL Timestamp, assumes PGDATESTYLE=ISO
1559+
try {
1560+
returnjava.sql.Date.valueOf((s.length() ==10) ?s :s.substring(0,10));
1561+
}catch (NumberFormatExceptione) {
1562+
thrownewPSQLException("postgresql.res.baddate",s);
1563+
}
15581564
}
15591565

15601566
publicstaticTimetoTime(Strings)throwsSQLException
15611567
{
15621568
if (s ==null)
15631569
returnnull;// SQL NULL
1564-
returnjava.sql.Time.valueOf(s);
1570+
// length == 8: SQL Time
1571+
// length > 8: SQL Timestamp
1572+
try {
1573+
returnjava.sql.Time.valueOf((s.length() ==8) ?s :s.substring(11,19));
1574+
}catch (NumberFormatExceptione) {
1575+
thrownewPSQLException("postgresql.res.badtime",s);
1576+
}
15651577
}
15661578

15671579
publicstaticTimestamptoTimestamp(Strings,ResultSetresultSet)throwsSQLException
@@ -1598,9 +1610,17 @@ public static Timestamp toTimestamp(String s, ResultSet resultSet) throws SQLExc
15981610
resultSet.sbuf.setLength(0);
15991611
resultSet.sbuf.append(s);
16001612

1613+
//we are looking to see if the backend has appended on a timezone.
1614+
//currently postgresql will return +/-HH:MM or +/-HH for timezone offset
1615+
//(i.e. -06, or +06:30, note the expectation of the leading zero for the
1616+
//hours, and the use of the : for delimiter between hours and minutes)
1617+
//if the backend ISO format changes in the future this code will
1618+
//need to be changed as well
16011619
charsub =resultSet.sbuf.charAt(resultSet.sbuf.length() -3);
16021620
if (sub =='+' ||sub =='-')
16031621
{
1622+
//we have found timezone info of format +/-HH
1623+
16041624
resultSet.sbuf.setLength(resultSet.sbuf.length() -3);
16051625
if (subsecond)
16061626
{
@@ -1610,6 +1630,23 @@ public static Timestamp toTimestamp(String s, ResultSet resultSet) throws SQLExc
16101630
{
16111631
resultSet.sbuf.append("GMT").append(s.substring(s.length() -3)).append(":00");
16121632
}
1633+
}elseif (sub ==':') {
1634+
//we may have found timezone info of format +/-HH:MM, or there is no
1635+
//timezone info at all and this is the : preceding the seconds
1636+
charsub2 =resultSet.sbuf.charAt(resultSet.sbuf.length()-5);
1637+
if (sub2 =='+' ||sub2 =='-')
1638+
{
1639+
//we have found timezone info of format +/-HH:MM
1640+
resultSet.sbuf.setLength(resultSet.sbuf.length()-5);
1641+
if (subsecond)
1642+
{
1643+
resultSet.sbuf.append('0').append("GMT").append(s.substring(s.length()-5));
1644+
}else {
1645+
resultSet.sbuf.append("GMT").append(s.substring(s.length()-5));
1646+
}
1647+
}elseif (subsecond) {
1648+
resultSet.sbuf.append('0');
1649+
}
16131650
}
16141651
elseif (subsecond)
16151652
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp