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

Added connection::prepare_statement sync exc

This commit is contained in:
ruben
2020-02-05 11:38:38 +00:00
parent e6f6e13060
commit 87b6e65a32
3 changed files with 32 additions and 6 deletions

View File

@@ -123,6 +123,7 @@ public:
async_query(std::string_view query_string, CompletionToken&& token);
prepared_statement<Stream> prepare_statement(std::string_view statement, error_code&, error_info&);
prepared_statement<Stream> prepare_statement(std::string_view statement);
};
/// A connection to MySQL over TCP.

View File

@@ -132,5 +132,18 @@ mysql::prepared_statement<Stream> mysql::connection<Stream>::prepare_statement(
return res;
}
template <typename Stream>
mysql::prepared_statement<Stream> mysql::connection<Stream>::prepare_statement(
std::string_view statement
)
{
mysql::prepared_statement<Stream> res;
error_code err;
error_info info;
detail::prepare_statement(channel_, statement, err, info, res);
detail::check_error_code(err, info);
return res;
}
#endif

View File

@@ -18,11 +18,12 @@ struct PrepareStatementTest : public IntegTestAfterHandshake
{
};
// sync errc
TEST_F(PrepareStatementTest, SyncErrc_OkNoParams)
{
auto stmt = conn.prepare_statement("SELECT * FROM empty_table", errc, info);
validate_no_error();
EXPECT_TRUE(stmt.valid());
ASSERT_TRUE(stmt.valid());
EXPECT_GT(stmt.id(), 0);
EXPECT_EQ(stmt.num_params(), 0);
}
@@ -43,12 +44,23 @@ TEST_F(PrepareStatementTest, SyncErrc_Error)
EXPECT_FALSE(stmt.valid());
}
// sync exc
TEST_F(PrepareStatementTest, SyncExc_Ok)
{
auto stmt = conn.prepare_statement("SELECT * FROM empty_table WHERE id = ?");
ASSERT_TRUE(stmt.valid());
EXPECT_GT(stmt.id(), 0);
EXPECT_EQ(stmt.num_params(), 1);
}
TEST_F(PrepareStatementTest, SyncExc_Err)
{
validate_sync_fail([this] {
conn.prepare_statement("SELECT * FROM bad_table WHERE id IN (?, ?)");
}, Error::no_such_table, {"table", "doesn't exist", "bad_table"});
}
// prepared_statement::execute
// OK, no params
// OK, with params
// OK, select, insert, update, delete
// Error, wrong number of parameters
// resultset::fetch_xxxx: repeat the same tests as in query
// Cover no params, with params, select, insert, update, delete, with table/fields as params
// statements life cycle