Skip to content

Commit 72873eb

Browse files
committed
Make converters receive the statusWrapper as parameters in individual methods
1 parent 902f7d4 commit 72873eb

9 files changed

Lines changed: 100 additions & 110 deletions

File tree

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/NumericConverter.h

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,8 @@ namespace fbcpp::impl
147147
class NumericConverter final
148148
{
149149
public:
150-
explicit NumericConverter(Client& client, StatusWrapper* statusWrapper)
151-
: client{&client},
152-
statusWrapper{statusWrapper}
150+
explicit NumericConverter(Client& client)
151+
: client{&client}
153152
{
154153
}
155154

@@ -354,23 +353,23 @@ namespace fbcpp::impl
354353
return from.str();
355354
}
356355

357-
std::string opaqueInt128ToString(const OpaqueInt128& opaqueInt128, int scale)
356+
std::string opaqueInt128ToString(StatusWrapper* statusWrapper, const OpaqueInt128& opaqueInt128, int scale)
358357
{
359358
const auto int128Util = client->getInt128Util(statusWrapper);
360359
char buffer[fb::IInt128::STRING_SIZE + 1];
361360
int128Util->toString(statusWrapper, &opaqueInt128, scale, static_cast<unsigned>(sizeof(buffer)), buffer);
362361
return buffer;
363362
}
364363

365-
std::string opaqueDecFloat16ToString(const OpaqueDecFloat16& opaqueDecFloat16)
364+
std::string opaqueDecFloat16ToString(StatusWrapper* statusWrapper, const OpaqueDecFloat16& opaqueDecFloat16)
366365
{
367366
const auto decFloat16Util = client->getDecFloat16Util(statusWrapper);
368367
char buffer[fb::IDecFloat16::STRING_SIZE + 1];
369368
decFloat16Util->toString(statusWrapper, &opaqueDecFloat16, static_cast<unsigned>(sizeof(buffer)), buffer);
370369
return buffer;
371370
}
372371

373-
std::string opaqueDecFloat34ToString(const OpaqueDecFloat34& opaqueDecFloat34)
372+
std::string opaqueDecFloat34ToString(StatusWrapper* statusWrapper, const OpaqueDecFloat34& opaqueDecFloat34)
374373
{
375374
const auto decFloat34Util = client->getDecFloat34Util(statusWrapper);
376375
char buffer[fb::IDecFloat34::STRING_SIZE + 1];
@@ -399,30 +398,34 @@ namespace fbcpp::impl
399398
return boostInt128;
400399
}
401400

402-
OpaqueDecFloat16 boostDecFloat16ToOpaqueDecFloat16(const BoostDecFloat16& boostDecFloat16)
401+
OpaqueDecFloat16 boostDecFloat16ToOpaqueDecFloat16(
402+
StatusWrapper* statusWrapper, const BoostDecFloat16& boostDecFloat16)
403403
{
404404
const auto decFloat16Util = client->getDecFloat16Util(statusWrapper);
405405
OpaqueDecFloat16 opaqueDecFloat16;
406406
decFloat16Util->fromString(statusWrapper, boostDecFloat16.str().c_str(), &opaqueDecFloat16);
407407
return opaqueDecFloat16;
408408
}
409409

410-
BoostDecFloat16 opaqueDecFloat16ToBoostDecFloat16(const OpaqueDecFloat16& opaqueDecFloat16)
410+
BoostDecFloat16 opaqueDecFloat16ToBoostDecFloat16(
411+
StatusWrapper* statusWrapper, const OpaqueDecFloat16& opaqueDecFloat16)
411412
{
412-
return BoostDecFloat16{opaqueDecFloat16ToString(opaqueDecFloat16)};
413+
return BoostDecFloat16{opaqueDecFloat16ToString(statusWrapper, opaqueDecFloat16)};
413414
}
414415

415-
OpaqueDecFloat34 boostDecFloat34ToOpaqueDecFloat34(const BoostDecFloat34& boostDecFloat34)
416+
OpaqueDecFloat34 boostDecFloat34ToOpaqueDecFloat34(
417+
StatusWrapper* statusWrapper, const BoostDecFloat34& boostDecFloat34)
416418
{
417419
const auto decFloat34Util = client->getDecFloat34Util(statusWrapper);
418420
OpaqueDecFloat34 opaqueDecFloat34;
419421
decFloat34Util->fromString(statusWrapper, boostDecFloat34.str().c_str(), &opaqueDecFloat34);
420422
return opaqueDecFloat34;
421423
}
422424

423-
BoostDecFloat34 opaqueDecFloat34ToBoostDecFloat34(const OpaqueDecFloat34& opaqueDecFloat34)
425+
BoostDecFloat34 opaqueDecFloat34ToBoostDecFloat34(
426+
StatusWrapper* statusWrapper, const OpaqueDecFloat34& opaqueDecFloat34)
424427
{
425-
return BoostDecFloat34{opaqueDecFloat34ToString(opaqueDecFloat34)};
428+
return BoostDecFloat34{opaqueDecFloat34ToString(statusWrapper, opaqueDecFloat34)};
426429
}
427430
#endif
428431

@@ -574,7 +577,6 @@ namespace fbcpp::impl
574577

575578
private:
576579
Client* client;
577-
StatusWrapper* statusWrapper;
578580
};
579581
} // namespace fbcpp::impl
580582

src/fb-cpp/Row.h

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,15 @@ namespace fbcpp
7171
///
7272
/// @param message Pointer to the raw row data.
7373
/// @param descriptors Column descriptors.
74+
/// @param statusWrapper Status wrapper used for Firebird conversions.
7475
/// @param numericConverter Numeric converter.
7576
/// @param calendarConverter Calendar converter.
7677
///
77-
Row(const std::byte* message, const std::vector<Descriptor>& descriptors,
78+
Row(const std::byte* message, const std::vector<Descriptor>& descriptors, impl::StatusWrapper& statusWrapper,
7879
impl::NumericConverter& numericConverter, impl::CalendarConverter& calendarConverter)
7980
: message{message},
8081
descriptors{&descriptors},
82+
statusWrapper{&statusWrapper},
8183
numericConverter{&numericConverter},
8284
calendarConverter{&calendarConverter}
8385
{
@@ -435,7 +437,7 @@ namespace fbcpp
435437
{
436438
case DescriptorAdjustedType::TIME_TZ:
437439
return getCalendarConverter().opaqueTimeTzToTimeTz(
438-
*reinterpret_cast<const OpaqueTimeTz*>(&message[descriptor.offset]));
440+
getStatusWrapper(), *reinterpret_cast<const OpaqueTimeTz*>(&message[descriptor.offset]));
439441

440442
default:
441443
throwInvalidType("TimeTz", descriptor.adjustedType);
@@ -476,7 +478,7 @@ namespace fbcpp
476478
{
477479
case DescriptorAdjustedType::TIMESTAMP_TZ:
478480
return getCalendarConverter().opaqueTimestampTzToTimestampTz(
479-
*reinterpret_cast<const OpaqueTimestampTz*>(&message[descriptor.offset]));
481+
getStatusWrapper(), *reinterpret_cast<const OpaqueTimestampTz*>(&message[descriptor.offset]));
480482

481483
default:
482484
throwInvalidType("TimestampTz", descriptor.adjustedType);
@@ -558,7 +560,7 @@ namespace fbcpp
558560

559561
case DescriptorAdjustedType::INT128:
560562
return getNumericConverter().opaqueInt128ToString(
561-
*reinterpret_cast<const OpaqueInt128*>(data), descriptor.scale);
563+
getStatusWrapper(), *reinterpret_cast<const OpaqueInt128*>(data), descriptor.scale);
562564

563565
case DescriptorAdjustedType::FLOAT:
564566
return getNumericConverter().numberToString(*reinterpret_cast<const float*>(data));
@@ -577,19 +579,20 @@ namespace fbcpp
577579
*reinterpret_cast<const OpaqueTimestamp*>(data));
578580

579581
case DescriptorAdjustedType::TIME_TZ:
580-
return getCalendarConverter().opaqueTimeTzToString(*reinterpret_cast<const OpaqueTimeTz*>(data));
582+
return getCalendarConverter().opaqueTimeTzToString(
583+
getStatusWrapper(), *reinterpret_cast<const OpaqueTimeTz*>(data));
581584

582585
case DescriptorAdjustedType::TIMESTAMP_TZ:
583586
return getCalendarConverter().opaqueTimestampTzToString(
584-
*reinterpret_cast<const OpaqueTimestampTz*>(data));
587+
getStatusWrapper(), *reinterpret_cast<const OpaqueTimestampTz*>(data));
585588

586589
case DescriptorAdjustedType::DECFLOAT16:
587590
return getNumericConverter().opaqueDecFloat16ToString(
588-
*reinterpret_cast<const OpaqueDecFloat16*>(data));
591+
getStatusWrapper(), *reinterpret_cast<const OpaqueDecFloat16*>(data));
589592

590593
case DescriptorAdjustedType::DECFLOAT34:
591594
return getNumericConverter().opaqueDecFloat34ToString(
592-
*reinterpret_cast<const OpaqueDecFloat34*>(data));
595+
getStatusWrapper(), *reinterpret_cast<const OpaqueDecFloat34*>(data));
593596

594597
case DescriptorAdjustedType::STRING:
595598
return std::string{reinterpret_cast<const char*>(data + sizeof(std::uint16_t)),
@@ -934,13 +937,13 @@ namespace fbcpp
934937

935938
case DescriptorAdjustedType::DECFLOAT16:
936939
boostDecFloat16.emplace(getNumericConverter().opaqueDecFloat16ToBoostDecFloat16(
937-
*reinterpret_cast<const OpaqueDecFloat16*>(data)));
940+
getStatusWrapper(), *reinterpret_cast<const OpaqueDecFloat16*>(data)));
938941
data = reinterpret_cast<const std::byte*>(&boostDecFloat16.value());
939942
break;
940943

941944
case DescriptorAdjustedType::DECFLOAT34:
942945
boostDecFloat34.emplace(getNumericConverter().opaqueDecFloat34ToBoostDecFloat34(
943-
*reinterpret_cast<const OpaqueDecFloat34*>(data)));
946+
getStatusWrapper(), *reinterpret_cast<const OpaqueDecFloat34*>(data)));
944947
data = reinterpret_cast<const std::byte*>(&boostDecFloat34.value());
945948
break;
946949
#endif
@@ -1024,9 +1027,15 @@ namespace fbcpp
10241027
private:
10251028
const std::byte* message = nullptr;
10261029
const std::vector<Descriptor>* descriptors = nullptr;
1030+
impl::StatusWrapper* statusWrapper = nullptr;
10271031
impl::NumericConverter* numericConverter = nullptr;
10281032
impl::CalendarConverter* calendarConverter = nullptr;
10291033

1034+
impl::StatusWrapper* getStatusWrapper() const
1035+
{
1036+
return statusWrapper;
1037+
}
1038+
10301039
const std::vector<Descriptor>& getDescriptors() const
10311040
{
10321041
return *descriptors;

src/fb-cpp/RowSet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ using namespace fbcpp::impl;
3232

3333
RowSet::RowSet(Statement& statement, unsigned maxRows)
3434
: statusWrapper{statement.getAttachment().getClient()},
35-
numericConverter{statement.getAttachment().getClient(), &statusWrapper},
36-
calendarConverter{statement.getAttachment().getClient(), &statusWrapper}
35+
numericConverter{statement.getAttachment().getClient()},
36+
calendarConverter{statement.getAttachment().getClient()}
3737
{
3838
assert(statement.isValid());
3939
assert(statement.getResultSetHandle());

src/fb-cpp/RowSet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ namespace fbcpp
128128
{
129129
assert(index < count);
130130
const auto* data = buffer.data() + static_cast<std::size_t>(index) * messageLength;
131-
return Row{data, descriptors, numericConverter, calendarConverter};
131+
return Row{data, descriptors, statusWrapper, numericConverter, calendarConverter};
132132
}
133133

134134
///

src/fb-cpp/Statement.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ Statement::Statement(
3535
Attachment& attachment, Transaction& transaction, std::string_view sql, const StatementOptions& options)
3636
: attachment{&attachment},
3737
statusWrapper{attachment.getClient()},
38-
calendarConverter{attachment.getClient(), &statusWrapper},
39-
numericConverter{attachment.getClient(), &statusWrapper}
38+
calendarConverter{attachment.getClient()},
39+
numericConverter{attachment.getClient()}
4040
{
4141
assert(attachment.isValid());
4242
assert(transaction.isValid());
@@ -178,7 +178,7 @@ Statement::Statement(
178178
outMetadata.reset(statementHandle->getOutputMetadata(&statusWrapper));
179179
processMetadata(outMetadata, outDescriptors, outMessage);
180180

181-
outRow = Row(outMessage.data(), outDescriptors, numericConverter, calendarConverter);
181+
outRow = Row(outMessage.data(), outDescriptors, statusWrapper, numericConverter, calendarConverter);
182182
}
183183

184184
void Statement::free()

0 commit comments

Comments
 (0)