FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sqlpp11/tests/postgresql/usage/Returning.cpp at optional · rbock/sqlpp11 · GitHub
rbock
/
sqlpp11
Public
Notifications
You must be signed in to change notification settings
Fork
361
Star
2.6k
Code
Issues
2
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
sqlpp11
/
tests
/
postgresql
/
usage
/
Returning.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
70 lines (53 loc) · 2.09 KB
Breadcrumbs
sqlpp11
/
tests
/
postgresql
/
usage
/
Returning.cpp
Copy path
File metadata and controls
70 lines (53 loc) · 2.09 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
#
include
<
iostream
>
#
include
<
sqlpp11/postgresql/postgresql.h
>
#
include
<
sqlpp11/sqlpp11.h
>
#
include
"
../../include/test_helpers.h
"
#
include
"
TabFoo.h
"
#
include
"
make_test_connection.h
"
int
Returning
(
int
,
char
*[])
{
namespace
sql
=
sqlpp::postgresql;
sql::connection db =
sql::make_test_connection
();
model::TabFoo foo = {};
try
{
db.
execute
(
R"(
DROP TABLE IF EXISTS tabfoo;
)"
);
db.
execute
(
R"(
CREATE TABLE tabfoo
(
alpha bigserial NOT NULL,
beta smallint,
gamma text,
c_bool boolean,
c_timepoint timestamp with time zone DEFAULT now(),
c_day date
)
)"
);
std::cout
<<
db
(
sqlpp::postgresql::insert_into
(foo).
set
(foo.
gamma
=
"
dsa
"
).
returning
(foo.
c_timepoint
)).
front
().
c_timepoint
<< std::endl;
std::cout
<<
db
(
sqlpp::postgresql::insert_into
(foo).
set
(foo.
gamma
=
"
asd
"
).
returning
(
std::make_tuple
(foo.
c_timepoint
))).
front
().
c_timepoint
<< std::endl;
auto
i =
sqlpp::postgresql::dynamic_insert_into
(db, foo).
dynamic_set
().
returning
(foo.
c_timepoint
);
i.
insert_list
.
add
(foo.
gamma
=
"
blah
"
);
std::cout <<
db
(i).
front
().
c_timepoint
<< std::endl;
auto
updated =
db
(
sqlpp::postgresql::update
(foo).
set
(foo.
beta
=
0
).
unconditionally
().
returning
(foo.
gamma
, foo.
beta
));
for
(
const
auto
& row : updated)
std::cout <<
"
Gamma:
"
<< row.
gamma
<<
"
Beta:
"
<< row.
beta
<< std::endl;
auto
removed =
db
(
sqlpp::postgresql::remove_from
(foo).
where
(foo.
beta
==
0
).
returning
(foo.
gamma
, foo.
beta
));
for
(
const
auto
& row : removed)
std::cout <<
"
Gamma:
"
<< row.
gamma
<<
"
Beta:
"
<< row.
beta
<< std::endl;
auto
multi_insert =
sqlpp::postgresql::insert_into
(foo).
columns
(foo.
beta
).
returning
(foo.
alpha
, foo.
beta
);
multi_insert.
values
.
add
(foo.
beta
=
1
);
multi_insert.
values
.
add
(foo.
beta
=
2
);
auto
inserted =
db
(multi_insert);
for
(
const
auto
& row : inserted)
std::cout << row.
beta
<< std::endl;
}
catch
(
const
sql::failure&)
{
return
1
;
}
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL