Skip to content

Commit eba317b

Browse files
committed
Add getOutputMessage() accessor to Statement
Symmetrical with the existing getInputMessage(), provides direct access to the raw output message buffer for consumers that need to read fetched row data at the raw byte level. Closes asfernandes#42 (REQ-2).
1 parent bb6f682 commit eba317b

2 files changed

Lines changed: 29 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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,27 @@ BOOST_AUTO_TEST_CASE(descriptorMetadataFields)
336336
BOOST_CHECK(inDescriptors[0].alias.empty());
337337
}
338338

339+
BOOST_AUTO_TEST_CASE(getOutputMessageMatchesMetadataLength)
340+
{
341+
const auto database = getTempFile("Statement-getOutputMessageMatchesMetadataLength.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+
// After fetch, the output message buffer contains the fetched data.
353+
BOOST_REQUIRE(stmt.execute(transaction));
354+
BOOST_CHECK_EQUAL(stmt.getInt32(0).value(), 42);
355+
356+
// The buffer reference should remain the same object.
357+
BOOST_CHECK_EQUAL(&outMsg, &stmt.getOutputMessage());
358+
}
359+
339360
BOOST_AUTO_TEST_SUITE_END()
340361

341362

0 commit comments

Comments
 (0)