fb-cpp 0.0.2
A modern C++ wrapper for the Firebird database API
Loading...
Searching...
No Matches
RequestMessage.h
1/*
2 * MIT License
3 *
4 * Copyright (c) 2026 Adriano dos Santos Fernandes
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_REQUEST_MESSAGE_H
26#define FBCPP_REQUEST_MESSAGE_H
27
28#include "../config.h"
29#include "fb-cpp-export.h"
30#include "../fb-api.h"
31#include "../types.h"
32#include "../Blob.h"
33#include "../Descriptor.h"
34#include "../NumericConverter.h"
35#include "../CalendarConverter.h"
36#include "../impl/ParameterSetter.h"
37#include "RequestMessageFormat.h"
38#include "../Row.h"
39#include "../SmartPtrs.h"
40#include "../Exception.h"
41#include "../StructBinding.h"
42#include <cassert>
43#include <cstddef>
44#include <cstdint>
45#include <memory>
46#include <optional>
47#include <span>
48#include <stdexcept>
49#include <string_view>
50#include <vector>
51
52#if FB_CPP_USE_BOOST_MULTIPRECISION != 0
53#include <boost/multiprecision/cpp_int.hpp>
54#include <boost/multiprecision/cpp_dec_float.hpp>
55#endif
56
57#if FB_CPP_USE_BOOST_DECIMAL != 0
58#include <boost/decimal.hpp>
59#endif
60
61
65namespace fbcpp::request
66{
77 class FB_CPP_EXPORT RequestMessage final : private impl::ParameterSetter<RequestMessage, true>
78 {
79 friend class impl::ParameterSetter<RequestMessage, true>;
80
81 public:
82 RequestMessage(RequestMessage&& o) noexcept
83 : client{o.client},
84 descriptors{std::move(o.descriptors)},
85 message{std::move(o.message)},
86 statusWrapper{std::move(o.statusWrapper)},
87 numericConverter{std::move(o.numericConverter)},
88 calendarConverter{std::move(o.calendarConverter)},
89 row{std::make_unique<Row>(*client, descriptors, std::span<const std::byte>{message})}
90 {
91 }
92
93 RequestMessage& operator=(RequestMessage&& o) noexcept
94 {
95 if (this != &o)
96 {
97 client = o.client;
98 descriptors = std::move(o.descriptors);
99 message = std::move(o.message);
100 statusWrapper = std::move(o.statusWrapper);
101 numericConverter = std::move(o.numericConverter);
102 calendarConverter = std::move(o.calendarConverter);
103 row = std::make_unique<Row>(*client, descriptors, std::span<const std::byte>{message});
104 }
105
106 return *this;
107 }
108
109 RequestMessage(const RequestMessage&) = delete;
110 RequestMessage& operator=(const RequestMessage&) = delete;
111
112 public:
116 Row& getRow() noexcept
117 {
118 assert(row);
119 return *row;
120 }
121
125 const std::vector<Descriptor>& getDescriptors() const noexcept
126 {
127 return descriptors;
128 }
129
133 using impl::ParameterSetter<RequestMessage, true>::clearParameters;
134 using impl::ParameterSetter<RequestMessage, true>::set;
135 using impl::ParameterSetter<RequestMessage, true>::setBlobId;
136 using impl::ParameterSetter<RequestMessage, true>::setBool;
137 using impl::ParameterSetter<RequestMessage, true>::setBytes;
138 using impl::ParameterSetter<RequestMessage, true>::setDate;
139 using impl::ParameterSetter<RequestMessage, true>::setDouble;
140 using impl::ParameterSetter<RequestMessage, true>::setFloat;
141 using impl::ParameterSetter<RequestMessage, true>::setInt16;
142 using impl::ParameterSetter<RequestMessage, true>::setInt32;
143 using impl::ParameterSetter<RequestMessage, true>::setInt64;
144 using impl::ParameterSetter<RequestMessage, true>::setNull;
145 using impl::ParameterSetter<RequestMessage, true>::setOpaqueDate;
146 using impl::ParameterSetter<RequestMessage, true>::setOpaqueDecFloat16;
147 using impl::ParameterSetter<RequestMessage, true>::setOpaqueDecFloat34;
148 using impl::ParameterSetter<RequestMessage, true>::setOpaqueInt128;
149 using impl::ParameterSetter<RequestMessage, true>::setOpaqueTime;
150 using impl::ParameterSetter<RequestMessage, true>::setOpaqueTimeTz;
151 using impl::ParameterSetter<RequestMessage, true>::setOpaqueTimestamp;
152 using impl::ParameterSetter<RequestMessage, true>::setOpaqueTimestampTz;
153 using impl::ParameterSetter<RequestMessage, true>::setScaledInt16;
154 using impl::ParameterSetter<RequestMessage, true>::setScaledInt32;
155 using impl::ParameterSetter<RequestMessage, true>::setScaledInt64;
156 using impl::ParameterSetter<RequestMessage, true>::setScaledOpaqueInt128;
157 using impl::ParameterSetter<RequestMessage, true>::setString;
158 using impl::ParameterSetter<RequestMessage, true>::setTime;
159 using impl::ParameterSetter<RequestMessage, true>::setTimeTz;
160 using impl::ParameterSetter<RequestMessage, true>::setTimestamp;
161 using impl::ParameterSetter<RequestMessage, true>::setTimestampTz;
162
163#if FB_CPP_USE_BOOST_MULTIPRECISION != 0
164 using impl::ParameterSetter<RequestMessage, true>::setBoostDecFloat16;
165 using impl::ParameterSetter<RequestMessage, true>::setBoostDecFloat34;
166 using impl::ParameterSetter<RequestMessage, true>::setBoostInt128;
167 using impl::ParameterSetter<RequestMessage, true>::setScaledBoostInt128;
168#endif
169
170#if FB_CPP_USE_BOOST_DECIMAL != 0
171 using impl::ParameterSetter<RequestMessage, true>::setBoostDecimal128;
172 using impl::ParameterSetter<RequestMessage, true>::setBoostDecimal32;
173 using impl::ParameterSetter<RequestMessage, true>::setBoostDecimal64;
174#endif
175
178
179
180 private:
181 friend class Request;
182
183 const std::vector<Descriptor>& getSetterDescriptors() const noexcept
184 {
185 return descriptors;
186 }
187
188 std::vector<std::byte>& getSetterMessage() noexcept
189 {
190 return message;
191 }
192
193 Client& getSetterClient() noexcept
194 {
195 return *client;
196 }
197
198 void validateSetter() const noexcept { }
199
200 explicit RequestMessage(Client& c, const RequestMessageFormat& format)
201 : client{&c},
202 descriptors{format.getDescriptors()},
203 message(format.getLength(), std::byte{0}),
204 statusWrapper{c},
205 numericConverter{c},
206 calendarConverter{c},
207 row{std::make_unique<Row>(c, descriptors, std::span<const std::byte>{message})}
208 {
209 clearParameters();
210 }
211
212 private:
213 Client* client;
214 std::vector<Descriptor> descriptors;
215 std::vector<std::byte> message;
216 impl::StatusWrapper statusWrapper;
217 impl::NumericConverter numericConverter;
218 impl::CalendarConverter calendarConverter;
219 std::unique_ptr<Row> row;
220 };
221} // namespace fbcpp::request
222
223
224#endif // FBCPP_REQUEST_MESSAGE_H
A lightweight, non-owning view of a single row's data with typed accessors.
Definition Row.h:71
A message buffer of a Firebird request with typed accessors.
Row & getRow() noexcept
Returns a Row view over the message, providing typed accessors for reading field values.
const std::vector< Descriptor > & getDescriptors() const noexcept
Returns the format-derived descriptors of the message fields.
Represents a Firebird request: a precompiled BLR (Binary Language Representation) program.
Definition Request.h:68
fb-cpp request namespace.
Definition Request.cpp:32