blob: 0e15e25e3bcfa5276a72d83922665dbf30efc888 (
plain)
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
|
== `sqlite/static_resultset.hpp`
A `static_resultset` represents the results of a query matched to a C++ type
[source,cpp]
----
// Representation of a result from a query.
struct resultset
{
template<typename T, bool Strict >
struct static_resultset
{
// Returns the current row.
T current() const &;
// Returns the current row.
T current(system::error_code & ec, error_info & ei) const &;
// Checks if the last row has been reached.
bool done() const {return result_.done();}
// Read the next row. Returns false if there's nothing more to read.
bool read_next(system::error_code & ec, error_info & ei);
bool read_next();
// The number of columes in the resultset
std::size_t column_count() const;
// Returns the name of the column idx.
string_view column_name(std::size_t idx) const;
// Returns the name of the source table for column idx.
string_view table_name(std::size_t idx) const;
// Returns the origin name of the column for column idx.
string_view column_origin_name(std::size_t idx) const;
static_resultset() = default;
static_resultset(resultset && result)
static_resultset(static_resultset<T, false> && rhs);
/// The input iterator can be used to read every row in a for-loop
struct iterator
{
using value_type = T;
using difference_type = int;
using reference = T&;
using iterator_category = std::forward_iterator_tag;
iterator();
explicit iterator(resultset::iterator itr);
bool operator!=(iterator rhs) const;
value_type &operator*();
value_type *operator->();
iterator& operator++();
iterator operator++(int);
};
/// Return an input iterator to the currently unread row
iterator begin();
/// Sentinel iterator.
iterator end();
// Convert the static_result to a strict version
static_resultset<T, true> strict() &&
{
return {std::move(result_)};
}
};
----
T:: The static type of the query. This must be a tuple or pfr compatible (for C++20) or described.
Strict:: Disables implicit conversions.
.Example
[source,cpp]
----
extern sqlite::connection conn;
struct user { std::string first_name; std::string last_name; };
BOOST_DESCRIBE_STRUCT(user, (), (first_name, last_name));
sqlite::resultset rs = conn.query("select first_name, last_name from users;");
do
{
user usr = r.current();
handle_row(u);
}
while (rs.read_next()) // read it line by line
----
|