fix bug in getTime() with fractional seconds reported by Laurette Cisneros (laurette@nextbus.com)
This commit is contained in:
parent
92a77cb870
commit
d676e29d41
|
@ -442,6 +442,6 @@ public class Driver implements java.sql.Driver
|
||||||
}
|
}
|
||||||
|
|
||||||
//The build number should be incremented for every new build
|
//The build number should be incremented for every new build
|
||||||
private static int m_buildNumber = 100;
|
private static int m_buildNumber = 101;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -468,24 +468,36 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
|
||||||
{
|
{
|
||||||
String s = getString(columnIndex);
|
String s = getString(columnIndex);
|
||||||
|
|
||||||
if (s != null)
|
if (s == null)
|
||||||
{
|
return null; // SQL NULL
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (s.length() != 5 && s.length() != 8)
|
if (s.length() == 8) {
|
||||||
throw new NumberFormatException("Wrong Length!");
|
//value is a time value
|
||||||
int hr = Integer.parseInt(s.substring(0, 2));
|
return java.sql.Time.valueOf(s);
|
||||||
int min = Integer.parseInt(s.substring(3, 5));
|
} else if (s.indexOf(".") == 8) {
|
||||||
int sec = (s.length() == 5) ? 0 : Integer.parseInt(s.substring(6));
|
//value is a time value with fractional seconds
|
||||||
return new Time(hr, min, sec);
|
java.sql.Time l_time = java.sql.Time.valueOf(s.substring(0,8));
|
||||||
|
String l_strMillis = s.substring(9);
|
||||||
|
if (l_strMillis.length() > 3)
|
||||||
|
l_strMillis = l_strMillis.substring(0,3);
|
||||||
|
int l_millis = Integer.parseInt(l_strMillis);
|
||||||
|
if (l_millis < 10) {
|
||||||
|
l_millis = l_millis * 100;
|
||||||
|
} else if (l_millis < 100) {
|
||||||
|
l_millis = l_millis * 10;
|
||||||
|
}
|
||||||
|
return new java.sql.Time(l_time.getTime() + l_millis);
|
||||||
|
} else {
|
||||||
|
//value is a timestamp
|
||||||
|
return new java.sql.Time(getTimestamp(columnIndex).getTime());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (NumberFormatException e)
|
catch (NumberFormatException e)
|
||||||
{
|
{
|
||||||
throw new PSQLException("postgresql.res.badtime", s);
|
throw new PSQLException("postgresql.res.badtime", s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null; // SQL NULL
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the value of a column in the current row as a
|
* Get the value of a column in the current row as a
|
||||||
|
|
|
@ -166,7 +166,7 @@ public class Array implements java.sql.Array
|
||||||
case Types.TIME:
|
case Types.TIME:
|
||||||
retVal = new java.sql.Time[ count ];
|
retVal = new java.sql.Time[ count ];
|
||||||
for ( ; count > 0; count-- )
|
for ( ; count > 0; count-- )
|
||||||
((java.sql.Time[])retVal)[i++] = ResultSet.toTime( arrayContents[(int)index++] );
|
((java.sql.Time[])retVal)[i++] = ResultSet.toTime( arrayContents[(int)index++], rs, getBaseTypeName() );
|
||||||
break;
|
break;
|
||||||
case Types.TIMESTAMP:
|
case Types.TIMESTAMP:
|
||||||
retVal = new Timestamp[ count ];
|
retVal = new Timestamp[ count ];
|
||||||
|
|
|
@ -388,7 +388,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
|
||||||
*/
|
*/
|
||||||
public Time getTime(int columnIndex) throws SQLException
|
public Time getTime(int columnIndex) throws SQLException
|
||||||
{
|
{
|
||||||
return toTime( getString(columnIndex) );
|
return toTime( getString(columnIndex), this, fields[columnIndex-1].getPGType() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1626,15 +1626,32 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Time toTime(String s) throws SQLException
|
public static Time toTime(String s, ResultSet resultSet, String pgDataType) throws SQLException
|
||||||
{
|
{
|
||||||
if (s == null)
|
if (s == null)
|
||||||
return null; // SQL NULL
|
return null; // SQL NULL
|
||||||
// length == 8: SQL Time
|
|
||||||
// length > 8: SQL Timestamp
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return java.sql.Time.valueOf((s.length() == 8) ? s : s.substring(11, 19));
|
if (s.length() == 8) {
|
||||||
|
//value is a time value
|
||||||
|
return java.sql.Time.valueOf(s);
|
||||||
|
} else if (s.indexOf(".") == 8) {
|
||||||
|
//value is a time value with fractional seconds
|
||||||
|
java.sql.Time l_time = java.sql.Time.valueOf(s.substring(0,8));
|
||||||
|
String l_strMillis = s.substring(9);
|
||||||
|
if (l_strMillis.length() > 3)
|
||||||
|
l_strMillis = l_strMillis.substring(0,3);
|
||||||
|
int l_millis = Integer.parseInt(l_strMillis);
|
||||||
|
if (l_millis < 10) {
|
||||||
|
l_millis = l_millis * 100;
|
||||||
|
} else if (l_millis < 100) {
|
||||||
|
l_millis = l_millis * 10;
|
||||||
|
}
|
||||||
|
return new java.sql.Time(l_time.getTime() + l_millis);
|
||||||
|
} else {
|
||||||
|
//value is a timestamp
|
||||||
|
return new java.sql.Time(toTimestamp(s, resultSet, pgDataType).getTime());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (NumberFormatException e)
|
catch (NumberFormatException e)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue