Skip to content

Commit 9e3b258

Browse files
committed
- 恢复 MySql ServerTime = Utc ;#1604 #1624
1 parent be6f2fa commit 9e3b258

File tree

5 files changed

+10
-5
lines changed

5 files changed

+10
-5
lines changed

FreeSql/Internal/UtilsExpressionTree.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,14 @@ internal static TableInfo GetTableByEntity(Type entity, CommonUtils common)
258258
commonNow = $"{commonNow.TrimEnd('(', ')')}({timeLength})";
259259
commonNowUtc = $"{commonNowUtc.TrimEnd('(', ')')}({timeLength})";
260260
}
261+
//https://github.com/dotnetcore/FreeSql/issues/1604 mysql 不支持默认值 utc_timestamp DDL
262+
if (colattr.ServerTime == DateTimeKind.Local)
263+
col.DbDefaultValue = commonNow;
264+
break;
265+
default:
266+
col.DbDefaultValue = colattr.ServerTime == DateTimeKind.Local ? commonNow : commonNowUtc;
261267
break;
262268
}
263-
col.DbDefaultValue = colattr.ServerTime == DateTimeKind.Local ? commonNow : commonNowUtc;
264269
col.DbInsertValue = colattr.ServerTime == DateTimeKind.Local ? commonNow : commonNowUtc;
265270
col.DbUpdateValue = colattr.ServerTime == DateTimeKind.Local ? commonNow : commonNowUtc;
266271
}

Providers/FreeSql.Provider.Custom/MySql/CustomMySqlUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public override string TrimQuoteSqlName(string name)
6868
public override string Mod(string left, string right, Type leftType, Type rightType) => $"{left} % {right}";
6969
public override string Div(string left, string right, Type leftType, Type rightType) => $"{left} div {right}";
7070
public override string Now => "now()";
71-
public override string NowUtc => "current_timestamp()";
71+
public override string NowUtc => "utc_timestamp()";
7272

7373
public override string QuoteWriteParamterAdapter(Type type, string paramterName)
7474
{

Providers/FreeSql.Provider.MySql/MySqlUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public override string TrimQuoteSqlName(string name)
100100
public override string Mod(string left, string right, Type leftType, Type rightType) => $"{left} % {right}";
101101
public override string Div(string left, string right, Type leftType, Type rightType) => $"{left} div {right}";
102102
public override string Now => "now()";
103-
public override string NowUtc => "current_timestamp()";
103+
public override string NowUtc => "utc_timestamp()";
104104

105105
public override string QuoteWriteParamterAdapter(Type type, string paramterName)
106106
{

Providers/FreeSql.Provider.MySqlConnector/MySqlConnectorUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public override string TrimQuoteSqlName(string name)
118118
public override string Mod(string left, string right, Type leftType, Type rightType) => $"{left} % {right}";
119119
public override string Div(string left, string right, Type leftType, Type rightType) => $"{left} div {right}";
120120
public override string Now => "now()";
121-
public override string NowUtc => "current_timestamp()";
121+
public override string NowUtc => "utc_timestamp()";
122122

123123
public override string QuoteWriteParamterAdapter(Type type, string paramterName)
124124
{

Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public override string TrimQuoteSqlName(string name)
6464
public override string Mod(string left, string right, Type leftType, Type rightType) => $"{left} % {right}";
6565
public override string Div(string left, string right, Type leftType, Type rightType) => $"{left} div {right}";
6666
public override string Now => "now()";
67-
public override string NowUtc => "current_timestamp()";
67+
public override string NowUtc => "utc_timestamp()";
6868

6969
public override string QuoteWriteParamterAdapter(Type type, string paramterName)
7070
{

0 commit comments

Comments
 (0)