You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "Knut Anders Hatlen (JIRA)" <ji...@apache.org> on 2010/04/20 15:34:50 UTC

[jira] Created: (DERBY-4621) Invalid conversion from Timestamp to String when calling setTimestamp() with Calendar

Invalid conversion from Timestamp to String when calling setTimestamp() with Calendar
-------------------------------------------------------------------------------------

                 Key: DERBY-4621
                 URL: https://issues.apache.org/jira/browse/DERBY-4621
             Project: Derby
          Issue Type: Bug
          Components: JDBC
    Affects Versions: 10.5.3.0
            Reporter: Knut Anders Hatlen


If you set a VARCHAR parameter with setTimestamp(), the string will be formatted differently depending on whether a Calendar is specified or not, even if the default calendar is used.

Take for example this statement:

    VALUES CAST(? AS VARCHAR(30))

I executed this statement twice with the same Timestamp instance. First like this:

    ps.setTimestamp(1, ts);

and then like this

    ps.setTimestamp(1, ts, Calendar.getInstance());

In this example, both of the methods should use the default Calendar to convert the timestamp to a string. However, I see that they generate different strings:

2010-04-20 15:17:36.0 vs 2010-04-20 03:17:36

Note there are two differences:

1) The method that takes a Calendar object does not show the fraction part (.0)

2) The method that takes a Calendar object is 12 hours off (03 instead of 15)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (DERBY-4621) Invalid conversion from Timestamp to String when calling setTimestamp() with Calendar

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-4621?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Knut Anders Hatlen updated DERBY-4621:
--------------------------------------

    Attachment: derby-4621.diff

The attached patch adds a regression test case to DateTimeTest and fixes the bug(s) in SQLChar.

The problems were

1) SQLChar.setValue(Timestamp,Calendar) used Timestamp.toString() if the calendar was null, but had its homegrown code to convert to a string if a calendar was specified. This code did not add the fraction part if it was zero. I added a special case for that.

2) SQLChar.formatJDBCTime(Calendar,StringBuffer) used Calendar.HOUR (which uses 12-hour clock) instead of Calendar.HOUR_OF_DAY (which uses 24-hour clock) to get the hour component of Time and Timestamp values. I corrected that.

Running the regression tests suites now.

> Invalid conversion from Timestamp to String when calling setTimestamp() with Calendar
> -------------------------------------------------------------------------------------
>
>                 Key: DERBY-4621
>                 URL: https://issues.apache.org/jira/browse/DERBY-4621
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.5.3.0
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>         Attachments: derby-4621.diff, TimestampToVarchar.java
>
>
> If you set a VARCHAR parameter with setTimestamp(), the string will be formatted differently depending on whether a Calendar is specified or not, even if the default calendar is used.
> Take for example this statement:
>     VALUES CAST(? AS VARCHAR(30))
> I executed this statement twice with the same Timestamp instance. First like this:
>     ps.setTimestamp(1, ts);
> and then like this
>     ps.setTimestamp(1, ts, Calendar.getInstance());
> In this example, both of the methods should use the default Calendar to convert the timestamp to a string. However, I see that they generate different strings:
> 2010-04-20 15:17:36.0 vs 2010-04-20 03:17:36
> Note there are two differences:
> 1) The method that takes a Calendar object does not show the fraction part (.0)
> 2) The method that takes a Calendar object is 12 hours off (03 instead of 15)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (DERBY-4621) Invalid conversion from Timestamp to String when calling setTimestamp() with Calendar

Posted by "Mamta A. Satoor (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-4621?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mamta A. Satoor resolved DERBY-4621.
------------------------------------

    Resolution: Fixed

Backport to 10.5 done

> Invalid conversion from Timestamp to String when calling setTimestamp() with Calendar
> -------------------------------------------------------------------------------------
>
>                 Key: DERBY-4621
>                 URL: https://issues.apache.org/jira/browse/DERBY-4621
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.5.3.0
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>             Fix For: 10.5.3.1, 10.6.1.0
>
>         Attachments: derby-4621.diff, TimestampToVarchar.java
>
>
> If you set a VARCHAR parameter with setTimestamp(), the string will be formatted differently depending on whether a Calendar is specified or not, even if the default calendar is used.
> Take for example this statement:
>     VALUES CAST(? AS VARCHAR(30))
> I executed this statement twice with the same Timestamp instance. First like this:
>     ps.setTimestamp(1, ts);
> and then like this
>     ps.setTimestamp(1, ts, Calendar.getInstance());
> In this example, both of the methods should use the default Calendar to convert the timestamp to a string. However, I see that they generate different strings:
> 2010-04-20 15:17:36.0 vs 2010-04-20 03:17:36
> Note there are two differences:
> 1) The method that takes a Calendar object does not show the fraction part (.0)
> 2) The method that takes a Calendar object is 12 hours off (03 instead of 15)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (DERBY-4621) Invalid conversion from Timestamp to String when calling setTimestamp() with Calendar

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-4621?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Knut Anders Hatlen updated DERBY-4621:
--------------------------------------

    Attachment: TimestampToVarchar.java

Attaching the file TimestampToVarchar.java which shows the problem with the two methods giving different results.

> Invalid conversion from Timestamp to String when calling setTimestamp() with Calendar
> -------------------------------------------------------------------------------------
>
>                 Key: DERBY-4621
>                 URL: https://issues.apache.org/jira/browse/DERBY-4621
>             Project: Derby
>          Issue Type: Bug
>          Components: JDBC
>    Affects Versions: 10.5.3.0
>            Reporter: Knut Anders Hatlen
>         Attachments: TimestampToVarchar.java
>
>
> If you set a VARCHAR parameter with setTimestamp(), the string will be formatted differently depending on whether a Calendar is specified or not, even if the default calendar is used.
> Take for example this statement:
>     VALUES CAST(? AS VARCHAR(30))
> I executed this statement twice with the same Timestamp instance. First like this:
>     ps.setTimestamp(1, ts);
> and then like this
>     ps.setTimestamp(1, ts, Calendar.getInstance());
> In this example, both of the methods should use the default Calendar to convert the timestamp to a string. However, I see that they generate different strings:
> 2010-04-20 15:17:36.0 vs 2010-04-20 03:17:36
> Note there are two differences:
> 1) The method that takes a Calendar object does not show the fraction part (.0)
> 2) The method that takes a Calendar object is 12 hours off (03 instead of 15)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (DERBY-4621) Invalid conversion from Timestamp to String when calling setTimestamp() with Calendar

Posted by "Mamta A. Satoor (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-4621?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mamta A. Satoor reassigned DERBY-4621:
--------------------------------------

    Assignee: Mamta A. Satoor  (was: Knut Anders Hatlen)

> Invalid conversion from Timestamp to String when calling setTimestamp() with Calendar
> -------------------------------------------------------------------------------------
>
>                 Key: DERBY-4621
>                 URL: https://issues.apache.org/jira/browse/DERBY-4621
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.5.3.0
>            Reporter: Knut Anders Hatlen
>            Assignee: Mamta A. Satoor
>             Fix For: 10.6.1.0
>
>         Attachments: derby-4621.diff, TimestampToVarchar.java
>
>
> If you set a VARCHAR parameter with setTimestamp(), the string will be formatted differently depending on whether a Calendar is specified or not, even if the default calendar is used.
> Take for example this statement:
>     VALUES CAST(? AS VARCHAR(30))
> I executed this statement twice with the same Timestamp instance. First like this:
>     ps.setTimestamp(1, ts);
> and then like this
>     ps.setTimestamp(1, ts, Calendar.getInstance());
> In this example, both of the methods should use the default Calendar to convert the timestamp to a string. However, I see that they generate different strings:
> 2010-04-20 15:17:36.0 vs 2010-04-20 03:17:36
> Note there are two differences:
> 1) The method that takes a Calendar object does not show the fraction part (.0)
> 2) The method that takes a Calendar object is 12 hours off (03 instead of 15)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (DERBY-4621) Invalid conversion from Timestamp to String when calling setTimestamp() with Calendar

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-4621?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Knut Anders Hatlen resolved DERBY-4621.
---------------------------------------

    Fix Version/s: 10.6.0.0
       Resolution: Fixed

All tests ran cleanly.
Committed revision 936215.

> Invalid conversion from Timestamp to String when calling setTimestamp() with Calendar
> -------------------------------------------------------------------------------------
>
>                 Key: DERBY-4621
>                 URL: https://issues.apache.org/jira/browse/DERBY-4621
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.5.3.0
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>             Fix For: 10.6.0.0
>
>         Attachments: derby-4621.diff, TimestampToVarchar.java
>
>
> If you set a VARCHAR parameter with setTimestamp(), the string will be formatted differently depending on whether a Calendar is specified or not, even if the default calendar is used.
> Take for example this statement:
>     VALUES CAST(? AS VARCHAR(30))
> I executed this statement twice with the same Timestamp instance. First like this:
>     ps.setTimestamp(1, ts);
> and then like this
>     ps.setTimestamp(1, ts, Calendar.getInstance());
> In this example, both of the methods should use the default Calendar to convert the timestamp to a string. However, I see that they generate different strings:
> 2010-04-20 15:17:36.0 vs 2010-04-20 03:17:36
> Note there are two differences:
> 1) The method that takes a Calendar object does not show the fraction part (.0)
> 2) The method that takes a Calendar object is 12 hours off (03 instead of 15)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (DERBY-4621) Invalid conversion from Timestamp to String when calling setTimestamp() with Calendar

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-4621?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Knut Anders Hatlen updated DERBY-4621:
--------------------------------------

            Assignee: Knut Anders Hatlen
    Issue & fix info: [Repro attached]

> Invalid conversion from Timestamp to String when calling setTimestamp() with Calendar
> -------------------------------------------------------------------------------------
>
>                 Key: DERBY-4621
>                 URL: https://issues.apache.org/jira/browse/DERBY-4621
>             Project: Derby
>          Issue Type: Bug
>          Components: JDBC
>    Affects Versions: 10.5.3.0
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>         Attachments: TimestampToVarchar.java
>
>
> If you set a VARCHAR parameter with setTimestamp(), the string will be formatted differently depending on whether a Calendar is specified or not, even if the default calendar is used.
> Take for example this statement:
>     VALUES CAST(? AS VARCHAR(30))
> I executed this statement twice with the same Timestamp instance. First like this:
>     ps.setTimestamp(1, ts);
> and then like this
>     ps.setTimestamp(1, ts, Calendar.getInstance());
> In this example, both of the methods should use the default Calendar to convert the timestamp to a string. However, I see that they generate different strings:
> 2010-04-20 15:17:36.0 vs 2010-04-20 03:17:36
> Note there are two differences:
> 1) The method that takes a Calendar object does not show the fraction part (.0)
> 2) The method that takes a Calendar object is 12 hours off (03 instead of 15)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (DERBY-4621) Invalid conversion from Timestamp to String when calling setTimestamp() with Calendar

Posted by "Mamta A. Satoor (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-4621?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mamta A. Satoor updated DERBY-4621:
-----------------------------------

         Assignee: Knut Anders Hatlen  (was: Mamta A. Satoor)
    Fix Version/s: 10.5.3.1

Finished the merge into 10.5 codeline

> Invalid conversion from Timestamp to String when calling setTimestamp() with Calendar
> -------------------------------------------------------------------------------------
>
>                 Key: DERBY-4621
>                 URL: https://issues.apache.org/jira/browse/DERBY-4621
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.5.3.0
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>             Fix For: 10.5.3.1, 10.6.1.0
>
>         Attachments: derby-4621.diff, TimestampToVarchar.java
>
>
> If you set a VARCHAR parameter with setTimestamp(), the string will be formatted differently depending on whether a Calendar is specified or not, even if the default calendar is used.
> Take for example this statement:
>     VALUES CAST(? AS VARCHAR(30))
> I executed this statement twice with the same Timestamp instance. First like this:
>     ps.setTimestamp(1, ts);
> and then like this
>     ps.setTimestamp(1, ts, Calendar.getInstance());
> In this example, both of the methods should use the default Calendar to convert the timestamp to a string. However, I see that they generate different strings:
> 2010-04-20 15:17:36.0 vs 2010-04-20 03:17:36
> Note there are two differences:
> 1) The method that takes a Calendar object does not show the fraction part (.0)
> 2) The method that takes a Calendar object is 12 hours off (03 instead of 15)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Reopened: (DERBY-4621) Invalid conversion from Timestamp to String when calling setTimestamp() with Calendar

Posted by "Kathey Marsden (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-4621?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Kathey Marsden reopened DERBY-4621:
-----------------------------------


reopen for 10.5 back port

> Invalid conversion from Timestamp to String when calling setTimestamp() with Calendar
> -------------------------------------------------------------------------------------
>
>                 Key: DERBY-4621
>                 URL: https://issues.apache.org/jira/browse/DERBY-4621
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.5.3.0
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>             Fix For: 10.6.1.0
>
>         Attachments: derby-4621.diff, TimestampToVarchar.java
>
>
> If you set a VARCHAR parameter with setTimestamp(), the string will be formatted differently depending on whether a Calendar is specified or not, even if the default calendar is used.
> Take for example this statement:
>     VALUES CAST(? AS VARCHAR(30))
> I executed this statement twice with the same Timestamp instance. First like this:
>     ps.setTimestamp(1, ts);
> and then like this
>     ps.setTimestamp(1, ts, Calendar.getInstance());
> In this example, both of the methods should use the default Calendar to convert the timestamp to a string. However, I see that they generate different strings:
> 2010-04-20 15:17:36.0 vs 2010-04-20 03:17:36
> Note there are two differences:
> 1) The method that takes a Calendar object does not show the fraction part (.0)
> 2) The method that takes a Calendar object is 12 hours off (03 instead of 15)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (DERBY-4621) Invalid conversion from Timestamp to String when calling setTimestamp() with Calendar

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-4621?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12858890#action_12858890 ] 

Knut Anders Hatlen commented on DERBY-4621:
-------------------------------------------

Time has the same problem with the 12 hours off.

> Invalid conversion from Timestamp to String when calling setTimestamp() with Calendar
> -------------------------------------------------------------------------------------
>
>                 Key: DERBY-4621
>                 URL: https://issues.apache.org/jira/browse/DERBY-4621
>             Project: Derby
>          Issue Type: Bug
>          Components: JDBC
>    Affects Versions: 10.5.3.0
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>         Attachments: TimestampToVarchar.java
>
>
> If you set a VARCHAR parameter with setTimestamp(), the string will be formatted differently depending on whether a Calendar is specified or not, even if the default calendar is used.
> Take for example this statement:
>     VALUES CAST(? AS VARCHAR(30))
> I executed this statement twice with the same Timestamp instance. First like this:
>     ps.setTimestamp(1, ts);
> and then like this
>     ps.setTimestamp(1, ts, Calendar.getInstance());
> In this example, both of the methods should use the default Calendar to convert the timestamp to a string. However, I see that they generate different strings:
> 2010-04-20 15:17:36.0 vs 2010-04-20 03:17:36
> Note there are two differences:
> 1) The method that takes a Calendar object does not show the fraction part (.0)
> 2) The method that takes a Calendar object is 12 hours off (03 instead of 15)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (DERBY-4621) Invalid conversion from Timestamp to String when calling setTimestamp() with Calendar

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-4621?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Knut Anders Hatlen updated DERBY-4621:
--------------------------------------

    Component/s: SQL
                     (was: JDBC)

Changing component from JDBC to SQL since the incorrect conversion appears to happen in the SQLChar class.

> Invalid conversion from Timestamp to String when calling setTimestamp() with Calendar
> -------------------------------------------------------------------------------------
>
>                 Key: DERBY-4621
>                 URL: https://issues.apache.org/jira/browse/DERBY-4621
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.5.3.0
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>         Attachments: TimestampToVarchar.java
>
>
> If you set a VARCHAR parameter with setTimestamp(), the string will be formatted differently depending on whether a Calendar is specified or not, even if the default calendar is used.
> Take for example this statement:
>     VALUES CAST(? AS VARCHAR(30))
> I executed this statement twice with the same Timestamp instance. First like this:
>     ps.setTimestamp(1, ts);
> and then like this
>     ps.setTimestamp(1, ts, Calendar.getInstance());
> In this example, both of the methods should use the default Calendar to convert the timestamp to a string. However, I see that they generate different strings:
> 2010-04-20 15:17:36.0 vs 2010-04-20 03:17:36
> Note there are two differences:
> 1) The method that takes a Calendar object does not show the fraction part (.0)
> 2) The method that takes a Calendar object is 12 hours off (03 instead of 15)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (DERBY-4621) Invalid conversion from Timestamp to String when calling setTimestamp() with Calendar

Posted by "Mamta A. Satoor (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-4621?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12885970#action_12885970 ] 

Mamta A. Satoor commented on DERBY-4621:
----------------------------------------

Will work on backporting this to 10.5

> Invalid conversion from Timestamp to String when calling setTimestamp() with Calendar
> -------------------------------------------------------------------------------------
>
>                 Key: DERBY-4621
>                 URL: https://issues.apache.org/jira/browse/DERBY-4621
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.5.3.0
>            Reporter: Knut Anders Hatlen
>            Assignee: Mamta A. Satoor
>             Fix For: 10.6.1.0
>
>         Attachments: derby-4621.diff, TimestampToVarchar.java
>
>
> If you set a VARCHAR parameter with setTimestamp(), the string will be formatted differently depending on whether a Calendar is specified or not, even if the default calendar is used.
> Take for example this statement:
>     VALUES CAST(? AS VARCHAR(30))
> I executed this statement twice with the same Timestamp instance. First like this:
>     ps.setTimestamp(1, ts);
> and then like this
>     ps.setTimestamp(1, ts, Calendar.getInstance());
> In this example, both of the methods should use the default Calendar to convert the timestamp to a string. However, I see that they generate different strings:
> 2010-04-20 15:17:36.0 vs 2010-04-20 03:17:36
> Note there are two differences:
> 1) The method that takes a Calendar object does not show the fraction part (.0)
> 2) The method that takes a Calendar object is 12 hours off (03 instead of 15)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.