Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-1371

PreparedStatement does not process Date type correctly

Rank to TopRank to BottomBulk Copy AttachmentsBulk Move AttachmentsVotersWatch issueWatchersConvert to sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.8.0
    • avatica-1.9.0
    • avatica
    • None

    Description

      I have problem when passing date parameter in PreparedStatement. Following is the sample code:
      TimeZone tzUtc = TimeZone.getTimeZone("UTC");
      Calendar cUtc = Calendar.getInstance(tzUtc);
      cUtc.set(2013, 10, 5, 0, 0, 0);
      java.sql.Date passSqlDate = new java.sql.Date(cUtc.getTimeInMillis());
      statement.setDate(1, passSqlDate, cUtc);
      I try to pass Date'2013/11/5' to the database, but from the debug info I found the
      database received '2013/10/4' (GMT -8 Timezone) always. It ignored the Calendar I passed in.

      There are some Calcite code a little strange, I have marked by color:
      Why setTimestamp and setTime have effective parameter 'calendar', but setDate ignore the
      parameter. Is that the root cause?
      AvaticaSite.java
      Line 189-199
      public void setTimestamp(Timestamp x, Calendar calendar)

      { slots[index] = wrap(ColumnMetaData.Rep.JAVA_SQL_TIMESTAMP, x, calendar); }

      public void setTime(Time x, Calendar calendar)

      { slots[index] = wrap(ColumnMetaData.Rep.JAVA_SQL_TIME, x, calendar); }

      public void setDate(Date x, Calendar cal)

      { slots[index] = wrap(ColumnMetaData.Rep.JAVA_SQL_DATE, x, calendar); }

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            yimingliu Billy Liu
            yimingliu Billy Liu
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment