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