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

Commitd676e29

Browse files
author
Barry Lind
committed
fix bug in getTime() with fractional seconds reported by Laurette Cisneros (laurette@nextbus.com)
1 parent92a77cb commitd676e29

File tree

4 files changed

+56
-27
lines changed

4 files changed

+56
-27
lines changed

‎src/interfaces/jdbc/org/postgresql/Driver.java.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,6 @@ public class Driver implements java.sql.Driver
442442
}
443443

444444
//The build number should be incremented for every new build
445-
private static int m_buildNumber =100;
445+
private static int m_buildNumber =101;
446446

447447
}

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

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public boolean next() throws SQLException
108108
{
109109
if (rows ==null)
110110
thrownewPSQLException("postgresql.con.closed");
111-
111+
112112
if (++current_row >=rows.size())
113113
returnfalse;
114114
this_row = (byte [][])rows.elementAt(current_row);
@@ -468,30 +468,42 @@ public Time getTime(int columnIndex) throws SQLException
468468
{
469469
Strings =getString(columnIndex);
470470

471-
if (s !=null)
471+
if (s ==null)
472+
returnnull;// SQL NULL
473+
try
472474
{
473-
try
474-
{
475-
if (s.length() !=5 &&s.length() !=8)
476-
thrownewNumberFormatException("Wrong Length!");
477-
inthr =Integer.parseInt(s.substring(0,2));
478-
intmin =Integer.parseInt(s.substring(3,5));
479-
intsec = (s.length() ==5) ?0 :Integer.parseInt(s.substring(6));
480-
returnnewTime(hr,min,sec);
481-
}
482-
catch (NumberFormatExceptione)
483-
{
484-
thrownewPSQLException ("postgresql.res.badtime",s);
485-
}
475+
if (s.length() ==8) {
476+
//value is a time value
477+
returnjava.sql.Time.valueOf(s);
478+
}elseif (s.indexOf(".") ==8) {
479+
//value is a time value with fractional seconds
480+
java.sql.Timel_time =java.sql.Time.valueOf(s.substring(0,8));
481+
Stringl_strMillis =s.substring(9);
482+
if (l_strMillis.length() >3)
483+
l_strMillis =l_strMillis.substring(0,3);
484+
intl_millis =Integer.parseInt(l_strMillis);
485+
if (l_millis <10) {
486+
l_millis =l_millis *100;
487+
}elseif (l_millis <100) {
488+
l_millis =l_millis *10;
489+
}
490+
returnnewjava.sql.Time(l_time.getTime() +l_millis);
491+
}else {
492+
//value is a timestamp
493+
returnnewjava.sql.Time(getTimestamp(columnIndex).getTime());
494+
}
495+
}
496+
catch (NumberFormatExceptione)
497+
{
498+
thrownewPSQLException("postgresql.res.badtime",s);
486499
}
487-
returnnull;// SQL NULL
488500
}
489501

490502
/*
491503
* Get the value of a column in the current row as a
492504
* java.sql.Timestamp object
493505
*
494-
* The driver is set to return ISO date formated strings. We modify this
506+
* The driver is set to return ISO date formated strings. We modify this
495507
* string from the ISO format to a format that Java can understand. Java
496508
* expects timezone info as 'GMT+09:00' where as ISO gives '+09'.
497509
* Java also expects fractional seconds to 3 places where postgres
@@ -577,7 +589,7 @@ public Timestamp getTimestamp(int columnIndex) throws SQLException
577589
}
578590
elseif (slen ==19)
579591
{
580-
// No tz or fractional second info.
592+
// No tz or fractional second info.
581593
// if type is timestamptz then data is in GMT, else it is in local timezone
582594
if (fields[columnIndex -1].getPGType().equals("timestamptz")) {
583595
sbuf.append(" GMT");

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ public Object getArray(long index, int count, Map map) throws SQLException
7474
ObjectretVal =null;
7575

7676
ArrayListarray =newArrayList();
77-
77+
7878
/* Check if the String is also not an empty array
7979
* otherwise there will be an exception thrown below
8080
* in the ResultSet.toX with an empty string.
8181
* -- Doug Fields <dfields-pg-jdbc@pexicom.com> Feb 20, 2002 */
82-
82+
8383
if (rawString !=null && !rawString.equals("{}") )
8484
{
8585
char[]chars =rawString.toCharArray();
@@ -166,7 +166,7 @@ public Object getArray(long index, int count, Map map) throws SQLException
166166
caseTypes.TIME:
167167
retVal =newjava.sql.Time[count ];
168168
for ( ;count >0;count-- )
169-
((java.sql.Time[])retVal)[i++] =ResultSet.toTime(arrayContents[(int)index++] );
169+
((java.sql.Time[])retVal)[i++] =ResultSet.toTime(arrayContents[(int)index++],rs,getBaseTypeName() );
170170
break;
171171
caseTypes.TIMESTAMP:
172172
retVal =newTimestamp[count ];

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ public java.sql.Date getDate(int columnIndex) throws SQLException
388388
*/
389389
publicTimegetTime(intcolumnIndex)throwsSQLException
390390
{
391-
returntoTime(getString(columnIndex) );
391+
returntoTime(getString(columnIndex),this,fields[columnIndex-1].getPGType() );
392392
}
393393

394394
/*
@@ -1626,15 +1626,32 @@ public static java.sql.Date toDate(String s) throws SQLException
16261626
}
16271627
}
16281628

1629-
publicstaticTimetoTime(Strings)throwsSQLException
1629+
publicstaticTimetoTime(Strings,ResultSetresultSet,StringpgDataType)throwsSQLException
16301630
{
16311631
if (s ==null)
16321632
returnnull;// SQL NULL
1633-
// length == 8: SQL Time
1634-
// length > 8: SQL Timestamp
16351633
try
16361634
{
1637-
returnjava.sql.Time.valueOf((s.length() ==8) ?s :s.substring(11,19));
1635+
if (s.length() ==8) {
1636+
//value is a time value
1637+
returnjava.sql.Time.valueOf(s);
1638+
}elseif (s.indexOf(".") ==8) {
1639+
//value is a time value with fractional seconds
1640+
java.sql.Timel_time =java.sql.Time.valueOf(s.substring(0,8));
1641+
Stringl_strMillis =s.substring(9);
1642+
if (l_strMillis.length() >3)
1643+
l_strMillis =l_strMillis.substring(0,3);
1644+
intl_millis =Integer.parseInt(l_strMillis);
1645+
if (l_millis <10) {
1646+
l_millis =l_millis *100;
1647+
}elseif (l_millis <100) {
1648+
l_millis =l_millis *10;
1649+
}
1650+
returnnewjava.sql.Time(l_time.getTime() +l_millis);
1651+
}else {
1652+
//value is a timestamp
1653+
returnnewjava.sql.Time(toTimestamp(s,resultSet,pgDataType).getTime());
1654+
}
16381655
}
16391656
catch (NumberFormatExceptione)
16401657
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp