Skip to content

Commit 8df5569

Browse files
authored
Add getOutputMessage() accessor to Statement (#45)
1 parent bb6f682 commit 8df5569

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

src/fb-cpp/Statement.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,14 @@ namespace fbcpp
408408
return outMetadata;
409409
}
410410

411+
///
412+
/// @brief Provides direct access to the raw output message buffer.
413+
///
414+
std::vector<std::byte>& getOutputMessage() noexcept
415+
{
416+
return outMessage;
417+
}
418+
411419
///
412420
/// @brief Returns the type classification reported by the server.
413421
///

src/test/Statement.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,29 @@ BOOST_AUTO_TEST_CASE(descriptorMetadataFields)
336336
BOOST_CHECK(inDescriptors[0].alias.empty());
337337
}
338338

339+
BOOST_AUTO_TEST_CASE(getOutputMessageContainsFetchedValueAtMetadataOffset)
340+
{
341+
const auto database = getTempFile("Statement-getOutputMessageContainsFetchedValueAtMetadataOffset.fdb");
342+
343+
Attachment attachment{CLIENT, database, AttachmentOptions().setCreateDatabase(true)};
344+
FbDropDatabase attachmentDrop{attachment};
345+
346+
Transaction transaction{attachment};
347+
Statement stmt{attachment, transaction, "select 42 from rdb$database"};
348+
349+
auto& outMsg = stmt.getOutputMessage();
350+
BOOST_CHECK(!outMsg.empty());
351+
352+
const auto valueOffset = stmt.getOutputDescriptors()[0].offset;
353+
354+
BOOST_REQUIRE(stmt.execute(transaction));
355+
BOOST_CHECK_EQUAL(stmt.getInt32(0).value(), 42);
356+
357+
BOOST_REQUIRE_GE(outMsg.size(), valueOffset + sizeof(std::int32_t));
358+
const auto* data = &outMsg[valueOffset];
359+
BOOST_CHECK_EQUAL(*reinterpret_cast<const std::int32_t*>(data), 42);
360+
}
361+
339362
BOOST_AUTO_TEST_SUITE_END()
340363

341364

0 commit comments

Comments
 (0)