Skip to content

Commit c940d97

Browse files
authored
Add a mysql_session_timezone define to disable MySQL date functions
2 parents 726a83a + 4de530a commit c940d97

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/tink/sql/drivers/MySql.hx

+5-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ private class MySqlSanitizer implements Sanitizer {
2929
if (Std.is(v, Bool)) return v ? 'true' : 'false';
3030
if (v == null || Std.is(v, Int)) return '$v';
3131
if (Std.is(v, Bytes)) v = (cast v: Bytes).toString();
32-
if (Std.is(v, Date)) return 'DATE_ADD(FROM_UNIXTIME(0), INTERVAL ${(v:Date).getTime()/1000} SECOND)';
32+
33+
if (Std.is(v, Date)) return
34+
#if mysql_session_timezone string((v: Date).toString())
35+
#else 'DATE_ADD(FROM_UNIXTIME(0), INTERVAL ${(v: Date).getTime() / 1000} SECOND)' #end;
36+
3337
return string('$v');
3438
}
3539

src/tink/sql/drivers/node/MySql.hx

+3-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ class MySqlConnection<Db> implements Connection<Db> implements Sanitizer {
137137
}
138138

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

143144
if (Int64.isInt64(v))
144145
return Int64.toStr(v);

0 commit comments

Comments
 (0)