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
2c1358f2
Commit
2c1358f2
authored
Jul 28, 2021
by
潘栩锋
🚴
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化 SQLiteHelper 只有当有数据被删除时,才会数据库压缩
parent
2542c75e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
5 deletions
+10
-5
SQLiteDbContext.cs
Project.SQLiteHelper/SQLiteHelper/SQLiteDbContext.cs
+5
-3
SQLiteHelper.cs
Project.SQLiteHelper/SQLiteHelper/SQLiteHelper.cs
+5
-2
No files found.
Project.SQLiteHelper/SQLiteHelper/SQLiteDbContext.cs
View file @
2c1358f2
...
@@ -257,12 +257,14 @@ namespace SQLite
...
@@ -257,12 +257,14 @@ namespace SQLite
sqls
.
RemoveAll
(
sql
=>
sql
==
null
);
sqls
.
RemoveAll
(
sql
=>
sql
==
null
);
if
(
sqls
.
Count
==
0
)
if
(
sqls
.
Count
==
0
)
return
;
return
;
int
cnt
=
0
;
if
(
sqliteHelper
.
QueryTran
(
sqls
))
{
foreach
(
var
sql
in
sqls
)
{
cnt
+=
sqliteHelper
.
ExecuteNonQuery
(
sql
);
}
if
(
cnt
>
0
)
{
//数据库压缩
//数据库压缩
sqliteHelper
.
ExecuteNonQuery
(
"VACUUM"
);
sqliteHelper
.
ExecuteNonQuery
(
"VACUUM"
);
}
}
}
}
/// <summary>
/// <summary>
...
...
Project.SQLiteHelper/SQLiteHelper/SQLiteHelper.cs
View file @
2c1358f2
...
@@ -446,18 +446,21 @@ namespace SQLite
...
@@ -446,18 +446,21 @@ namespace SQLite
/// <param name="parameters">执行增删改语句所需要的参数,参数必须以它们在SQL语句中的顺序为准。</param>
/// <param name="parameters">执行增删改语句所需要的参数,参数必须以它们在SQL语句中的顺序为准。</param>
/// <returns></returns>
/// <returns></returns>
/// <exception cref="Exception"></exception>
/// <exception cref="Exception"></exception>
public
void
ExecuteNonQuery
(
string
sql
)
public
int
ExecuteNonQuery
(
string
sql
)
{
{
int
ret
=
0
;
using
(
SQLiteConnection
connection
=
new
SQLiteConnection
(
ConnectionString
))
using
(
SQLiteConnection
connection
=
new
SQLiteConnection
(
ConnectionString
))
{
{
using
(
SQLiteCommand
command
=
new
SQLiteCommand
(
connection
))
using
(
SQLiteCommand
command
=
new
SQLiteCommand
(
connection
))
{
{
connection
.
Open
();
connection
.
Open
();
command
.
CommandText
=
sql
;
command
.
CommandText
=
sql
;
command
.
ExecuteNonQuery
();
ret
=
command
.
ExecuteNonQuery
();
connection
.
Close
();
connection
.
Close
();
}
}
}
}
return
ret
;
}
}
...
...
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