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
72 RowSet(RowSet&& o) noexcept
73 : client{o.client},
74 count{o.count},
75 messageLength{o.messageLength},
76 buffer{std::move(o.buffer)},
77 descriptors{std::move(o.descriptors)},
78 statusWrapper{std::move(o.statusWrapper)},
79 numericConverter{std::move(o.numericConverter)},
80 calendarConverter{std::move(o.calendarConverter)}
81 {
82 o.count = 0;
83 o.messageLength = 0;
84 }
85
86 RowSet& operator=(RowSet&& o) noexcept
87 {
88 if (this != &o)
89 {
90 client = o.client;
91 count = o.count;
92 messageLength = o.messageLength;
93 buffer = std::move(o.buffer);
94 descriptors = std::move(o.descriptors);
95 statusWrapper = std::move(o.statusWrapper);
96 numericConverter = std::move(o.numericConverter);
97 calendarConverter = std::move(o.calendarConverter);
98 o.count = 0;
99 o.messageLength = 0;
100 }
101
102 return *this;
103 }
104
105 RowSet(const RowSet&) = delete;
106 RowSet& operator=(const RowSet&) = delete;
107
108 public:
112 unsigned getCount() const noexcept
113 {
114 return count;
115 }
116
120 unsigned getMessageLength() const noexcept
121 {
122 return messageLength;
123 }
124
129 Row getRow(unsigned index)
130 {
131 assert(index < count);
132 return Row{*client, descriptors, getRawRow(index)};
133 }
134
139 std::span<const std::byte> getRawRow(unsigned index) const
140 {
141 assert(index < count);
142 const auto* data = buffer.data() + static_cast<std::size_t>(index) * messageLength;
143 return {data, messageLength};
144 }
145
149 const std::vector<std::byte>& getRawBuffer() const noexcept
150 {
151 return buffer;
152 }
153
154 private:
155 Client* client;
156 unsigned count = 0;
157 unsigned messageLength = 0;
158 std::vector<std::byte> buffer;
159 std::vector<Descriptor> descriptors;
160 impl::StatusWrapper statusWrapper;
161 impl::NumericConverter numericConverter;
162 impl::CalendarConverter calendarConverter;
163 };
164} // namespace fbcpp
165
166#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:112
Row getRow(unsigned index)
Returns a Row view for typed access to the row at index.
Definition RowSet.h:129
std::span< const std::byte > getRawRow(unsigned index) const
Returns a span over the raw data of the row at index.
Definition RowSet.h:139
unsigned getMessageLength() const noexcept
Returns the message length (in bytes) of each row.
Definition RowSet.h:120
const std::vector< std::byte > & getRawBuffer() const noexcept
Returns the entire contiguous buffer containing all fetched rows.
Definition RowSet.h:149
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:262
fb-cpp namespace.
Definition Attachment.h:42