mirror of
https://github.com/boostorg/mysql.git
synced 2026-02-14 00:42:53 +00:00
94 lines
2.7 KiB
C++
94 lines
2.7 KiB
C++
//
|
|
// Copyright (c) 2019-2022 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
|
|
//
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
//
|
|
|
|
#include <boost/mysql/statement_base.hpp>
|
|
#include <boost/mysql/tcp.hpp>
|
|
|
|
#include <boost/asio/ip/tcp.hpp>
|
|
#include <boost/test/tools/interface.hpp>
|
|
|
|
#include "integration_test_common.hpp"
|
|
#include "streams.hpp"
|
|
#include "tcp_network_fixture.hpp"
|
|
|
|
using namespace boost::mysql::test;
|
|
using boost::mysql::errc;
|
|
using boost::mysql::error_code;
|
|
using boost::mysql::no_statement_params;
|
|
using boost::mysql::tcp_resultset;
|
|
using boost::mysql::tcp_statement;
|
|
|
|
namespace {
|
|
|
|
BOOST_AUTO_TEST_SUITE(test_prepare_statement)
|
|
|
|
BOOST_MYSQL_NETWORK_TEST(ok_no_params, network_fixture)
|
|
{
|
|
setup_and_connect(sample.net);
|
|
conn->prepare_statement("SELECT * FROM empty_table", *stmt).validate_no_error();
|
|
BOOST_TEST_REQUIRE(stmt->base().valid());
|
|
BOOST_TEST(stmt->base().id() > 0u);
|
|
BOOST_TEST(stmt->base().num_params() == 0u);
|
|
}
|
|
|
|
BOOST_MYSQL_NETWORK_TEST(ok_with_params, network_fixture)
|
|
{
|
|
setup_and_connect(sample.net);
|
|
conn->prepare_statement("SELECT * FROM empty_table WHERE id IN (?, ?)", *stmt)
|
|
.validate_no_error();
|
|
BOOST_TEST_REQUIRE(stmt->base().valid());
|
|
BOOST_TEST(stmt->base().id() > 0u);
|
|
BOOST_TEST(stmt->base().num_params() == 2u);
|
|
}
|
|
|
|
BOOST_MYSQL_NETWORK_TEST(invalid_statement, network_fixture)
|
|
{
|
|
setup_and_connect(sample.net);
|
|
conn->prepare_statement("SELECT * FROM bad_table WHERE id IN (?, ?)", *stmt)
|
|
.validate_error(errc::no_such_table, {"table", "doesn't exist", "bad_table"});
|
|
}
|
|
|
|
BOOST_FIXTURE_TEST_CASE(move_ctor, tcp_network_fixture)
|
|
{
|
|
connect();
|
|
|
|
// Get a valid prepared statement and perform a move construction
|
|
tcp_statement s1;
|
|
conn.prepare_statement("SELECT * FROM empty_table", s1);
|
|
|
|
// Move construct
|
|
tcp_statement s2(std::move(s1));
|
|
BOOST_TEST_REQUIRE(s2.valid());
|
|
|
|
// We can use the 2nd stmt
|
|
tcp_resultset result;
|
|
s2.execute(no_statement_params, result);
|
|
BOOST_TEST(result.read_all().empty());
|
|
}
|
|
|
|
BOOST_FIXTURE_TEST_CASE(move_assignment, tcp_network_fixture)
|
|
{
|
|
connect();
|
|
|
|
// Get a valid resultset_base and perform a move assignment
|
|
tcp_statement s1, s2;
|
|
conn.prepare_statement("SELECT * FROM empty_table", s1);
|
|
conn.prepare_statement("SELECT 1", s2);
|
|
|
|
s2 = std::move(s1);
|
|
BOOST_TEST_REQUIRE(s2.valid());
|
|
|
|
// We can use the 2nd stmt
|
|
tcp_resultset result;
|
|
s2.execute(no_statement_params, result);
|
|
BOOST_TEST(result.read_all().empty());
|
|
}
|
|
|
|
BOOST_AUTO_TEST_SUITE_END() // test_prepare_statement
|
|
|
|
} // namespace
|