The Battle for Wesnoth  1.15.1+dev
Classes | Macros | Functions
mysql_prepared_statement.ipp File Reference
#include <array>
#include <utility>
#include <memory>
#include <string>
#include <string.h>
#include <boost/scope_exit.hpp>
#include <mysql/mysql.h>
#include "exceptions.hpp"
Include dependency graph for mysql_prepared_statement.ipp:

Go to the source code of this file.

Classes

struct  sql_error
 

Macros

#define MYSQL_PREPARED_STATEMENT_IPP
 
#define BOOST_SCOPE_EXIT_CONFIG_USE_LAMBDAS
 

Functions

static MYSQL_BIND make_bind (const std::string &str, my_bool *is_null=0)
 
static MYSQL_BIND make_bind (char *str, std::size_t *len, my_bool *is_null=0)
 
static MYSQL_BIND make_bind (int &i, my_bool *is_null=0)
 
static MYSQL_BIND make_bind (unsigned int &i, my_bool *is_null=0)
 
template<typename... Args>
constexpr auto make_binds (Args &&... args) -> std::array< MYSQL_BIND, sizeof...(Args)>
 
template<typename T >
fetch_result (MYSQL_STMT *stmt, const std::string &sql)
 
template<>
std::string fetch_result< std::string > (MYSQL_STMT *stmt, const std::string &sql)
 
template<typename T >
fetch_result_long_internal_ (MYSQL_STMT *stmt, const std::string &sql)
 
template<>
int fetch_result< int > (MYSQL_STMT *stmt, const std::string &sql)
 
template<>
unsigned int fetch_result< unsigned int > (MYSQL_STMT *stmt, const std::string &sql)
 
template<>
bool fetch_result< bool > (MYSQL_STMT *stmt, const std::string &sql)
 
template<>
void fetch_result< void > (MYSQL_STMT *, const std::string &)
 
template<typename R , typename... Args>
prepared_statement (MYSQL *conn, const std::string &sql, Args &&... args)
 Execute an sql query using mysql prepared statements API This function can convert its arguments and results to appropriate MYSQL_BIND structures automatically based on their C++ type though each type requires explicit support. More...
 

Macro Definition Documentation

◆ BOOST_SCOPE_EXIT_CONFIG_USE_LAMBDAS

#define BOOST_SCOPE_EXIT_CONFIG_USE_LAMBDAS

Definition at line 24 of file mysql_prepared_statement.ipp.

◆ MYSQL_PREPARED_STATEMENT_IPP

#define MYSQL_PREPARED_STATEMENT_IPP

Definition at line 16 of file mysql_prepared_statement.ipp.

Function Documentation

◆ fetch_result()

template<typename T >
T fetch_result ( MYSQL_STMT *  stmt,
const std::string &  sql 
)

Referenced by make_binds().

◆ fetch_result< bool >()

template<>
bool fetch_result< bool > ( MYSQL_STMT *  stmt,
const std::string &  sql 
)

Definition at line 169 of file mysql_prepared_statement.ipp.

References make_bind(), and sql_error::sql_error().

◆ fetch_result< int >()

template<>
int fetch_result< int > ( MYSQL_STMT *  stmt,
const std::string &  sql 
)

Definition at line 159 of file mysql_prepared_statement.ipp.

◆ fetch_result< std::string >()

template<>
std::string fetch_result< std::string > ( MYSQL_STMT *  stmt,
const std::string &  sql 
)

Definition at line 97 of file mysql_prepared_statement.ipp.

References make_bind(), and sql_error::sql_error().

◆ fetch_result< unsigned int >()

template<>
unsigned int fetch_result< unsigned int > ( MYSQL_STMT *  stmt,
const std::string &  sql 
)

Definition at line 164 of file mysql_prepared_statement.ipp.

◆ fetch_result< void >()

template<>
void fetch_result< void > ( MYSQL_STMT *  ,
const std::string &   
)

Definition at line 192 of file mysql_prepared_statement.ipp.

◆ fetch_result_long_internal_()

template<typename T >
T fetch_result_long_internal_ ( MYSQL_STMT *  stmt,
const std::string &  sql 
)

Definition at line 136 of file mysql_prepared_statement.ipp.

References make_bind(), and sql_error::sql_error().

◆ make_bind() [1/4]

static MYSQL_BIND make_bind ( const std::string &  str,
my_bool *  is_null = 0 
)
static

◆ make_bind() [2/4]

static MYSQL_BIND make_bind ( char *  str,
std::size_t *  len,
my_bool *  is_null = 0 
)
static

Definition at line 55 of file mysql_prepared_statement.ipp.

◆ make_bind() [3/4]

static MYSQL_BIND make_bind ( int &  i,
my_bool *  is_null = 0 
)
static

Definition at line 68 of file mysql_prepared_statement.ipp.

References i.

◆ make_bind() [4/4]

static MYSQL_BIND make_bind ( unsigned int &  i,
my_bool *  is_null = 0 
)
static

Definition at line 79 of file mysql_prepared_statement.ipp.

References i.

◆ make_binds()

template<typename... Args>
constexpr auto make_binds ( Args &&...  args) -> std::array<MYSQL_BIND, sizeof...(Args)>

Definition at line 90 of file mysql_prepared_statement.ipp.

References fetch_result(), and make_bind().

Referenced by prepared_statement().

◆ prepared_statement()

template<typename R , typename... Args>
R prepared_statement ( MYSQL *  conn,
const std::string &  sql,
Args &&...  args 
)

Execute an sql query using mysql prepared statements API This function can convert its arguments and results to appropriate MYSQL_BIND structures automatically based on their C++ type though each type requires explicit support.

For now only ints and std::strings are supported. Setting return type to bool causes this function to do a test query and return true if there is any data in result set, false otherwise

Definition at line 206 of file mysql_prepared_statement.ipp.

References make_binds(), and sql_error::sql_error().