26#include "../Attachment.h"
27#include "../Transaction.h"
35 statusWrapper{a.getClient()}
39 for (
const auto& entry : entries)
41 if (entry.messageNumber > 255u)
44 const auto it = std::lower_bound(messages.begin(), messages.end(), entry.messageNumber,
45 [](
const auto& pair,
unsigned number) { return pair.first < number; });
47 if (it != messages.end() && it->first == entry.messageNumber)
48 throw FbCppException(
"Duplicated message number " + std::to_string(entry.messageNumber));
50 messages.emplace(it, entry.messageNumber,
RequestMessage{attachment->getClient(), entry.format});
53 handle.reset(attachment->
getHandle()->compileRequest(
54 &statusWrapper,
static_cast<unsigned>(blr.size()),
reinterpret_cast<const unsigned char*
>(blr.data())));
58 : attachment{o.attachment},
59 messages{std::move(o.messages)},
60 statusWrapper{std::move(o.statusWrapper)},
61 handle{std::move(o.handle)}
69 attachment = o.attachment;
70 messages = std::move(o.messages);
71 statusWrapper = std::move(o.statusWrapper);
72 handle = std::move(o.handle);
80 const auto message = findMessage(messageNumber);
85 "Message number " + std::to_string(messageNumber) +
" was not declared in the request");
95 handle->free(&statusWrapper);
104 handle->start(&statusWrapper, transaction.
getHandle().get(),
static_cast<int>(level));
112 const auto message = findMessage(messageNumber);
117 "Message number " + std::to_string(messageNumber) +
" was not declared in the request");
120 handle->startAndSend(&statusWrapper, transaction.
getHandle().get(),
static_cast<int>(level), messageNumber,
121 static_cast<unsigned>(message->message.size()), message->message.data());
128 const auto message = findMessage(messageNumber);
133 "Message number " + std::to_string(messageNumber) +
" was not declared in the request");
136 handle->send(&statusWrapper,
static_cast<int>(level), messageNumber,
137 static_cast<unsigned>(message->message.size()), message->message.data());
144 const auto message = findMessage(messageNumber);
149 "Message number " + std::to_string(messageNumber) +
" was not declared in the request");
154 handle->receive(&statusWrapper,
static_cast<int>(level), messageNumber,
155 static_cast<unsigned>(message->message.size()), message->message.data());
172 handle->unwind(&statusWrapper,
static_cast<int>(level));
175 RequestMessage* Request::findMessage(
unsigned messageNumber)
const noexcept
177 const auto it = std::lower_bound(messages.begin(), messages.end(), messageNumber,
178 [](
const auto& pair,
unsigned number) { return pair.first < number; });
180 if (it != messages.end() && it->first == messageNumber)
Represents a connection to a Firebird database.
FbRef< fb::IAttachment > getHandle() noexcept
Returns the internal Firebird IAttachment handle.
bool isValid() noexcept
Returns whether the Attachment object is valid.
Exception thrown when a Firebird database operation fails.
std::intptr_t getErrorCode() const noexcept
Returns the primary ISC error code (first isc_arg_gds value), or 0 if none.
Base exception class for all fb-cpp exceptions.
Represents a transaction in one or more Firebird databases.
bool isValid() noexcept
Returns whether the Transaction object is valid.
FbRef< fb::ITransaction > getHandle() noexcept
Returns the internal Firebird ITransaction handle.
A message buffer of a Firebird request with typed accessors.
Represents a Firebird request: a precompiled BLR (Binary Language Representation) program.
Request & operator=(Request &&o) noexcept
Move assignment.
void startAndSend(Transaction &transaction, unsigned messageNumber, unsigned level=0)
Starts the execution of the request, sending it an input message.
void send(unsigned messageNumber, unsigned level=0)
Sends an input message to the running request.
void free()
Releases the compiled request.
bool isValid() noexcept
Returns whether the Request object is valid.
RequestMessage & getMessage(unsigned messageNumber)
Returns the message associated with a message number declared at construction time.
Request(Attachment &attachment, std::span< const std::byte > blr, const std::vector< MessageEntry > &messages={})
Compiles a request from the given BLR for the attachment's database.
void unwind(unsigned level=0)
Unwinds the running request.
bool receive(unsigned messageNumber, unsigned level=0)
Receives a record from the running request into the associated message.
void start(Transaction &transaction, unsigned level=0)
Starts the execution of the request.
fb-cpp request namespace.