Skip to content

Commit 0b9de71

Browse files
authored
Merge pull request asfernandes#46 from fdcastel/issue-42-req3
Add disconnected RowSet class with typed Row access
2 parents 1df374f + 9936e3b commit 0b9de71

22 files changed

Lines changed: 1936 additions & 881 deletions

src/fb-cpp/Attachment.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ Attachment::Attachment(Client& client, const std::string& uri, const AttachmentO
3535
{
3636
const auto master = client.getMaster();
3737

38-
const auto status = client.newStatus();
39-
StatusWrapper statusWrapper{client, status.get()};
38+
StatusWrapper statusWrapper{client};
4039

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

@@ -74,8 +73,7 @@ void Attachment::disconnectOrDrop(bool drop)
7473
{
7574
assert(isValid());
7675

77-
const auto status = client->newStatus();
78-
StatusWrapper statusWrapper{*client, status.get()};
76+
StatusWrapper statusWrapper{*client};
7977

8078
if (drop)
8179
handle->dropDatabase(&statusWrapper);

src/fb-cpp/Batch.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,13 @@ using namespace fbcpp::impl;
3636

3737
BatchCompletionState::BatchCompletionState(Client& client, FbUniquePtr<fb::IBatchCompletionState> handle) noexcept
3838
: client{&client},
39-
status{client.newStatus()},
40-
statusWrapper{client, status.get()},
39+
statusWrapper{client},
4140
handle{std::move(handle)}
4241
{
4342
}
4443

4544
BatchCompletionState::BatchCompletionState(BatchCompletionState&& o) noexcept
4645
: client{o.client},
47-
status{std::move(o.status)},
4846
statusWrapper{std::move(o.statusWrapper)},
4947
handle{std::move(o.handle)}
5048
{
@@ -102,8 +100,7 @@ Batch::Batch(Statement& statement, Transaction& transaction, const BatchOptions&
102100
: client{&statement.getAttachment().getClient()},
103101
transaction{&transaction},
104102
statement{&statement},
105-
status{client->newStatus()},
106-
statusWrapper{*client, status.get()}
103+
statusWrapper{*client}
107104
{
108105
assert(statement.isValid());
109106
assert(transaction.isValid());
@@ -118,8 +115,7 @@ Batch::Batch(Attachment& attachment, Transaction& transaction, std::string_view
118115
const BatchOptions& options)
119116
: client{&attachment.getClient()},
120117
transaction{&transaction},
121-
status{client->newStatus()},
122-
statusWrapper{*client, status.get()}
118+
statusWrapper{*client}
123119
{
124120
assert(attachment.isValid());
125121
assert(transaction.isValid());
@@ -135,7 +131,6 @@ Batch::Batch(Batch&& o) noexcept
135131
: client{o.client},
136132
transaction{o.transaction},
137133
statement{o.statement},
138-
status{std::move(o.status)},
139134
statusWrapper{std::move(o.statusWrapper)},
140135
handle{std::move(o.handle)}
141136
{

src/fb-cpp/Batch.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ namespace fbcpp
250250

251251
private:
252252
Client* client;
253-
FbUniquePtr<fb::IStatus> status;
254253
impl::StatusWrapper statusWrapper;
255254
FbUniquePtr<fb::IBatchCompletionState> handle;
256255
};
@@ -447,7 +446,6 @@ namespace fbcpp
447446
Client* client;
448447
Transaction* transaction;
449448
Statement* statement = nullptr;
450-
FbUniquePtr<fb::IStatus> status;
451449
impl::StatusWrapper statusWrapper;
452450
FbRef<fb::IBatch> handle;
453451
std::vector<Descriptor> inputDescriptors;

src/fb-cpp/Blob.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ using namespace fbcpp::impl;
3838
Blob::Blob(Attachment& attachment, Transaction& transaction, const BlobOptions& options)
3939
: attachment{attachment},
4040
transaction{transaction},
41-
status{attachment.getClient().newStatus()},
42-
statusWrapper{attachment.getClient(), status.get()}
41+
statusWrapper{attachment.getClient()}
4342
{
4443
assert(attachment.isValid());
4544
assert(transaction.isValid());
@@ -54,8 +53,7 @@ Blob::Blob(Attachment& attachment, Transaction& transaction, const BlobId& blobI
5453
: attachment{attachment},
5554
transaction{transaction},
5655
id{blobId},
57-
status{attachment.getClient().newStatus()},
58-
statusWrapper{attachment.getClient(), status.get()}
56+
statusWrapper{attachment.getClient()}
5957
{
6058
assert(attachment.isValid());
6159
assert(transaction.isValid());

src/fb-cpp/Blob.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ namespace fbcpp
284284
: attachment{o.attachment},
285285
transaction{o.transaction},
286286
id{o.id},
287-
status{std::move(o.status)},
288287
statusWrapper{std::move(o.statusWrapper)},
289288
handle{std::move(o.handle)}
290289
{
@@ -427,7 +426,6 @@ namespace fbcpp
427426
Attachment& attachment;
428427
Transaction& transaction;
429428
BlobId id;
430-
FbUniquePtr<fb::IStatus> status;
431429
impl::StatusWrapper statusWrapper;
432430
FbRef<fb::IBlob> handle;
433431
};

src/fb-cpp/CalendarConverter.h

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ namespace fbcpp::impl
4848
class CalendarConverter final
4949
{
5050
public:
51-
explicit CalendarConverter(Client& client, StatusWrapper* statusWrapper)
52-
: client{&client},
53-
statusWrapper{statusWrapper}
51+
explicit CalendarConverter(Client& client)
52+
: client{&client}
5453
{
5554
}
5655

@@ -236,7 +235,7 @@ namespace fbcpp::impl
236235
subseconds);
237236
}
238237

239-
OpaqueTimeTz timeTzToOpaqueTimeTz(const TimeTz& timeTz)
238+
OpaqueTimeTz timeTzToOpaqueTimeTz(StatusWrapper* statusWrapper, const TimeTz& timeTz)
240239
{
241240
const auto duration = timeTz.utcTime.to_duration();
242241

@@ -259,7 +258,8 @@ namespace fbcpp::impl
259258
return opaque;
260259
}
261260

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

@@ -282,12 +282,12 @@ namespace fbcpp::impl
282282
return timeTz;
283283
}
284284

285-
OpaqueTimeTz stringToOpaqueTimeTz(std::string_view value)
285+
OpaqueTimeTz stringToOpaqueTimeTz(StatusWrapper* statusWrapper, std::string_view value)
286286
{
287-
return timeTzToOpaqueTimeTz(stringToTimeTz(value));
287+
return timeTzToOpaqueTimeTz(statusWrapper, stringToTimeTz(statusWrapper, value));
288288
}
289289

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

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

366-
return opaqueTimeTzToTimeTz(encoded);
366+
return opaqueTimeTzToTimeTz(statusWrapper, encoded);
367367
}
368368

369369
// FIXME: review
@@ -509,7 +509,7 @@ namespace fbcpp::impl
509509
return std::format("{} {}", dateString, timeString);
510510
}
511511

512-
OpaqueTimestampTz timestampTzToOpaqueTimestampTz(const TimestampTz& timestampTz)
512+
OpaqueTimestampTz timestampTzToOpaqueTimestampTz(StatusWrapper* statusWrapper, const TimestampTz& timestampTz)
513513
{
514514
OpaqueTimestampTz opaque;
515515

@@ -522,7 +522,7 @@ namespace fbcpp::impl
522522
return opaque;
523523
}
524524

525-
TimestampTz opaqueTimestampTzToTimestampTz(
525+
TimestampTz opaqueTimestampTzToTimestampTz(StatusWrapper* statusWrapper,
526526
const OpaqueTimestampTz& opaqueTimestamp, std::string* decodedTimeZoneName = nullptr)
527527
{
528528
const auto ticks =
@@ -553,12 +553,12 @@ namespace fbcpp::impl
553553
return timestampTz;
554554
}
555555

556-
OpaqueTimestampTz stringToOpaqueTimestampTz(std::string_view value)
556+
OpaqueTimestampTz stringToOpaqueTimestampTz(StatusWrapper* statusWrapper, std::string_view value)
557557
{
558-
return timestampTzToOpaqueTimestampTz(stringToTimestampTz(value));
558+
return timestampTzToOpaqueTimestampTz(statusWrapper, stringToTimestampTz(statusWrapper, value));
559559
}
560560

561-
std::string opaqueTimestampTzToString(const OpaqueTimestampTz& timestamp)
561+
std::string opaqueTimestampTzToString(StatusWrapper* statusWrapper, const OpaqueTimestampTz& timestamp)
562562
{
563563
unsigned year;
564564
unsigned month;
@@ -576,7 +576,7 @@ namespace fbcpp::impl
576576
seconds, subseconds, timeZoneBuffer.data());
577577
}
578578

579-
TimestampTz stringToTimestampTz(std::string_view value)
579+
TimestampTz stringToTimestampTz(StatusWrapper* statusWrapper, std::string_view value)
580580
{
581581
static const std::regex pattern(
582582
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*$)");
@@ -660,7 +660,7 @@ namespace fbcpp::impl
660660
throwInvalidTimestampValue();
661661

662662
std::string resolvedTimeZoneName;
663-
opaqueTimestampTzToTimestampTz(encoded, &resolvedTimeZoneName);
663+
opaqueTimestampTzToTimestampTz(statusWrapper, encoded, &resolvedTimeZoneName);
664664

665665
return TimestampTz{utcTimestamp, resolvedTimeZoneName};
666666
}
@@ -713,7 +713,6 @@ namespace fbcpp::impl
713713
std::chrono::year{1858} / std::chrono::November / 17,
714714
};
715715
Client* client;
716-
StatusWrapper* statusWrapper;
717716
};
718717
} // namespace fbcpp::impl
719718

src/fb-cpp/Client.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ void Client::shutdown()
3535
assert(isValid());
3636

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

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

src/fb-cpp/EventListener.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ EventListener::EventListener(Attachment& attachment, const std::vector<std::stri
104104
listening = true;
105105
running = true;
106106

107-
const auto status = client.newStatus();
108-
StatusWrapper statusWrapper{client, status.get()};
107+
StatusWrapper statusWrapper{client};
109108

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

252-
const auto status = client.newStatus();
253-
StatusWrapper statusWrapper{client, status.get()};
251+
StatusWrapper statusWrapper{client};
254252
FbRef<fb::IEvents> newHandle;
255253

256254
try
@@ -351,8 +349,7 @@ void EventListener::cancelEventsHandle()
351349
if (!handle)
352350
return;
353351

354-
const auto status = client.newStatus();
355-
StatusWrapper statusWrapper{client, status.get()};
352+
StatusWrapper statusWrapper{client};
356353

357354
handle->cancel(&statusWrapper);
358355
}

src/fb-cpp/Exception.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ using namespace fbcpp;
3232
using namespace fbcpp::impl;
3333

3434

35+
fb::IStatus* StatusWrapper::getStatus() const
36+
{
37+
if (!status)
38+
{
39+
status = client->newStatus().release();
40+
statusOwner = true;
41+
}
42+
43+
return status;
44+
}
45+
3546
void StatusWrapper::checkException(StatusWrapper* status)
3647
{
3748
if (status->dirty && (status->getState() & fb::IStatus::STATE_ERRORS))

0 commit comments

Comments
 (0)