fb-cpp 0.0.2
A modern C++ wrapper for the Firebird database API
Loading...
Searching...
No Matches
RowSet.h
1/*
2 * MIT License
3 *
4 * Copyright (c) 2026 F.D.Castel
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25#ifndef FBCPP_ROWSET_H
26#define FBCPP_ROWSET_H
27
28#include "fb-api.h"
29#include "Row.h"
30#include "SmartPtrs.h"
31#include "NumericConverter.h"
32#include "CalendarConverter.h"
33#include "Descriptor.h"
34#include "Exception.h"
35#include <cassert>
36#include <cstddef>
37#include <span>
38#include <vector>
39
40
44namespace fbcpp
45{
46 class Statement;
47
55 class RowSet final
56 {
57
58 public:
70 explicit RowSet(Statement& statement, unsigned maxRows);
71
78 explicit RowSet(Statement& statement, unsigned maxRows, bool includeCurrentRow);
79
80 RowSet(RowSet&& o) noexcept
81 : client{o.client},
82 count{o.count},
83 messageLength{o.messageLength},
84 buffer{std::move(o.buffer)},
85 descriptors{std::move(o.descriptors)},
86 statusWrapper{std::move(o.statusWrapper)},
87 numericConverter{std::move(o.numericConverter)},
88 calendarConverter{std::move(o.calendarConverter)}
89 {
90 o.count = 0;
91 o.messageLength = 0;
92 }
93
94 RowSet& operator=(RowSet&& o) noexcept
95 {
96 if (this != &o)
97 {
98 client = o.client;
99 count = o.count;
100 messageLength = o.messageLength;
101 buffer = std::move(o.buffer);
102 descriptors = std::move(o.descriptors);
103 statusWrapper = std::move(o.statusWrapper);
104 numericConverter = std::move(o.numericConverter);
105 calendarConverter = std::move(o.calendarConverter);
106 o.count = 0;
107 o.messageLength = 0;
108 }
109
110 return *this;
111 }
112
113 RowSet(const RowSet&) = delete;
114 RowSet& operator=(const RowSet&) = delete;
115
116 public:
120 unsigned getCount() const noexcept
121 {
122 return count;
123 }
124
128 unsigned getMessageLength() const noexcept
129 {
130 return messageLength;
131 }
132
137 Row getRow(unsigned index)
138 {
139 assert(index < count);
140 return Row{*client, descriptors, getRawRow(index)};
141 }
142
147 std::span<const std::byte> getRawRow(unsigned index) const
148 {
149 assert(index < count);
150 const auto* data = buffer.data() + static_cast<std::size_t>(index) * messageLength;
151 return {data, messageLength};
152 }
153
157 const std::vector<std::byte>& getRawBuffer() const noexcept
158 {
159 return buffer;
160 }
161
162 private:
163 Client* client;
164 unsigned count = 0;
165 unsigned messageLength = 0;
166 std::vector<std::byte> buffer;
167 std::vector<Descriptor> descriptors;
168 impl::StatusWrapper statusWrapper;
169 impl::NumericConverter numericConverter;
170 impl::CalendarConverter calendarConverter;
171 };
172} // namespace fbcpp
173
174#endif // FBCPP_ROWSET_H
Represents a Firebird client library instance.
Definition Client.h:53
A disconnected buffer of rows fetched from a Statement's result set.
Definition RowSet.h:56
unsigned getCount() const noexcept
Returns the number of rows actually fetched.
Definition RowSet.h:120
Row getRow(unsigned index)
Returns a Row view for typed access to the row at index.
Definition RowSet.h:137
std::span< const std::byte > getRawRow(unsigned index) const
Returns a span over the raw data of the row at index.
Definition RowSet.h:147
unsigned getMessageLength() const noexcept
Returns the message length (in bytes) of each row.
Definition RowSet.h:128
const std::vector< std::byte > & getRawBuffer() const noexcept
Returns the entire contiguous buffer containing all fetched rows.
Definition RowSet.h:157
A lightweight, non-owning view of a single row's data with typed accessors.
Definition Row.h:66
Prepares, executes, and fetches SQL statements against a Firebird attachment.
Definition Statement.h:138
fb-cpp namespace.
Definition Attachment.h:45