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
1676b45b
Commit
1676b45b
authored
Dec 26, 2020
by
潘栩锋
🚴
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加 BulkDbSQLite 的 只有 DbT 版本
parent
a7ee1e00
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
104 additions
and
0 deletions
+104
-0
BulkDbSQLite.cs
...ct.FLY.OBJComponents/OBJComponents/Server/BulkDbSQLite.cs
+104
-0
No files found.
Project.FLY.OBJComponents/OBJComponents/Server/BulkDbSQLite.cs
View file @
1676b45b
...
...
@@ -127,4 +127,108 @@ namespace FLY.OBJComponents.Server
asyncDelegate
(
asyncContext
,
reponse
);
}
}
public
class
BulkDbSQLite
<
TDb
>
:
IBulkDbSQLiteService
where
TDb
:
IDbBase
,
new
()
{
DBTable
<
TDb
>
dbTable
;
SQLiteHelper
sqliteHelper
;
public
long
LastId
{
get
;
private
set
;
}
public
event
PropertyChangedEventHandler
PropertyChanged
;
public
BulkDbSQLite
()
{
}
public
void
Init
(
DBTable
<
TDb
>
dbTable
)
{
this
.
dbTable
=
dbTable
;
this
.
sqliteHelper
=
dbTable
.
sqliteHelper
;
//获取最后一行数据
LastId
=
dbTable
.
MaxID
;
}
public
void
Add
(
TDb
lc
)
{
//添加 数据库必要的 field
lc
.
ID
=
dbTable
.
FreeID
;
//SQLs
List
<
string
>
sqls
=
new
List
<
string
>();
sqls
.
Add
(
SQLiteHelper
.
GetInsertCommandText
(
lc
));
sqliteHelper
.
QueryTranAsync
(
sqls
);
LastId
=
lc
.
ID
;
}
public
void
AddRange
(
IEnumerable
<
TDb
>
lcs
)
{
//SQLs
List
<
string
>
sqls
=
new
List
<
string
>();
foreach
(
var
lc
in
lcs
)
{
//添加 数据库必要的 field
lc
.
ID
=
dbTable
.
FreeID
;
sqls
.
Add
(
SQLiteHelper
.
GetInsertCommandText
(
lc
));
}
sqliteHelper
.
QueryTranAsync
(
sqls
);
LastId
=
lcs
.
Last
().
ID
;
}
public
async
void
GetTrend
(
Pack_GetTrendRequest
request
,
AsyncCBHandler
asyncDelegate
,
object
asyncContext
)
{
Pack_GetTrendReponse
<
TDb
>
reponse
=
new
Pack_GetTrendReponse
<
TDb
>();
reponse
.
Request
=
request
;
if
(
request
.
Count
>
400
)
//数量限制,避免死机
request
.
Count
=
400
;
else
if
(
request
.
Count
<
1
)
request
.
Count
=
1
;
if
(
request
.
Interval
<
1
)
//避免 /0
request
.
Interval
=
1
;
await
Task
.
Factory
.
StartNew
(()
=>
{
List
<
TDb
>
dbs
=
null
;
if
(!
request
.
IsSearchByTime
)
{
if
(
request
.
Id
<=
0
)
dbs
=
dbTable
.
Find
(
$"WHERE (ID %
{
request
.
Interval
}
= 0)"
+
$" ORDER BY ID DESC"
+
$" LIMIT
{
request
.
Count
}
OFFSET
{-
request
.
Id
}
"
);
else
dbs
=
dbTable
.
Find
(
$"WHERE (ID <=
{
request
.
Id
}
)"
+
$" AND (ID %
{
request
.
Interval
}
= 0)"
+
$" ORDER BY ID DESC"
+
$" LIMIT
{
request
.
Count
}
"
);
}
else
{
dbs
=
dbTable
.
Find
(
$"WHERE ( Time <=
{
request
.
Time
.
ToStringOfSQLiteFieldType
()}
)"
+
$" AND ( ID %
{
request
.
Interval
}
= 0)"
+
$" ORDER BY ID DESC"
+
$" LIMIT
{
request
.
Count
}
"
);
}
if
(
dbs
.
Count
()
==
0
)
return
;
//从尾向前排的!!!!
reponse
.
Values
=
dbs
;
});
asyncDelegate
(
asyncContext
,
reponse
);
}
}
}
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