FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
qsqlbuilder/sqlbuilder/Inserter.cpp at master · MasterAler/qsqlbuilder · GitHub
MasterAler
/
qsqlbuilder
Public
Notifications
You must be signed in to change notification settings
Fork
5
Star
21
Code
Issues
1
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
qsqlbuilder
/
sqlbuilder
/
Inserter.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
79 lines (59 loc) · 1.94 KB
Breadcrumbs
qsqlbuilder
/
sqlbuilder
/
Inserter.cpp
Copy path
File metadata and controls
79 lines (59 loc) · 1.94 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#
include
"
Inserter.h
"
#
include
"
Query.h
"
#
include
"
Where.h
"
#
include
<
QSqlQuery
>
#
include
<
QSqlError
>
struct
Inserter
::InserterPrivate
{
InserterPrivate
(
const
Query* q,
const
QStringList& fields)
: m_query(q)
, m_fields(fields)
{}
const
Query* m_query;
const
QStringList m_fields;
QList<QVariantList> m_data;
};
/*
*************************************************************************************
*/
const
QString Inserter::
INSERT_SQL
{
"
INSERT INTO %1 %2 VALUES %3 RETURNING %4;
"
};
Inserter::Inserter
(
const
Query* q,
const
QStringList& fields)
: impl(
new
InserterPrivate(q, fields))
{ }
Inserter::~Inserter
()
{ }
Inserter::Inserter
(Inserter &&) = default;
InserterPerformer
Inserter::values
(
const
QVariantList& data) &&
{
return
InserterPerformer
(
std::move
(*
this
)).
values
(data);
}
/*
*************************************************************************************
*/
InserterPerformer::~InserterPerformer
()
{ }
InserterPerformer::InserterPerformer
(Inserter&& inserter)
: impl(std::move(inserter.impl))
{ }
InserterPerformer
InserterPerformer::values
(
const
QVariantList& data) &&
{
impl->
m_data
.
append
(data);
return
std::move
(*
this
);
}
QList<
int
>
InserterPerformer::perform
() &&
{
QList<
int
> result;
QStringList valueTail;
for
(
const
QVariantList& dataTuple : impl->
m_data
)
{
QStringList vBlock;
for
(
const
QVariant& value : dataTuple)
vBlock <<
OP::Clause::escapeValue
(value);
valueTail <<
QString
(
"
(%1)
"
).
arg
(vBlock.
join
(
'
,
'
));
}
const
QString sql = Inserter::
INSERT_SQL
.
arg
(impl->
m_query
->
tableName
())
.
arg
(
QString
(
"
(%1)
"
).
arg
(impl->
m_fields
.
join
(
'
,
'
)))
.
arg
(valueTail.
join
(
'
,
'
))
.
arg
(impl->
m_query
->
primaryKeyName
());
QSqlQuery q = impl->
m_query
->
performSQL
(sql);
while
(q.
next
())
result.
append
(q.
value
(
0
).
toInt
());
return
result;
}
Back
|
FazBrowse Home
|
New Git URL