You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2019/11/19 05:07:35 UTC

[GitHub] [incubator-shardingsphere] lightning-pro edited a comment on issue #3550: Timestamp miss milliseconds

lightning-pro edited a comment on issue #3550: Timestamp miss milliseconds
URL: https://github.com/apache/incubator-shardingsphere/issues/3550#issuecomment-555313811
 
 
   Well, the root cause is that in the Mysql jdbc PreparedStatement setTimestampInternal method,
   there is a checking
    this.serverSupportsFracSecs 
   
   which is to detect  the current connection agains the mysql's version 
   
   but when connect to the sharding-proxy, the response of the checking detectFractionalSecondsSupport is false . and BTW, my MySQL server is 5.7.25 version and the jdbc driver is 5.1.43
   
   ------below is the code in the MySQL driver PreparedStatement for your reference-----
   
   ```java
   protected void detectFractionalSecondsSupport() throws SQLException {
           this.serverSupportsFracSecs = this.connection != null && this.connection.versionMeetsMinimum(5, 6, 4);
       }
   
   private void setTimestampInternal(int parameterIndex, Timestamp x, Calendar targetCalendar, TimeZone tz, boolean rollForward) throws SQLException {
           if (x == null) {
               setNull(parameterIndex, java.sql.Types.TIMESTAMP);
           } else {
               checkClosed();
   
               if (!this.sendFractionalSeconds) {
                   x = TimeUtil.truncateFractionalSeconds(x);
               }
   
               if (!this.useLegacyDatetimeCode) {
                   newSetTimestampInternal(parameterIndex, x, targetCalendar);
               } else {
                   Calendar sessionCalendar = this.connection.getUseJDBCCompliantTimezoneShift() ? this.connection.getUtcCalendar()
                           : getCalendarInstanceForSessionOrNew();
   
                   x = TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, x, tz, this.connection.getServerTimezoneTZ(), rollForward);
   
                   if (this.connection.getUseSSPSCompatibleTimezoneShift()) {
                       doSSPSCompatibleTimezoneShift(parameterIndex, x);
                   } else {
                       synchronized (this) {
                           if (this.tsdf == null) {
                               this.tsdf = new SimpleDateFormat("''yyyy-MM-dd HH:mm:ss", Locale.US);
                           }
   
                           StringBuffer buf = new StringBuffer();
                           buf.append(this.tsdf.format(x));
   
                           if (this.serverSupportsFracSecs) {
                               int nanos = x.getNanos();
   
                               if (nanos != 0) {
                                   buf.append('.');
                                   buf.append(TimeUtil.formatNanos(nanos, this.serverSupportsFracSecs, true));
                               }
                           }
   
                           buf.append('\'');
   
                           setInternal(parameterIndex, buf.toString()); // SimpleDateFormat is not
                                                                       // thread-safe
                       }
                   }
               }
   
               this.parameterTypes[parameterIndex - 1 + getParameterIndexOffset()] = Types.TIMESTAMP;
           }
       }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services