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-cpp-export.h"
29#include "fb-api.h"
30#include "Row.h"
31#include "SmartPtrs.h"
32#include "NumericConverter.h"
33#include "CalendarConverter.h"
34#include "Descriptor.h"
35#include "Exception.h"
36#include <cassert>
37#include <cstddef>
38#include <span>
39#include <vector>
40
41
45namespace fbcpp
46{
47 class Statement;
48
56 class FB_CPP_EXPORT RowSet final
57 {
58
59 public:
71 explicit RowSet(Statement& statement, unsigned maxRows);
72
79 explicit RowSet(Statement& statement, unsigned maxRows, bool includeCurrentRow);
80
81 RowSet(RowSet&& o) noexcept
82 : client{o.client},
83 count{o.count},
84 messageLength{o.messageLength},
85 buffer{std::move(o.buffer)},
86 descriptors{std::move(o.descriptors)},
87 statusWrapper{std::move(o.statusWrapper)},
88 numericConverter{std::move(o.numericConverter)},
89 calendarConverter{std::move(o.calendarConverter)}
90 {
91 o.count = 0;
92 o.messageLength = 0;
93 }
94
95 RowSet& operator=(RowSet&& o) noexcept
96 {
97 if (this != &o)
98 {
99 client = o.client;
100 count = o.count;
101 messageLength = o.messageLength;
102 buffer = std::move(o.buffer);
103 descriptors = std::move(o.descriptors);
104 statusWrapper = std::move(o.statusWrapper);
105 numericConverter = std::move(o.numericConverter);
106 calendarConverter = std::move(o.calendarConverter);
107 o.count = 0;
108 o.messageLength = 0;
109 }
110
111 return *this;
112 }
113
114 RowSet(const RowSet&) = delete;
115 RowSet& operator=(const RowSet&) = delete;
116
117 public:
121 unsigned getCount() const noexcept
122 {
123 return count;
124 }
125
129 unsigned getMessageLength() const noexcept
130 {
131 return messageLength;
132 }
133
138 Row getRow(unsigned index)
139 {
140 assert(index < count);
141 return Row{*client, descriptors, getRawRow(index)};
142 }
143
148 std::span<const std::byte> getRawRow(unsigned index) const
149 {
150 assert(index < count);
151 const auto* data = buffer.data() + static_cast<std::size_t>(index) * messageLength;
152 return {data, messageLength};
153 }
154
158 const std::vector<std::byte>& getRawBuffer() const noexcept
159 {
160 return buffer;
161 }
162
163 private:
164 Client* client;
165 unsigned count = 0;
166 unsigned messageLength = 0;
167 std::vector<std::byte> buffer;
168 std::vector<Descriptor> descriptors;
169 impl::StatusWrapper statusWrapper;
170 impl::NumericConverter numericConverter;
171 impl::CalendarConverter calendarConverter;
172 };
173} // namespace fbcpp
174
175#endif // FBCPP_ROWSET_H
Represents a Firebird client library instance.
Definition Client.h:54
A disconnected buffer of rows fetched from a Statement's result set.
Definition RowSet.h:57
unsigned getCount() const noexcept
Returns the number of rows actually fetched.
Definition RowSet.h:121
Row getRow(unsigned index)
Returns a Row view for typed access to the row at index.
Definition RowSet.h:138
std::span< const std::byte > getRawRow(unsigned index) const
Returns a span over the raw data of the row at index.
Definition RowSet.h:148
unsigned getMessageLength() const noexcept
Returns the message length (in bytes) of each row.
Definition RowSet.h:129
const std::vector< std::byte > & getRawBuffer() const noexcept
Returns the entire contiguous buffer containing all fetched rows.
Definition RowSet.h:158
A lightweight, non-owning view of a single row's data with typed accessors.
Definition Row.h:70
Prepares, executes, and fetches SQL statements against a Firebird attachment.
Definition Statement.h:143
fb-cpp namespace.
Definition Attachment.h:46