Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/fb-cpp/Attachment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,25 @@ void Attachment::dropDatabase()
disconnectOrDrop(true);
}

void Attachment::ping()
{
assert(isValid());

StatusWrapper statusWrapper{*client};

handle->ping(&statusWrapper);
}

void Attachment::resetSession()
{
assert(isValid());

StatusWrapper statusWrapper{*client};

handle->execute(
&statusWrapper, nullptr, 0, "alter session reset", SQL_DIALECT_V6, nullptr, nullptr, nullptr, nullptr);
}

bool Attachment::execute(Transaction& transaction, std::string_view sql, const StatementOptions& options)
{
Statement statement{*this, transaction, sql, options};
Expand Down
10 changes: 10 additions & 0 deletions src/fb-cpp/Attachment.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,16 @@ namespace fbcpp
///
void dropDatabase();

///
/// Checks if the connection to the database is alive.
///
void ping();

///
/// Resets the session state.
///
void resetSession();

///
/// Prepares and executes an SQL statement using the supplied transaction.
///
Expand Down
33 changes: 33 additions & 0 deletions src/test/Attachment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,4 +733,37 @@ BOOST_AUTO_TEST_CASE(isNotValidAfterDropDatabase)
BOOST_CHECK_EQUAL(attachment1.isValid(), false);
}

BOOST_AUTO_TEST_CASE(ping)
{
const auto database = getTempFile("Attachment-ping.fdb");
Attachment attachment{CLIENT, database, AttachmentOptions().setCreateDatabase(true).setForcedWrites(false)};
FbDropDatabase attachmentDrop{attachment};

BOOST_CHECK_NO_THROW(attachment.ping());
}

BOOST_AUTO_TEST_CASE(resetSession)
{
const auto database = getTempFile("Attachment-resetSession.fdb");
Attachment attachment{CLIENT, database, AttachmentOptions().setCreateDatabase(true).setForcedWrites(false)};
FbDropDatabase attachmentDrop{attachment};

Transaction transaction{attachment};
attachment.execute(transaction,
"select rdb$set_context('USER_SESSION', 'test_var', 'test_value') from rdb$database");
const auto valueBefore = attachment.queryScalar<std::string>(
transaction, "select rdb$get_context('USER_SESSION', 'test_var') from rdb$database");
BOOST_REQUIRE(valueBefore.has_value());
BOOST_CHECK_EQUAL(*valueBefore, "test_value");
transaction.commit();

attachment.resetSession();

Transaction transaction2{attachment};
const auto valueAfter = attachment.queryScalar<std::string>(
transaction2, "select rdb$get_context('USER_SESSION', 'test_var') from rdb$database");
BOOST_CHECK(!valueAfter.has_value());
transaction2.commit();
}

BOOST_AUTO_TEST_SUITE_END()
Loading