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

Added prepared_statement::execute tests

Fixed bug in prepare_statement (was not reading metadata packets after
the prepared statement response)
Added stringize()
Now execute() explicitly checks the number of parameters and issues an
error if they don't match the expected count
This commit is contained in:
ruben
2020-02-05 12:44:33 +00:00
parent 87b6e65a32
commit e0f83bf1c1
7 changed files with 129 additions and 19 deletions

View File

@@ -0,0 +1,56 @@
/*
* execute_statement.cpp
*
* Created on: Feb 5, 2020
* Author: ruben
*/
#include "integration_test_common.hpp"
#include <forward_list>
using namespace mysql::test;
using mysql::value;
using mysql::Error;
namespace
{
struct ExecuteStatementTest : public IntegTestAfterHandshake
{
};
TEST_F(ExecuteStatementTest, IteratorsSyncErrc_OkNoParams)
{
std::forward_list<value> params;
auto stmt = conn.prepare_statement("SELECT * FROM empty_table");
auto result = stmt.execute(params.begin(), params.end(), errc, info);
validate_no_error();
EXPECT_TRUE(result.valid());
}
TEST_F(ExecuteStatementTest, IteratorsSyncErrc_OkWithParams)
{
std::forward_list<value> params { value("item"), value(42) };
auto stmt = conn.prepare_statement("SELECT * FROM empty_table WHERE id IN (?, ?)");
auto result = stmt.execute(params.begin(), params.end(), errc, info);
validate_no_error();
EXPECT_TRUE(result.valid());
}
TEST_F(ExecuteStatementTest, IteratorsSyncErrc_Error)
{
std::forward_list<value> params { value("item") };
auto stmt = conn.prepare_statement("SELECT * FROM empty_table WHERE id IN (?, ?)");
auto result = stmt.execute(params.begin(), params.end(), errc, info);
validate_sync_fail(Error::wrong_num_params, {"param", "2", "1", "statement", "execute"});
EXPECT_FALSE(result.valid());
}
// prepared_statement::execute
// OK, no params
// OK, with params
// OK, select, insert, update, delete
// Error, wrong number of parameters
// Collection version
}