Browse Source

Update mysql AddDefaultValue

pull/31/head
sunkaixuan 2 years ago
parent
commit
17cd6b8cd9
  1. 4
      Src/Asp.Net/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs
  2. 4
      Src/Asp.NetCore2/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs

4
Src/Asp.Net/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs

@ -560,10 +560,10 @@ namespace SqlSugar
{
defaultValue = "";
}
if (defaultValue.ToLower().IsIn("now()", "current_timestamp") || defaultValue.ToLower().Contains("current_timestamp"))
if (defaultValue.ToLower().IsIn("now()", "current_timestamp","null") || defaultValue.ToLower().Contains("current_timestamp")|| defaultValue.Contains("()"))
{
string template = "ALTER table {0} CHANGE COLUMN {1} {1} {3} {4} default {2} COMMENT '{5}'";
var dbColumnInfo = this.Context.DbMaintenance.GetColumnInfosByTableName(tableName).First(it => it.DbColumnName.Equals(columnName, StringComparison.CurrentCultureIgnoreCase));
var dbColumnInfo = this.Context.DbMaintenance.GetColumnInfosByTableName(tableName,false).First(it => it.DbColumnName.Equals(columnName, StringComparison.CurrentCultureIgnoreCase));
var value = Regex.Match(defaultValue, @"\(\d\)$").Value;
string sql = string.Format(template, tableName, columnName, defaultValue, dbColumnInfo.DataType + value, dbColumnInfo.IsNullable ? " NULL " : " NOT NULL ", dbColumnInfo.ColumnDescription);
this.Context.Ado.ExecuteCommand(sql);

4
Src/Asp.NetCore2/SqlSugar/Realization/MySql/DbMaintenance/MySqlDbMaintenance.cs

@ -561,10 +561,10 @@ namespace SqlSugar
{
defaultValue = "";
}
if (defaultValue.ToLower().IsIn("now()", "current_timestamp") || defaultValue.ToLower().Contains("current_timestamp"))
if (defaultValue.ToLower().IsIn("null","now()", "current_timestamp") || defaultValue.ToLower().Contains("current_timestamp")|| defaultValue.Contains("()"))
{
string template = "ALTER table {0} CHANGE COLUMN {1} {1} {3} {4} default {2} COMMENT '{5}'";
var dbColumnInfo = this.Context.DbMaintenance.GetColumnInfosByTableName(tableName).First(it => it.DbColumnName.Equals(columnName, StringComparison.CurrentCultureIgnoreCase));
var dbColumnInfo = this.Context.DbMaintenance.GetColumnInfosByTableName(tableName,false).First(it => it.DbColumnName.Equals(columnName, StringComparison.CurrentCultureIgnoreCase));
var value = Regex.Match(defaultValue, @"\(\d\)$").Value;
string sql = string.Format(template, tableName, columnName, defaultValue, dbColumnInfo.DataType + value, dbColumnInfo.IsNullable ? " NULL " : " NOT NULL ", dbColumnInfo.ColumnDescription);
this.Context.Ado.ExecuteCommand(sql);

Loading…
Cancel
Save