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

Commit8f83590

Browse files
author
Dave Cramer
committed
Patch from Ryouichi Matsuda
An attached patch corrects problem of this bug and fractional second. The handling of time zone was as follows: (a) with time zone using SimpleDateFormat("yyyy-MM-dd HH:mm:ss z") (b) without time zone using SimpleDateFormat("yyyy-MM-dd HH:mm:ss") About problem of fractional second, Fractional second was changed from milli-second to nano-second
1 parent7aa6270 commit8f83590

File tree

2 files changed

+51
-33
lines changed

2 files changed

+51
-33
lines changed

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

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,9 @@ public Timestamp getTimestamp(int columnIndex) throws SQLException
514514
StringBuffersbuf =newStringBuffer(s);
515515
SimpleDateFormatdf =null;
516516

517-
if (s.length() >19)
517+
intslen =s.length();
518+
519+
if (slen >19)
518520
{
519521
// The len of the ISO string to the second value is 19 chars. If
520522
// greater then 19, there should be tz info and perhaps fractional
@@ -534,7 +536,7 @@ public Timestamp getTimestamp(int columnIndex) throws SQLException
534536
if (i <24)
535537
sbuf.append(c);
536538
c =s.charAt(i++);
537-
}while (Character.isDigit(c));
539+
}while (i <slen &&Character.isDigit(c));
538540

539541
// If there wasn't at least 3 digits we should add some zeros
540542
// to make up the 3 digits we tell java to expect.
@@ -547,21 +549,28 @@ public Timestamp getTimestamp(int columnIndex) throws SQLException
547549
sbuf.append(".000");
548550
}
549551

550-
// prepend the GMT part and then add the remaining bit of
551-
// the string.
552-
sbuf.append(" GMT");
553-
sbuf.append(c);
554-
sbuf.append(s.substring(i,s.length()));
555-
556-
// Lastly, if the tz part doesn't specify the :MM part then
557-
// we add ":00" for java.
558-
if (s.length() -i <5)
559-
sbuf.append(":00");
560-
561-
// we'll use this dateformat string to parse the result.
562-
df =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z");
552+
if (i <slen)
553+
{
554+
// prepend the GMT part and then add the remaining bit of
555+
// the string.
556+
sbuf.append(" GMT");
557+
sbuf.append(c);
558+
sbuf.append(s.substring(i,slen));
559+
560+
// Lastly, if the tz part doesn't specify the :MM part then
561+
// we add ":00" for java.
562+
if (slen -i <5)
563+
sbuf.append(":00");
564+
565+
// we'll use this dateformat string to parse the result.
566+
df =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z");
567+
}
568+
else
569+
{
570+
df =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
571+
}
563572
}
564-
elseif (s.length() ==19)
573+
elseif (slen ==19)
565574
{
566575
// No tz or fractional second info.
567576
// I'm not sure if it is

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

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,11 +1630,12 @@ public static Timestamp toTimestamp(String s, ResultSet resultSet)
16301630

16311631
// Copy s into sbuf for parsing.
16321632
resultSet.sbuf.append(s);
1633+
intslen =s.length();
16331634

1634-
if (s.length() >19)
1635+
if (slen >19)
16351636
{
16361637
// The len of the ISO string to the second value is 19 chars. If
1637-
// greater then 19, thereshould be tz info and perhaps fractional
1638+
// greater then 19, theremay be tz info and perhaps fractional
16381639
// second info which we need to change to java to read it.
16391640

16401641
// cut the copy to second value "2001-12-07 16:29:22"
@@ -1651,7 +1652,7 @@ public static Timestamp toTimestamp(String s, ResultSet resultSet)
16511652
if (i <24)
16521653
resultSet.sbuf.append(c);
16531654
c =s.charAt(i++);
1654-
}while (Character.isDigit(c));
1655+
}while (i <slen &&Character.isDigit(c));
16551656

16561657
// If there wasn't at least 3 digits we should add some zeros
16571658
// to make up the 3 digits we tell java to expect.
@@ -1664,21 +1665,29 @@ public static Timestamp toTimestamp(String s, ResultSet resultSet)
16641665
resultSet.sbuf.append(".000");
16651666
}
16661667

1667-
// prepend the GMT part and then add the remaining bit of
1668-
// the string.
1669-
resultSet.sbuf.append(" GMT");
1670-
resultSet.sbuf.append(c);
1671-
resultSet.sbuf.append(s.substring(i,s.length()));
1672-
1673-
// Lastly, if the tz part doesn't specify the :MM part then
1674-
// we add ":00" for java.
1675-
if (s.length() -i <5)
1676-
resultSet.sbuf.append(":00");
1677-
1678-
// we'll use this dateformat string to parse the result.
1679-
df =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z");
1668+
if (i <slen)
1669+
{
1670+
// prepend the GMT part and then add the remaining bit of
1671+
// the string.
1672+
resultSet.sbuf.append(" GMT");
1673+
resultSet.sbuf.append(c);
1674+
resultSet.sbuf.append(s.substring(i,slen));
1675+
1676+
// Lastly, if the tz part doesn't specify the :MM part then
1677+
// we add ":00" for java.
1678+
if (slen -i <5)
1679+
resultSet.sbuf.append(":00");
1680+
1681+
// we'll use this dateformat string to parse the result.
1682+
df =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z");
1683+
}
1684+
else
1685+
{
1686+
// Just found fractional seconds but no timezone.
1687+
df =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
1688+
}
16801689
}
1681-
elseif (s.length() ==19)
1690+
elseif (slen ==19)
16821691
{
16831692
// No tz or fractional second info.
16841693
// I'm not sure if it is

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp