Applied patch submitted by Ryouichi Matsuda (r-matuda@sra.co.jp) that fixed a problem with leading zeros being lost on fractional seconds when setting a timestamp value on a PreparedStatement.

This commit is contained in:
Barry Lind 2002-01-15 07:37:33 +00:00
parent d013dbed75
commit 2843a13e51
2 changed files with 23 additions and 2 deletions

View File

@ -388,8 +388,19 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
{
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
df.setTimeZone(TimeZone.getTimeZone("GMT"));
// Make decimal from nanos.
StringBuffer decimal = new StringBuffer("000000000"); // max nanos length
String nanos = String.valueOf(x.getNanos());
decimal.setLength(decimal.length() - nanos.length());
decimal.append(nanos);
if (! connection.haveMinimumServerVersion("7.2")) {
// Because 7.1 include bug that "hh:mm:59.999" becomes "hh:mm:60.00".
decimal.setLength(2);
}
StringBuffer strBuf = new StringBuffer("'");
strBuf.append(df.format(x)).append('.').append(x.getNanos() / 10000000).append("+00'");
strBuf.append(df.format(x)).append('.').append(decimal).append("+00'");
set(parameterIndex, strBuf.toString());
}
}

View File

@ -412,11 +412,21 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
tl_tsdf.set(df);
}
// Make decimal from nanos.
StringBuffer decimal = new StringBuffer("000000000"); // max nanos length
String nanos = String.valueOf(x.getNanos());
decimal.setLength(decimal.length() - nanos.length());
decimal.append(nanos);
if (! connection.haveMinimumServerVersion("7.2")) {
// Because 7.1 include bug that "hh:mm:59.999" becomes "hh:mm:60.00".
decimal.setLength(2);
}
// Use the shared StringBuffer
synchronized (sbuf)
{
sbuf.setLength(0);
sbuf.append("'").append(df.format(x)).append('.').append(x.getNanos() / 10000000).append("+00'");
sbuf.append("'").append(df.format(x)).append('.').append(decimal).append("+00'");
set(parameterIndex, sbuf.toString());
}