From 4de530a8eaf8174d743c00a30fcb60ccb1f33890 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Belin?= Date: Thu, 26 Oct 2023 19:07:59 +0200 Subject: [PATCH] Add a `mysql_session_timezone` define to disable MySQL date functions --- src/tink/sql/drivers/MySql.hx | 6 +++++- src/tink/sql/drivers/node/MySql.hx | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/tink/sql/drivers/MySql.hx b/src/tink/sql/drivers/MySql.hx index fccc887..dd642ec 100644 --- a/src/tink/sql/drivers/MySql.hx +++ b/src/tink/sql/drivers/MySql.hx @@ -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'); } diff --git a/src/tink/sql/drivers/node/MySql.hx b/src/tink/sql/drivers/node/MySql.hx index 9bc5914..0f7c5e7 100755 --- a/src/tink/sql/drivers/node/MySql.hx +++ b/src/tink/sql/drivers/node/MySql.hx @@ -137,8 +137,9 @@ class MySqlConnection implements Connection 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);