]> granicus.if.org Git - postgresql/commitdiff
Applied patch submitted by Ryouichi Matsuda (r-matuda@sra.co.jp) that fixed a problem...
authorBarry Lind <barry@xythos.com>
Tue, 15 Jan 2002 07:37:33 +0000 (07:37 +0000)
committerBarry Lind <barry@xythos.com>
Tue, 15 Jan 2002 07:37:33 +0000 (07:37 +0000)
src/interfaces/jdbc/org/postgresql/jdbc1/PreparedStatement.java
src/interfaces/jdbc/org/postgresql/jdbc2/PreparedStatement.java

index 1da1da671153f349e4082955ff4eae70cc498430..31bbaf2eecec3128228693daeb0a15357f01fcb2 100644 (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());
                }
        }
index d5418bd1be7642970e4bbfbb6dcfc29c81944663..49c5f2da804e8eb72617e6a9f9e09af7ef252ee1 100644 (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());
                        }