Update sqlite truncate table

This commit is contained in:
sunkaixuan
2022-05-24 20:00:18 +08:00
parent 5a2eca8781
commit c9a7dd7364
2 changed files with 22 additions and 4 deletions

View File

@@ -260,8 +260,17 @@ namespace SqlSugar
#region Methods #region Methods
public override bool TruncateTable(string tableName) public override bool TruncateTable(string tableName)
{ {
base.TruncateTable(tableName); base.TruncateTable(tableName);//delete data
return this.Context.Ado.ExecuteCommand($"UPDATE sqlite_sequence SET seq = 0 WHERE name = '{tableName}'") > 0; try
{
//clear sqlite identity
return this.Context.Ado.ExecuteCommand($"UPDATE sqlite_sequence SET seq = 0 WHERE name = '{tableName}'") > 0;
}
catch
{
//if no identity sqlite_sequence
return true;
}
} }
/// <summary> /// <summary>
///by current connection string ///by current connection string

View File

@@ -256,8 +256,17 @@ namespace SqlSugar
#region Methods #region Methods
public override bool TruncateTable(string tableName) public override bool TruncateTable(string tableName)
{ {
base.TruncateTable(tableName); base.TruncateTable(tableName);//delete data
return this.Context.Ado.ExecuteCommand($"UPDATE sqlite_sequence SET seq = 0 WHERE name = '{tableName}'") > 0; try
{
//clear sqlite identity
return this.Context.Ado.ExecuteCommand($"UPDATE sqlite_sequence SET seq = 0 WHERE name = '{tableName}'") > 0;
}
catch
{
//if no identity sqlite_sequence
return true;
}
} }
/// <summary> /// <summary>
///by current connection string ///by current connection string