Skip to content

Commit

Permalink
Add a mysql_session_timezone define to disable MySQL date functions
Browse files Browse the repository at this point in the history
  • Loading branch information
cedx authored Oct 26, 2023
2 parents 726a83a + 4de530a commit c940d97
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/tink/sql/drivers/MySql.hx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ private class MySqlSanitizer implements Sanitizer {
if (Std.is(v, Bool)) return v ? 'true' : 'false';
if (v == null || Std.is(v, Int)) return '$v';
if (Std.is(v, Bytes)) v = (cast v: Bytes).toString();
if (Std.is(v, Date)) return 'DATE_ADD(FROM_UNIXTIME(0), INTERVAL ${(v:Date).getTime()/1000} SECOND)';

if (Std.is(v, Date)) return
#if mysql_session_timezone string((v: Date).toString())
#else 'DATE_ADD(FROM_UNIXTIME(0), INTERVAL ${(v: Date).getTime() / 1000} SECOND)' #end;

return string('$v');
}

Expand Down
5 changes: 3 additions & 2 deletions src/tink/sql/drivers/node/MySql.hx
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ class MySqlConnection<Db> implements Connection<Db> implements Sanitizer {
}

public function value(v:Any):String {
if (Std.is(v, Date))
return 'DATE_ADD(FROM_UNIXTIME(0), INTERVAL ${(v : Date).getTime() / 1000} SECOND)';
if (Std.is(v, Date)) return
#if mysql_session_timezone NativeDriver.escape((v: Date).toString())
#else 'DATE_ADD(FROM_UNIXTIME(0), INTERVAL ${(v: Date).getTime() / 1000} SECOND)' #end;

if (Int64.isInt64(v))
return Int64.toStr(v);
Expand Down

0 comments on commit c940d97

Please sign in to comment.