FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sqlpp11/include/sqlpp11/offset.h at postgresql_remove_returning · 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
/
include
/
sqlpp11
/
offset.h
Copy path
More file actions
More file actions
Latest commit
History
History
History
332 lines (282 loc) · 9.84 KB
Breadcrumbs
sqlpp11
/
include
/
sqlpp11
/
offset.h
Copy path
File metadata and controls
332 lines (282 loc) · 9.84 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#
pragma
once
/*
* Copyright (c) 2013-2016, Roland Bock
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#
include
<
sqlpp11/detail/type_set.h
>
#
include
<
sqlpp11/policy_update.h
>
#
include
<
sqlpp11/type_traits.h
>
namespace
sqlpp
{
//
OFFSET DATA
template
<
typename
Offset>
struct
offset_data_t
{
offset_data_t
(Offset value) : _value(value)
{
}
offset_data_t
(
const
offset_data_t
&) =
default
;
offset_data_t
(
offset_data_t
&&) =
default
;
offset_data_t
&
operator
=(
const
offset_data_t
&) =
default
;
offset_data_t
&
operator
=(
offset_data_t
&&) =
default
;
~offset_data_t
() =
default
;
Offset _value;
};
//
OFFSET
template
<
typename
Offset>
struct
offset_t
{
using
_traits = make_traits<
no_value_t
, tag::is_offset>;
using
_nodes = detail::type_vector<Offset>;
//
Data
using
_data_t
=
offset_data_t
<Offset>;
//
Member implementation with data and methods
template
<
typename
Policies>
struct
_impl_t
{
//
workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069
_impl_t
() =
default
;
_impl_t
(
const
_data_t
& data) : _data(data)
{
}
_data_t
_data;
};
//
Base template to be inherited by the statement
template
<
typename
Policies>
struct
_base_t
{
using
_data_t
=
offset_data_t
<Offset>;
//
workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069
template
<
typename
... Args>
_base_t
(Args&&... args) : offset{std::forward<Args>(args)...}
{
}
_impl_t
<Policies> offset;
_impl_t
<Policies>&
operator
()()
{
return
offset;
}
const
_impl_t
<Policies>&
operator
()()
const
{
return
offset;
}
template
<
typename
T>
static
auto
_get_member
(T t) -> decltype(t.offset)
{
return
t.
offset
;
}
using
_consistency_check =
consistent_t
;
};
};
//
DYNAMIC OFFSET DATA
template
<
typename
Database>
struct
dynamic_offset_data_t
{
dynamic_offset_data_t
() : _value(noop())
{
}
template
<
typename
Offset>
dynamic_offset_data_t
(Offset value) : _initialized(
true
), _value(
wrap_operand_t
<Offset>(value))
{
}
dynamic_offset_data_t
(
const
dynamic_offset_data_t
&) =
default
;
dynamic_offset_data_t
(
dynamic_offset_data_t
&&) =
default
;
dynamic_offset_data_t
&
operator
=(
const
dynamic_offset_data_t
&) =
default
;
dynamic_offset_data_t
&
operator
=(
dynamic_offset_data_t
&&) =
default
;
~dynamic_offset_data_t
() =
default
;
bool
_initialized =
false
;
interpretable_t
<Database> _value;
};
//
DYNAMIC OFFSET
template
<
typename
Database>
struct
dynamic_offset_t
{
using
_traits = make_traits<
no_value_t
, tag::is_offset>;
using
_nodes = detail::type_vector<>;
//
Data
using
_data_t
=
dynamic_offset_data_t
<Database>;
//
Member implementation with data and methods
template
<
typename
Policies>
struct
_impl_t
{
//
workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069
_impl_t
() =
default
;
_impl_t
(
const
_data_t
& data) : _data(data)
{
}
template
<
typename
Offset>
void
set
(Offset value)
{
//
FIXME: Make sure that Offset does not require external tables? Need to read up on SQL
using
arg_t
=
wrap_operand_t
<Offset>;
static_assert
(
is_unsigned_integral_t
<
arg_t
>::value,
"
offset requires an unsigned integral value or unsigned integral parameter
"
);
_data.
_value
=
arg_t
{value};
_data.
_initialized
=
true
;
}
public:
_data_t
_data;
};
//
Base template to be inherited by the statement
template
<
typename
Policies>
struct
_base_t
{
using
_data_t
=
dynamic_offset_data_t
<Database>;
//
workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069
template
<
typename
... Args>
_base_t
(Args&&... args) : offset{std::forward<Args>(args)...}
{
}
_impl_t
<Policies> offset;
_impl_t
<Policies>&
operator
()()
{
return
offset;
}
const
_impl_t
<Policies>&
operator
()()
const
{
return
offset;
}
template
<
typename
T>
static
auto
_get_member
(T t) -> decltype(t.offset)
{
return
t.
offset
;
}
using
_consistency_check =
consistent_t
;
template
<
typename
Offset>
void
set_offset
(Offset value)
{
//
FIXME: Make sure that Offset does not require external tables? Need to read up on SQL
using
arg_t
=
wrap_operand_t
<Offset>;
static_cast
<
derived_statement_t
<Policies>*>(
this
)->
_offset
().
_value
=
arg_t
{value};
static_cast
<
derived_statement_t
<Policies>*>(
this
)->
_offset
().
_initialized
=
true
;
}
};
bool
_initialized =
false
;
interpretable_t
<Database> _value;
};
SQLPP_PORTABLE_STATIC_ASSERT
(assert_offset_is_unsigned_integral,
"
argument for offset() must be an integral expressions
"
);
template
<
typename
T>
struct
check_offset
{
using
type =
static_combined_check_t
<
static_check_t
<
is_unsigned_integral_t
<T>::value, assert_offset_is_unsigned_integral>>;
};
template
<
typename
T>
using
check_offset_t
=
typename
check_offset<
wrap_operand_t
<T>>::type;
struct
no_offset_t
{
using
_traits = make_traits<
no_value_t
, tag::is_noop>;
using
_nodes = detail::type_vector<>;
//
Data
using
_data_t
=
no_data_t
;
//
Member implementation with data and methods
template
<
typename
Policies>
struct
_impl_t
{
//
workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069
_impl_t
() =
default
;
_impl_t
(
const
_data_t
& data) : _data(data)
{
}
_data_t
_data;
};
//
Base template to be inherited by the statement
template
<
typename
Policies>
struct
_base_t
{
using
_data_t
=
no_data_t
;
//
workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2091069
template
<
typename
... Args>
_base_t
(Args&&... args) : no_offset{std::forward<Args>(args)...}
{
}
_impl_t
<Policies> no_offset;
_impl_t
<Policies>&
operator
()()
{
return
no_offset;
}
const
_impl_t
<Policies>&
operator
()()
const
{
return
no_offset;
}
template
<
typename
T>
static
auto
_get_member
(T t) -> decltype(t.no_offset)
{
return
t.
no_offset
;
}
using
_database_t
=
typename
Policies::
_database_t
;
template
<
typename
Check,
typename
T>
using
_new_statement_t
=
new_statement_t
<Check, Policies,
no_offset_t
, T>;
using
_consistency_check =
consistent_t
;
template
<
typename
Arg>
auto
offset
(Arg arg)
const
-> _new_statement_t<check_offset_t<Arg>, offset_t<wrap_operand_t<Arg>>>
{
return
_offset_impl
(
check_offset_t
<Arg>{},
wrap_operand_t
<Arg>{arg});
}
auto
dynamic_offset
()
const
-> _new_statement_t<consistent_t, dynamic_offset_t<_database_t>>
{
static_assert
(
not
std::is_same<
_database_t
,
void
>::value,
"
dynamic_offset must not be called in a static statement
"
);
return
{
static_cast
<
const
derived_statement_t
<Policies>&>(*
this
),
dynamic_offset_data_t
<
_database_t
>{}};
}
private:
template
<
typename
Check,
typename
Arg>
auto
_offset_impl
(Check, Arg arg)
const
-> inconsistent<Check>;
template
<
typename
Arg>
auto
_offset_impl
(
consistent_t
/*
unused
*/
, Arg arg)
const
-> _new_statement_t<consistent_t, offset_t<Arg>>
{
return
{
static_cast
<
const
derived_statement_t
<Policies>&>(*
this
),
offset_data_t
<Arg>{arg}};
}
};
};
//
Interpreters
template
<
typename
Context,
typename
Offset>
Context&
serialize
(
const
offset_data_t
<Offset>& t, Context& context)
{
context <<
"
OFFSET
"
;
serialize_operand
(t.
_value
, context);
return
context;
}
template
<
typename
Context,
typename
Database>
Context&
serialize
(
const
dynamic_offset_data_t
<Database>& t, Context& context)
{
if
(t.
_initialized
)
{
context <<
"
OFFSET
"
;
serialize
(t.
_value
, context);
}
return
context;
}
template
<
typename
T>
auto
offset
(T&& t) -> decltype(
statement_t
<
void
,
no_offset_t
>().offset(std::forward<T>(t)))
{
return
statement_t
<
void
,
no_offset_t
>().
offset
(std::forward<T>(t));
}
template
<
typename
Database>
auto
dynamic_offset
(
const
Database &
/*
unused
*/
) -> decltype(
statement_t
<Database,
no_offset_t
>().dynamic_offset())
{
return
statement_t
<Database,
no_offset_t
>().
dynamic_offset
();
}
}
//
namespace sqlpp
Back
|
FazBrowse Home
|
New Git URL