Skip to content
8 changes: 3 additions & 5 deletions src/fb-cpp/Attachment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ Attachment::Attachment(Client& client, const std::string& uri, const AttachmentO
{
const auto master = client.getMaster();

const auto status = client.newStatus();
StatusWrapper statusWrapper{client, status.get()};
StatusWrapper statusWrapper{client};

auto dpbBuilder = fbUnique(master->getUtilInterface()->getXpbBuilder(&statusWrapper, fb::IXpbBuilder::DPB,
auto dpbBuilder = fbUnique(client.getUtil()->getXpbBuilder(&statusWrapper, fb::IXpbBuilder::DPB,
reinterpret_cast<const std::uint8_t*>(options.getDpb().data()),
static_cast<unsigned>(options.getDpb().size())));

Expand Down Expand Up @@ -74,8 +73,7 @@ void Attachment::disconnectOrDrop(bool drop)
{
assert(isValid());

const auto status = client->newStatus();
StatusWrapper statusWrapper{*client, status.get()};
StatusWrapper statusWrapper{*client};

if (drop)
handle->dropDatabase(&statusWrapper);
Expand Down
11 changes: 3 additions & 8 deletions src/fb-cpp/Batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@ using namespace fbcpp::impl;

BatchCompletionState::BatchCompletionState(Client& client, FbUniquePtr<fb::IBatchCompletionState> handle) noexcept
: client{&client},
status{client.newStatus()},
statusWrapper{client, status.get()},
statusWrapper{client},
handle{std::move(handle)}
{
}

BatchCompletionState::BatchCompletionState(BatchCompletionState&& o) noexcept
: client{o.client},
status{std::move(o.status)},
statusWrapper{std::move(o.statusWrapper)},
handle{std::move(o.handle)}
{
Expand Down Expand Up @@ -102,8 +100,7 @@ Batch::Batch(Statement& statement, Transaction& transaction, const BatchOptions&
: client{&statement.getAttachment().getClient()},
transaction{&transaction},
statement{&statement},
status{client->newStatus()},
statusWrapper{*client, status.get()}
statusWrapper{*client}
{
assert(statement.isValid());
assert(transaction.isValid());
Expand All @@ -118,8 +115,7 @@ Batch::Batch(Attachment& attachment, Transaction& transaction, std::string_view
const BatchOptions& options)
: client{&attachment.getClient()},
transaction{&transaction},
status{client->newStatus()},
statusWrapper{*client, status.get()}
statusWrapper{*client}
{
assert(attachment.isValid());
assert(transaction.isValid());
Expand All @@ -135,7 +131,6 @@ Batch::Batch(Batch&& o) noexcept
: client{o.client},
transaction{o.transaction},
statement{o.statement},
status{std::move(o.status)},
statusWrapper{std::move(o.statusWrapper)},
handle{std::move(o.handle)}
{
Expand Down
2 changes: 0 additions & 2 deletions src/fb-cpp/Batch.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ namespace fbcpp

private:
Client* client;
FbUniquePtr<fb::IStatus> status;
impl::StatusWrapper statusWrapper;
FbUniquePtr<fb::IBatchCompletionState> handle;
};
Expand Down Expand Up @@ -447,7 +446,6 @@ namespace fbcpp
Client* client;
Transaction* transaction;
Statement* statement = nullptr;
FbUniquePtr<fb::IStatus> status;
impl::StatusWrapper statusWrapper;
FbRef<fb::IBatch> handle;
std::vector<Descriptor> inputDescriptors;
Expand Down
6 changes: 2 additions & 4 deletions src/fb-cpp/Blob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ using namespace fbcpp::impl;
Blob::Blob(Attachment& attachment, Transaction& transaction, const BlobOptions& options)
: attachment{attachment},
transaction{transaction},
status{attachment.getClient().newStatus()},
statusWrapper{attachment.getClient(), status.get()}
statusWrapper{attachment.getClient()}
{
assert(attachment.isValid());
assert(transaction.isValid());
Expand All @@ -54,8 +53,7 @@ Blob::Blob(Attachment& attachment, Transaction& transaction, const BlobId& blobI
: attachment{attachment},
transaction{transaction},
id{blobId},
status{attachment.getClient().newStatus()},
statusWrapper{attachment.getClient(), status.get()}
statusWrapper{attachment.getClient()}
{
assert(attachment.isValid());
assert(transaction.isValid());
Expand Down
2 changes: 0 additions & 2 deletions src/fb-cpp/Blob.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ namespace fbcpp
: attachment{o.attachment},
transaction{o.transaction},
id{o.id},
status{std::move(o.status)},
statusWrapper{std::move(o.statusWrapper)},
handle{std::move(o.handle)}
{
Expand Down Expand Up @@ -427,7 +426,6 @@ namespace fbcpp
Attachment& attachment;
Transaction& transaction;
BlobId id;
FbUniquePtr<fb::IStatus> status;
impl::StatusWrapper statusWrapper;
FbRef<fb::IBlob> handle;
};
Expand Down
35 changes: 17 additions & 18 deletions src/fb-cpp/CalendarConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ namespace fbcpp::impl
class CalendarConverter final
{
public:
explicit CalendarConverter(Client& client, StatusWrapper* statusWrapper)
: client{&client},
statusWrapper{statusWrapper}
explicit CalendarConverter(Client& client)
: client{&client}
{
}

Expand Down Expand Up @@ -236,7 +235,7 @@ namespace fbcpp::impl
subseconds);
}

OpaqueTimeTz timeTzToOpaqueTimeTz(const TimeTz& timeTz)
OpaqueTimeTz timeTzToOpaqueTimeTz(StatusWrapper* statusWrapper, const TimeTz& timeTz)
{
const auto duration = timeTz.utcTime.to_duration();

Expand All @@ -259,7 +258,8 @@ namespace fbcpp::impl
return opaque;
}

TimeTz opaqueTimeTzToTimeTz(const OpaqueTimeTz& opaqueTime, std::string* decodedTimeZoneName = nullptr)
TimeTz opaqueTimeTzToTimeTz(
StatusWrapper* statusWrapper, const OpaqueTimeTz& opaqueTime, std::string* decodedTimeZoneName = nullptr)
{
const auto ticks = static_cast<std::int64_t>(opaqueTime.value.utc_time) * 100;

Expand All @@ -282,12 +282,12 @@ namespace fbcpp::impl
return timeTz;
}

OpaqueTimeTz stringToOpaqueTimeTz(std::string_view value)
OpaqueTimeTz stringToOpaqueTimeTz(StatusWrapper* statusWrapper, std::string_view value)
{
return timeTzToOpaqueTimeTz(stringToTimeTz(value));
return timeTzToOpaqueTimeTz(statusWrapper, stringToTimeTz(statusWrapper, value));
}

std::string opaqueTimeTzToString(const OpaqueTimeTz& time)
std::string opaqueTimeTzToString(StatusWrapper* statusWrapper, const OpaqueTimeTz& time)
{
unsigned hours;
unsigned minutes;
Expand All @@ -301,7 +301,7 @@ namespace fbcpp::impl
return std::format("{:02}:{:02}:{:02}.{:04} {}", hours, minutes, seconds, fractions, timeZoneBuffer.data());
}

TimeTz stringToTimeTz(std::string_view value)
TimeTz stringToTimeTz(StatusWrapper* statusWrapper, std::string_view value)
{
static const std::regex pattern(
R"(^\s*([0-9]{2})\s*:\s*([0-9]{2})\s*:\s*([0-9]{2})(?:\s*\.\s*([0-9]{1,4}))?\s+([^\s]+)\s*$)");
Expand Down Expand Up @@ -363,7 +363,7 @@ namespace fbcpp::impl
client->getUtil()->encodeTimeTz(
statusWrapper, &encoded.value, hours, minutes, seconds, fractions, timeZoneString.c_str());

return opaqueTimeTzToTimeTz(encoded);
return opaqueTimeTzToTimeTz(statusWrapper, encoded);
}

// FIXME: review
Expand Down Expand Up @@ -509,7 +509,7 @@ namespace fbcpp::impl
return std::format("{} {}", dateString, timeString);
}

OpaqueTimestampTz timestampTzToOpaqueTimestampTz(const TimestampTz& timestampTz)
OpaqueTimestampTz timestampTzToOpaqueTimestampTz(StatusWrapper* statusWrapper, const TimestampTz& timestampTz)
{
OpaqueTimestampTz opaque;

Expand All @@ -522,7 +522,7 @@ namespace fbcpp::impl
return opaque;
}

TimestampTz opaqueTimestampTzToTimestampTz(
TimestampTz opaqueTimestampTzToTimestampTz(StatusWrapper* statusWrapper,
const OpaqueTimestampTz& opaqueTimestamp, std::string* decodedTimeZoneName = nullptr)
{
const auto ticks =
Expand Down Expand Up @@ -553,12 +553,12 @@ namespace fbcpp::impl
return timestampTz;
}

OpaqueTimestampTz stringToOpaqueTimestampTz(std::string_view value)
OpaqueTimestampTz stringToOpaqueTimestampTz(StatusWrapper* statusWrapper, std::string_view value)
{
return timestampTzToOpaqueTimestampTz(stringToTimestampTz(value));
return timestampTzToOpaqueTimestampTz(statusWrapper, stringToTimestampTz(statusWrapper, value));
}

std::string opaqueTimestampTzToString(const OpaqueTimestampTz& timestamp)
std::string opaqueTimestampTzToString(StatusWrapper* statusWrapper, const OpaqueTimestampTz& timestamp)
{
unsigned year;
unsigned month;
Expand All @@ -576,7 +576,7 @@ namespace fbcpp::impl
seconds, subseconds, timeZoneBuffer.data());
}

TimestampTz stringToTimestampTz(std::string_view value)
TimestampTz stringToTimestampTz(StatusWrapper* statusWrapper, std::string_view value)
{
static const std::regex pattern(
R"(^\s*([0-9]{4})\s*-\s*([0-9]{2})\s*-\s*([0-9]{2})\s+([0-9]{2})\s*:\s*([0-9]{2})\s*:\s*([0-9]{2})(?:\s*\.\s*([0-9]{1,4}))?\s+([^\s]+)\s*$)");
Expand Down Expand Up @@ -660,7 +660,7 @@ namespace fbcpp::impl
throwInvalidTimestampValue();

std::string resolvedTimeZoneName;
opaqueTimestampTzToTimestampTz(encoded, &resolvedTimeZoneName);
opaqueTimestampTzToTimestampTz(statusWrapper, encoded, &resolvedTimeZoneName);

return TimestampTz{utcTimestamp, resolvedTimeZoneName};
}
Expand Down Expand Up @@ -713,7 +713,6 @@ namespace fbcpp::impl
std::chrono::year{1858} / std::chrono::November / 17,
};
Client* client;
StatusWrapper* statusWrapper;
};
} // namespace fbcpp::impl

Expand Down
3 changes: 1 addition & 2 deletions src/fb-cpp/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ void Client::shutdown()
assert(isValid());

auto dispatcher = fbRef(master->getDispatcher());
const auto status = newStatus();
StatusWrapper statusWrapper{*this, status.get()};
StatusWrapper statusWrapper{*this};

dispatcher->shutdown(&statusWrapper, 0, fb_shutrsn_app_stopped);

Expand Down
9 changes: 3 additions & 6 deletions src/fb-cpp/EventListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ EventListener::EventListener(Attachment& attachment, const std::vector<std::stri
listening = true;
running = true;

const auto status = client.newStatus();
StatusWrapper statusWrapper{client, status.get()};
StatusWrapper statusWrapper{client};

eventsHandle.reset(attachment.getHandle()->queEvents(
&statusWrapper, &firebirdCallback, static_cast<unsigned>(eventBuffer.size()), eventBuffer.data()));
Expand Down Expand Up @@ -249,8 +248,7 @@ void EventListener::handleEvent(unsigned length, const std::uint8_t* events)
return;
}

const auto status = client.newStatus();
StatusWrapper statusWrapper{client, status.get()};
StatusWrapper statusWrapper{client};
FbRef<fb::IEvents> newHandle;

try
Expand Down Expand Up @@ -351,8 +349,7 @@ void EventListener::cancelEventsHandle()
if (!handle)
return;

const auto status = client.newStatus();
StatusWrapper statusWrapper{client, status.get()};
StatusWrapper statusWrapper{client};

handle->cancel(&statusWrapper);
}
11 changes: 11 additions & 0 deletions src/fb-cpp/Exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ using namespace fbcpp;
using namespace fbcpp::impl;


fb::IStatus* StatusWrapper::getStatus() const
{
if (!status)
{
status = client->newStatus().release();
statusOwner = true;
}

return status;
}

void StatusWrapper::checkException(StatusWrapper* status)
{
if (status->dirty && (status->getState() & fb::IStatus::STATE_ERRORS))
Expand Down
Loading