2
0
mirror of https://github.com/boostorg/mysql.git synced 2026-02-14 12:52:17 +00:00

close_statement and stmt lifecycle

This commit is contained in:
Ruben Perez
2022-10-15 14:26:55 +02:00
parent 8874a87ec7
commit ab6eb7b168
3 changed files with 218 additions and 191 deletions

View File

@@ -9,28 +9,28 @@
using namespace boost::mysql::test;
namespace {
BOOST_AUTO_TEST_SUITE(test_close_statement)
BOOST_MYSQL_NETWORK_TEST(existing_or_closed_statement, network_fixture)
BOOST_MYSQL_NETWORK_TEST(success, network_fixture)
{
setup_and_connect(sample.net);
// Prepare a statement
auto stmt = conn->prepare_statement("SELECT * FROM empty_table").get();
conn->prepare_statement("SELECT * FROM empty_table", *stmt).validate_no_error();
// Verify it works fine
auto exec_result = stmt->execute_container({}).get();
exec_result->read_all().validate_no_error(); // clean all packets sent for this execution
stmt->execute_collection({}, *result).validate_no_error();
result->read_all().validate_no_error(); // clean all packets sent for this execution
// Close the statement
stmt->close().validate_no_error();
// Close it again
stmt->close().validate_no_error();
// Verify close took effect
stmt->execute_container({}).validate_error(
boost::mysql::errc::unknown_stmt_handler, {"unknown prepared statement"});
// The statement is no longer valid
BOOST_TEST(!stmt->base().valid());
}
BOOST_AUTO_TEST_SUITE_END() // test_close_statement
BOOST_AUTO_TEST_SUITE_END() // test_close_statement
} // namespace