mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-23 12:33:44 +08:00
Update sqlite update column
This commit is contained in:
@@ -257,6 +257,7 @@ namespace SqlSugar
|
|||||||
#region Methods
|
#region Methods
|
||||||
public override bool UpdateColumn(string tableName, DbColumnInfo column)
|
public override bool UpdateColumn(string tableName, DbColumnInfo column)
|
||||||
{
|
{
|
||||||
|
var isTran = this.Context.Ado.IsNoTran();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (column.IsPrimarykey)
|
if (column.IsPrimarykey)
|
||||||
@@ -264,8 +265,9 @@ namespace SqlSugar
|
|||||||
Check.ExceptionEasy("Sqlite no support alter column primary key","Sqlite不支持修改主键");
|
Check.ExceptionEasy("Sqlite no support alter column primary key","Sqlite不支持修改主键");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start a transaction
|
if (isTran)
|
||||||
this.Context.Ado.BeginTran();
|
// Start a transaction
|
||||||
|
this.Context.Ado.BeginTran();
|
||||||
|
|
||||||
tableName = tableName ?? column.TableName;
|
tableName = tableName ?? column.TableName;
|
||||||
var oldColumn = column.DbColumnName;
|
var oldColumn = column.DbColumnName;
|
||||||
@@ -291,15 +293,17 @@ namespace SqlSugar
|
|||||||
//Step 6: Drop the temporary column
|
//Step 6: Drop the temporary column
|
||||||
this.DropColumn(tableName, tempColumn);
|
this.DropColumn(tableName, tempColumn);
|
||||||
|
|
||||||
// Commit the transaction
|
if (isTran)
|
||||||
this.Context.Ado.CommitTran();
|
// Commit the transaction
|
||||||
|
this.Context.Ado.CommitTran();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
// Handle exceptions, log, or rollback the transaction if necessary
|
if (isTran)
|
||||||
this.Context.Ado.RollbackTran();
|
// Handle exceptions, log, or rollback the transaction if necessary
|
||||||
|
this.Context.Ado.RollbackTran();
|
||||||
// Log the exception or throw it again based on your requirements
|
// Log the exception or throw it again based on your requirements
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user