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

Commit2843a13

Browse files
author
Barry Lind
committed
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.
1 parentd013dbe commit2843a13

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,19 @@ public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException
388388
{
389389
SimpleDateFormatdf =newSimpleDateFormat("yyyy-MM-dd HH:mm:ss");
390390
df.setTimeZone(TimeZone.getTimeZone("GMT"));
391+
392+
// Make decimal from nanos.
393+
StringBufferdecimal =newStringBuffer("000000000");// max nanos length
394+
Stringnanos =String.valueOf(x.getNanos());
395+
decimal.setLength(decimal.length() -nanos.length());
396+
decimal.append(nanos);
397+
if (!connection.haveMinimumServerVersion("7.2")) {
398+
// Because 7.1 include bug that "hh:mm:59.999" becomes "hh:mm:60.00".
399+
decimal.setLength(2);
400+
}
401+
391402
StringBufferstrBuf =newStringBuffer("'");
392-
strBuf.append(df.format(x)).append('.').append(x.getNanos() /10000000).append("+00'");
403+
strBuf.append(df.format(x)).append('.').append(decimal).append("+00'");
393404
set(parameterIndex,strBuf.toString());
394405
}
395406
}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,11 +412,21 @@ public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException
412412
tl_tsdf.set(df);
413413
}
414414

415+
// Make decimal from nanos.
416+
StringBufferdecimal =newStringBuffer("000000000");// max nanos length
417+
Stringnanos =String.valueOf(x.getNanos());
418+
decimal.setLength(decimal.length() -nanos.length());
419+
decimal.append(nanos);
420+
if (!connection.haveMinimumServerVersion("7.2")) {
421+
// Because 7.1 include bug that "hh:mm:59.999" becomes "hh:mm:60.00".
422+
decimal.setLength(2);
423+
}
424+
415425
// Use the shared StringBuffer
416426
synchronized (sbuf)
417427
{
418428
sbuf.setLength(0);
419-
sbuf.append("'").append(df.format(x)).append('.').append(x.getNanos() /10000000).append("+00'");
429+
sbuf.append("'").append(df.format(x)).append('.').append(decimal).append("+00'");
420430
set(parameterIndex,sbuf.toString());
421431
}
422432

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp