Also, if you could suggest a workaround I can use, it would be greatly 
appreciated


On Tuesday, 9 May 2017 16:45:45 UTC-4, Anthony Calce wrote:
>
> Hello,
>
> We are using a custom time converter (from Timestamp to joda DateTime), 
> using MARIADB.  The converter code is attached below.  We have discovered 
> the following bug:
>
>    - When inserting records into the DB, a DateTime object is provided
>    - If you apply breakpoints, you can see that the converter is doing 
>    the correct conversion (based off of millis)
>    - If you step thru the code up until the SQL is generated 
>    (DefaultBinding.toSQL()), you will see that it resolves as a string, 
>    similar to  *timestamp '2017-05-09 20:33:32.122'*
>    - The bug is that the date string which is fetched is grabbed from the 
>    Timestamp.toString() method... which is dependent on the java timezone 
> that 
>    is set.  The correct implementation should be to use something like 
>    *FROM_UNIXTIME(millis)*
>
> DefaultBinding trace point
>  else if (type == Timestamp.class) {
>
>                 // The SQLite JDBC driver does not implement the escape 
> syntax
>                 // [#1253] SQL Server and Sybase do not implement 
> timestamp literals
>                 if (asList(SQLITE).contains(family)) {
>                     render.sql('\'').sql(escape(val, render)).sql('\'');
>                 }
>
>                 // [#1253] Derby doesn't support the standard literal
>                 else if (family == DERBY) {
>                     render.keyword("timestamp('").sql(escape(val, 
> render)).sql("')");
>                 }
>
>                 // CUBRID timestamps have no fractional seconds
>                 else if (family == CUBRID) {
>                     render.keyword("datetime '").sql(escape(val, 
> render)).sql('\'');
>                 }
>
>                 // [#3648] Circumvent a MySQL bug related to date literals
>                 else if (family == MYSQL) {
>                     render.keyword("{ts '").sql(escape(val, 
> render)).sql("'}");
>                 }
>
>                 // Most dialects implement SQL standard timestamp literals
>                 else {
>                     *render.keyword("timestamp '").sql(escape(val, 
> render)).sql('\'');*
>                 }
>             }
>
>
>
>
> Converter code
> public static class TimestampConverter implements Converter<Timestamp, 
> DateTime> {
>         private static final long serialVersionUID = 1L;
>
>         @Override
>         public DateTime from(Timestamp x) {
>             try {
>                 if (x == null) {
>                     return null;
>                 }
>                 else {
>                     return new DateTime(x.getTime());
>                 }
>             }
>             catch (Exception e){
>                 return null;
>             }
>         }
>
>
>         @Override
>         public Class<Timestamp> fromType() {
>             return Timestamp.class;
>         }
>
>
>         @Override
>         public Timestamp to(DateTime x) {
>             try {
>                 if (x == null) {
>                     return null;
>                 }
>                 else {
>                     long milli = x.getMillis();
>                     Timestamp t = new Timestamp(milli); 
>                     return t;
>                 }
>             }
>             catch (Exception e){
>                 return null;
>             }
>         }
>
>
>         @Override
>         public Class<DateTime> toType() {
>             return DateTime.class;
>         }
>     }
>
>
>

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to