MySql RenameColumn BUG

This commit is contained in:
sunkaixuan 2019-05-21 09:55:24 +08:00
parent 583ad3279e
commit 6c360ffdc3
3 changed files with 50 additions and 1 deletions

View File

@ -147,6 +147,7 @@
<Compile Include="OldTest\UnitTest\Update.cs" />
<Compile Include="Models\CarType.cs" />
<Compile Include="UnitTest\UAdo.cs" />
<Compile Include="UnitTest\Updateable.cs" />
<Compile Include="UnitTest\UQueryable.cs" />
<Compile Include="UnitTest\UQueryableAsync.cs" />
<Compile Include="UnitTest\UThread3.cs" />

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest
{
public class Updateable
{
public static void Init()
{
}
}
}

View File

@ -146,7 +146,7 @@ namespace SqlSugar
{
get
{
return "exec sp_rename '{0}.{1}','{2}','column';";
return "alter table {0} change column {1} {2}";
}
}
#endregion
@ -366,6 +366,38 @@ namespace SqlSugar
return dataSize;
}
public override bool RenameColumn(string tableName, string oldColumnName, string newColumnName)
{
var columns=GetColumnInfosByTableName(tableName).Where(it=>it.DbColumnName.Equals(oldColumnName,StringComparison.CurrentCultureIgnoreCase));
if (columns != null && columns.Any())
{
var column = columns.First();
var appendSql = " " + column.DataType;
if (column.Length > 0 && column.Scale == 0)
{
appendSql += string.Format("({0}) ", column.Length);
}
else if (column.Scale > 0 && column.Length > 0)
{
appendSql += string.Format("({0},{1}) ", column.Length, column.Scale);
}
else
{
appendSql += column.IsNullable ? " NULL" : "NOT NULL";
}
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
oldColumnName = this.SqlBuilder.GetTranslationColumnName(oldColumnName);
newColumnName = this.SqlBuilder.GetTranslationColumnName(newColumnName);
string sql = string.Format(this.RenameColumnSql, tableName, oldColumnName, newColumnName+appendSql);
this.Context.Ado.ExecuteCommand(sql);
return true;
}
else
{
return false;
}
}
public override bool IsAnyConstraint(string constraintName)
{
throw new NotSupportedException("MySql IsAnyConstraint NotSupportedException");