Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-2928

LP:740958 - 5.1-micro can not handle prepared statements with timestamps involving nanoseconds

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Fixed
    • None
    • None
    • None

    Description

      5.1-micro can not handle prepared statements where a nanosecond-precision timestamp is sent to the server. Nanoseconds may be constructed by Java applications using the Timestamp class which operates in nanoseconds.

      Test case:

      import java.sql.Connection;
      import java.sql.DriverManager;
      import java.sql.ResultSet;
      import java.sql.ResultSetMetaData;
      import java.sql.Statement;
      import java.sql.PreparedStatement;
      import java.sql.Timestamp;
      import java.util.Calendar;

      class b5 {
              public static void main(String[] args) {
                      Connection conn;
                      try

      {                         Class.forName("com.mysql.jdbc.Driver").newInstance();                         String url = "jdbc:mysql://127.0.0.1:3306/test?traceProtocol=true&profileSQL=true";                         String userName = "test";                         String userPassword = "";                         conn = DriverManager.getConnection(url, userName, userPassword);                         Statement stmt = conn.createStatement();                         stmt.executeUpdate("DROP TABLE IF EXISTS t1");                         stmt.executeUpdate("CREATE TABLE IF NOT EXISTS t1 (t_id int(10), test_date timestamp NOT NULL,primary key t_pk (t_id));");                         stmt.executeUpdate("insert into t1 values (1,NOW());");                         PreparedStatement pstmt = ((com.mysql.jdbc.Connection) conn).serverPrepareStatement("UPDATE t1 SET test_date=ADDDATE( ? , INTERVAL 1 YEAR) WHERE t_id=1;");                         Timestamp ts = new Timestamp(System.currentTimeMillis());                         ts.setNanos(99999999);                         pstmt.setTimestamp(1, ts);                         System.out.println("Updated rows: " + pstmt.executeUpdate());                         ts.setNanos(999999999);                         pstmt.setTimestamp(1, ts);                         System.out.println("Timestamp is " + ts.toString());                         System.out.println("Updated rows: " + pstmt.executeUpdate());                 }

      catch (Exception e)

      {                         System.out.println("Exception: "+e);                         e.printStackTrace();                 }

              }
      }

      Attachments

        Activity

          People

            serg Sergei Golubchik
            philipstoev Philip Stoev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.