Skip to content

Commit

Permalink
- 恢复 MySql ServerTime = Utc ;#1604 #1624
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed Sep 21, 2023
1 parent be6f2fa commit 9e3b258
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
7 changes: 6 additions & 1 deletion FreeSql/Internal/UtilsExpressionTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,14 @@ internal static TableInfo GetTableByEntity(Type entity, CommonUtils common)
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public override string TrimQuoteSqlName(string name)
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)
{
Expand Down
2 changes: 1 addition & 1 deletion Providers/FreeSql.Provider.MySql/MySqlUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public override string TrimQuoteSqlName(string name)
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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public override string TrimQuoteSqlName(string name)
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)
{
Expand Down
2 changes: 1 addition & 1 deletion Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public override string TrimQuoteSqlName(string name)
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)
{
Expand Down

0 comments on commit 9e3b258

Please sign in to comment.