mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
MySql RenameColumn BUG
This commit is contained in:
parent
583ad3279e
commit
6c360ffdc3
@ -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" />
|
||||
|
16
Src/Asp.Net/SqlServerTest/UnitTest/Updateable.cs
Normal file
16
Src/Asp.Net/SqlServerTest/UnitTest/Updateable.cs
Normal 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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user