2
0
mirror of https://github.com/boostorg/mysql.git synced 2026-01-29 19:52:11 +00:00

SSL/TLS and row reading rework (v0.2.0)

* SSL/TLS rework
* Unified connection object
* New prepared_statement::execute interface
* New resultset::read_one mechanic
* Unified row object
* null_t type
* Travis to GitHub actions migration
* Integration test rework
This commit is contained in:
Ruben Perez
2022-03-21 16:09:48 +01:00
parent 981c2b34d7
commit 86e0eacd6a
267 changed files with 6589 additions and 5634 deletions

View File

@@ -1,14 +1,18 @@
//
// Copyright (c) 2019-2021 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
// 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/connection.hpp"
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/ssl/context.hpp>
#include <boost/mysql.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/system/system_error.hpp>
#include <iostream>
#include <string>
/**
* For this example, we will be using the 'boost_mysql_examples' database.
@@ -20,35 +24,43 @@
void main_impl(int argc, char** argv)
{
if (argc != 3)
if (argc != 4)
{
std::cerr << "Usage: " << argv[0] << " <username> <password>\n";
std::cerr << "Usage: " << argv[0] << " <username> <password> <server-hostname>\n";
exit(1);
}
//[tutorial_connection
// The execution context, required to run I/O operations
boost::asio::io_context ctx;
boost::mysql::tcp_connection conn (ctx.get_executor());
// The SSL context, required to establish TLS connections.
// The default SSL options are good enough for us at this point.
boost::asio::ssl::context ssl_ctx (boost::asio::ssl::context::tls_client);
// The object defining the connection to the MySQL server.
boost::mysql::tcp_ssl_connection conn (ctx.get_executor(), ssl_ctx);
//]
//[tutorial_connect
boost::asio::ip::tcp::endpoint ep (
boost::asio::ip::address_v4::loopback(), // host
boost::mysql::default_port // port
);
// Resolve the hostname to get a collection of endpoints
boost::asio::ip::tcp::resolver resolver (ctx.get_executor());
auto endpoints = resolver.resolve(argv[3], boost::mysql::default_port_string);
// The username and password to use
boost::mysql::connection_params params (
argv[1], // username
argv[2] // password
);
conn.connect(ep, params);
// Connect to the server using the first endpoint returned by the resolver
conn.connect(*endpoints.begin(), params);
//]
//[tutorial_query
const char* sql = "SELECT \"Hello world!\"";
boost::mysql::tcp_resultset result = conn.query(sql);
boost::mysql::tcp_ssl_resultset result = conn.query(sql);
//]
//[tutorial_read
@@ -56,7 +68,9 @@ void main_impl(int argc, char** argv)
//]
//[tutorial_values
std::cout << employees.at(0).values().at(0).get<boost::string_view>();
const boost::mysql::row& first_row = employees.at(0);
boost::mysql::value first_value = first_row.values().at(0);
std::cout << first_value << std::endl;
//]
//[tutorial_close