Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Thick-Common
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
潘栩锋
Thick-Common
Commits
26796810
Commit
26796810
authored
Jan 20, 2025
by
潘栩锋
🚴
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'remotes/origin/dev8.0-jinjiu' into dev8.0-blowing
parents
9eb4fbff
d258b479
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
45 deletions
+46
-45
SQLiteDbContext.cs
Project.SQLiteHelper/SQLiteHelper/SQLiteDbContext.cs
+2
-1
SQLiteHelper.cs
Project.SQLiteHelper/SQLiteHelper/SQLiteHelper.cs
+44
-44
No files found.
Project.SQLiteHelper/SQLiteHelper/SQLiteDbContext.cs
View file @
26796810
...
...
@@ -19,7 +19,8 @@ namespace SQLite
{
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"
;
...
...
Project.SQLiteHelper/SQLiteHelper/SQLiteHelper.cs
View file @
26796810
...
...
@@ -491,9 +491,9 @@ namespace SQLite
/// <returns></returns>
public
bool
QueryTran
(
IEnumerable
<
string
>
queryList
)
{
if
(
isHoldQueryTran
)
if
(
isHoldQueryTran
)
//打包模式
{
holdQueryList
.
AddRange
(
queryList
);
holdQueryList
.
AddRange
(
queryList
);
//记录SQLs
return
true
;
}
else
...
...
@@ -504,30 +504,29 @@ namespace SQLite
{
connection
.
Open
();
SQLiteTransaction
tran
=
connection
.
BeginTransaction
();
bool
check
=
false
;
try
using
(
SQLiteTransaction
tran
=
connection
.
BeginTransaction
())
{
foreach
(
string
item
in
queryList
)
bool
check
=
false
;
try
{
command
.
CommandText
=
item
;
command
.
ExecuteNonQuery
();
foreach
(
string
item
in
queryList
)
{
command
.
CommandText
=
item
;
command
.
ExecuteNonQuery
();
}
tran
.
Commit
();
//事务提交
check
=
true
;
//执行成功
}
tran
.
Commit
();
check
=
true
;
}
catch
(
Exception
ex
)
{
tran
.
Rollback
();
check
=
false
;
logger
.
Error
(
ex
,
Newtonsoft
.
Json
.
JsonConvert
.
SerializeObject
(
queryList
));
throw
ex
;
}
finally
{
connection
.
Close
();
catch
(
Exception
ex
)
{
//异常
tran
.
Rollback
();
//事务回滚
check
=
false
;
//执行失败
logger
.
Error
(
ex
,
Newtonsoft
.
Json
.
JsonConvert
.
SerializeObject
(
queryList
));
throw
ex
;
//抛出异常
}
return
check
;
}
return
check
;
}
}
}
...
...
@@ -564,35 +563,36 @@ namespace SQLite
{
connection
.
Open
();
SQLiteTransaction
tran
=
connection
.
BeginTransaction
();
bool
check
=
false
;
try
using
(
SQLiteTransaction
tran
=
connection
.
BeginTransaction
())
{
foreach
(
string
item
in
holdQueryList
)
bool
check
;
try
{
command
.
CommandText
=
item
;
command
.
ExecuteNonQuery
();
foreach
(
string
item
in
holdQueryList
)
//全部SQL 打包为一个事务执行
{
command
.
CommandText
=
item
;
command
.
ExecuteNonQuery
();
}
tran
.
Commit
();
//事务提交
check
=
true
;
//执行成功
}
tran
.
Commit
();
check
=
true
;
}
catch
(
Exception
ex
)
{
tran
.
Rollback
();
check
=
false
;
throw
ex
;
}
finally
{
holdQueryList
.
Clear
();
connection
.
Close
();
isHoldQueryTran
=
false
;
catch
(
Exception
ex
)
{
tran
.
Rollback
();
//异常出错,事务回滚
check
=
false
;
//执行失败
throw
ex
;
//弹出异常
}
finally
{
holdQueryList
.
Clear
();
//清除 SQL
isHoldQueryTran
=
false
;
//退出打包模式
}
return
check
;
}
return
check
;
}
}
}
isHoldQueryTran
=
false
;
isHoldQueryTran
=
false
;
//退出打包模式
return
true
;
}
/// <summary>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment