提交 2843a13e 编写于 作者: B Barry Lind

Applied patch submitted by Ryouichi Matsuda (r-matuda@sra.co.jp) that fixed a...

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.
上级 d013dbed
...@@ -388,8 +388,19 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta ...@@ -388,8 +388,19 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
{ {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
df.setTimeZone(TimeZone.getTimeZone("GMT")); 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("'"); 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()); set(parameterIndex, strBuf.toString());
} }
} }
......
...@@ -412,11 +412,21 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta ...@@ -412,11 +412,21 @@ public class PreparedStatement extends Statement implements java.sql.PreparedSta
tl_tsdf.set(df); 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 // Use the shared StringBuffer
synchronized (sbuf) synchronized (sbuf)
{ {
sbuf.setLength(0); 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()); set(parameterIndex, sbuf.toString());
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册