From 9e3b258ffdbd6cdb3840810cf5eaab97ef658775 Mon Sep 17 00:00:00 2001 From: 2881099 <2881099@qq.com> Date: Thu, 21 Sep 2023 20:08:17 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E6=81=A2=E5=A4=8D=20MySql=20ServerTime=20?= =?UTF-8?q?=3D=20Utc=20=EF=BC=9B#1604=20#1624?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FreeSql/Internal/UtilsExpressionTree.cs | 7 ++++++- .../FreeSql.Provider.Custom/MySql/CustomMySqlUtils.cs | 2 +- Providers/FreeSql.Provider.MySql/MySqlUtils.cs | 2 +- .../FreeSql.Provider.MySqlConnector/MySqlConnectorUtils.cs | 2 +- Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlUtils.cs | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/FreeSql/Internal/UtilsExpressionTree.cs b/FreeSql/Internal/UtilsExpressionTree.cs index 38513aab..aa95c1cf 100644 --- a/FreeSql/Internal/UtilsExpressionTree.cs +++ b/FreeSql/Internal/UtilsExpressionTree.cs @@ -258,9 +258,14 @@ namespace FreeSql.Internal commonNow = $"{commonNow.TrimEnd('(', ')')}({timeLength})"; commonNowUtc = $"{commonNowUtc.TrimEnd('(', ')')}({timeLength})"; } + //https://github.com/dotnetcore/FreeSql/issues/1604 mysql 不支持默认值 utc_timestamp DDL + if (colattr.ServerTime == DateTimeKind.Local) + col.DbDefaultValue = commonNow; + break; + default: + col.DbDefaultValue = colattr.ServerTime == DateTimeKind.Local ? commonNow : commonNowUtc; break; } - col.DbDefaultValue = colattr.ServerTime == DateTimeKind.Local ? commonNow : commonNowUtc; col.DbInsertValue = colattr.ServerTime == DateTimeKind.Local ? commonNow : commonNowUtc; col.DbUpdateValue = colattr.ServerTime == DateTimeKind.Local ? commonNow : commonNowUtc; } diff --git a/Providers/FreeSql.Provider.Custom/MySql/CustomMySqlUtils.cs b/Providers/FreeSql.Provider.Custom/MySql/CustomMySqlUtils.cs index 41d81cf0..82db8cfc 100644 --- a/Providers/FreeSql.Provider.Custom/MySql/CustomMySqlUtils.cs +++ b/Providers/FreeSql.Provider.Custom/MySql/CustomMySqlUtils.cs @@ -68,7 +68,7 @@ namespace FreeSql.Custom.MySql public override string Mod(string left, string right, Type leftType, Type rightType) => $"{left} % {right}"; public override string Div(string left, string right, Type leftType, Type rightType) => $"{left} div {right}"; public override string Now => "now()"; - public override string NowUtc => "current_timestamp()"; + public override string NowUtc => "utc_timestamp()"; public override string QuoteWriteParamterAdapter(Type type, string paramterName) { diff --git a/Providers/FreeSql.Provider.MySql/MySqlUtils.cs b/Providers/FreeSql.Provider.MySql/MySqlUtils.cs index f8d17211..a1622cc6 100644 --- a/Providers/FreeSql.Provider.MySql/MySqlUtils.cs +++ b/Providers/FreeSql.Provider.MySql/MySqlUtils.cs @@ -100,7 +100,7 @@ namespace FreeSql.MySql public override string Mod(string left, string right, Type leftType, Type rightType) => $"{left} % {right}"; public override string Div(string left, string right, Type leftType, Type rightType) => $"{left} div {right}"; public override string Now => "now()"; - public override string NowUtc => "current_timestamp()"; + public override string NowUtc => "utc_timestamp()"; public override string QuoteWriteParamterAdapter(Type type, string paramterName) { diff --git a/Providers/FreeSql.Provider.MySqlConnector/MySqlConnectorUtils.cs b/Providers/FreeSql.Provider.MySqlConnector/MySqlConnectorUtils.cs index 27374291..ad08572d 100644 --- a/Providers/FreeSql.Provider.MySqlConnector/MySqlConnectorUtils.cs +++ b/Providers/FreeSql.Provider.MySqlConnector/MySqlConnectorUtils.cs @@ -118,7 +118,7 @@ namespace FreeSql.MySql public override string Mod(string left, string right, Type leftType, Type rightType) => $"{left} % {right}"; public override string Div(string left, string right, Type leftType, Type rightType) => $"{left} div {right}"; public override string Now => "now()"; - public override string NowUtc => "current_timestamp()"; + public override string NowUtc => "utc_timestamp()"; public override string QuoteWriteParamterAdapter(Type type, string paramterName) { diff --git a/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlUtils.cs b/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlUtils.cs index c451aeb2..d78f43ea 100644 --- a/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlUtils.cs +++ b/Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlUtils.cs @@ -64,7 +64,7 @@ namespace FreeSql.Odbc.MySql public override string Mod(string left, string right, Type leftType, Type rightType) => $"{left} % {right}"; public override string Div(string left, string right, Type leftType, Type rightType) => $"{left} div {right}"; public override string Now => "now()"; - public override string NowUtc => "current_timestamp()"; + public override string NowUtc => "utc_timestamp()"; public override string QuoteWriteParamterAdapter(Type type, string paramterName) {