Commit 2c1358f2 authored by 潘栩锋's avatar 潘栩锋 🚴

优化 SQLiteHelper 只有当有数据被删除时,才会数据库压缩

parent 2542c75e
......@@ -257,12 +257,14 @@ namespace SQLite
sqls.RemoveAll(sql => sql == null);
if (sqls.Count == 0)
return;
if (sqliteHelper.QueryTran(sqls)) {
int cnt = 0;
foreach (var sql in sqls) {
cnt += sqliteHelper.ExecuteNonQuery(sql);
}
if (cnt > 0) {
//数据库压缩
sqliteHelper.ExecuteNonQuery("VACUUM");
}
}
/// <summary>
......
......@@ -446,18 +446,21 @@ namespace SQLite
/// <param name="parameters">执行增删改语句所需要的参数,参数必须以它们在SQL语句中的顺序为准。</param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public void ExecuteNonQuery(string sql)
public int ExecuteNonQuery(string sql)
{
int ret = 0;
using (SQLiteConnection connection = new SQLiteConnection(ConnectionString))
{
using (SQLiteCommand command = new SQLiteCommand(connection))
{
connection.Open();
command.CommandText = sql;
command.ExecuteNonQuery();
ret = command.ExecuteNonQuery();
connection.Close();
}
}
return ret;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment