mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-24 18:55:04 +08:00
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:
parent
d013dbed75
commit
2843a13e51
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user