Commit 26796810 authored by 潘栩锋's avatar 潘栩锋 🚴

Merge remote-tracking branch 'remotes/origin/dev8.0-jinjiu' into dev8.0-blowing

parents 9eb4fbff d258b479
...@@ -19,7 +19,8 @@ namespace SQLite ...@@ -19,7 +19,8 @@ namespace SQLite
{ {
get get
{ {
return string.Format("Data Source={0};Version=3;", DBPath); //超时100ms
return string.Format("Data Source={0};Version=3;BusyTimeout=100", DBPath);
} }
} }
public string DBPath { get; private set; } = @"test.sqlite3"; public string DBPath { get; private set; } = @"test.sqlite3";
......
...@@ -491,9 +491,9 @@ namespace SQLite ...@@ -491,9 +491,9 @@ namespace SQLite
/// <returns></returns> /// <returns></returns>
public bool QueryTran(IEnumerable<string> queryList) public bool QueryTran(IEnumerable<string> queryList)
{ {
if (isHoldQueryTran) if (isHoldQueryTran)//打包模式
{ {
holdQueryList.AddRange(queryList); holdQueryList.AddRange(queryList);//记录SQLs
return true; return true;
} }
else else
...@@ -504,30 +504,29 @@ namespace SQLite ...@@ -504,30 +504,29 @@ namespace SQLite
{ {
connection.Open(); connection.Open();
SQLiteTransaction tran = connection.BeginTransaction(); using (SQLiteTransaction tran = connection.BeginTransaction())
bool check = false;
try
{ {
foreach (string item in queryList) bool check = false;
try
{ {
command.CommandText = item; foreach (string item in queryList)
command.ExecuteNonQuery(); {
command.CommandText = item;
command.ExecuteNonQuery();
}
tran.Commit();//事务提交
check = true;//执行成功
} }
tran.Commit(); catch (Exception ex)
check = true; {
} //异常
catch (Exception ex) tran.Rollback();//事务回滚
{ check = false;//执行失败
tran.Rollback(); logger.Error(ex, Newtonsoft.Json.JsonConvert.SerializeObject(queryList));
check = false; throw ex;//抛出异常
logger.Error(ex, Newtonsoft.Json.JsonConvert.SerializeObject(queryList)); }
throw ex; return check;
}
finally
{
connection.Close();
} }
return check;
} }
} }
} }
...@@ -564,35 +563,36 @@ namespace SQLite ...@@ -564,35 +563,36 @@ namespace SQLite
{ {
connection.Open(); connection.Open();
SQLiteTransaction tran = connection.BeginTransaction(); using (SQLiteTransaction tran = connection.BeginTransaction())
bool check = false;
try
{ {
foreach (string item in holdQueryList) bool check;
try
{ {
command.CommandText = item; foreach (string item in holdQueryList)//全部SQL 打包为一个事务执行
command.ExecuteNonQuery(); {
command.CommandText = item;
command.ExecuteNonQuery();
}
tran.Commit();//事务提交
check = true;//执行成功
} }
tran.Commit(); catch (Exception ex)
check = true; {
} tran.Rollback();//异常出错,事务回滚
catch (Exception ex) check = false;//执行失败
{ throw ex;//弹出异常
tran.Rollback(); }
check = false; finally
throw ex; {
} holdQueryList.Clear();//清除 SQL
finally isHoldQueryTran = false;//退出打包模式
{ }
holdQueryList.Clear(); return check;
connection.Close();
isHoldQueryTran = false;
} }
return check;
} }
} }
} }
isHoldQueryTran = false; isHoldQueryTran = false;//退出打包模式
return true; return true;
} }
/// <summary> /// <summary>
......
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