matador::connection Class Reference

The connection class represents a connection to a database. More...

#include <connection.hpp>

Public Member Functions

 connection ()=default
 Creates an empty connection.
 
 connection (std::shared_ptr< basic_sql_logger > sqllogger)
 Creates an empty connection.
 
 connection (const std::string &dns)
 Creates a database connection from a connection string.
 
 connection (const std::string &dns, std::shared_ptr< basic_sql_logger > sql_logger)
 Creates a database connection from a connection string.
 
 connection (const connection &x)
 
 connection (connection &&x) noexcept
 
connectionoperator= (const connection &x)
 
connectionoperator= (connection &&x) noexcept
 
void connect (const std::string &dns)
 Opens the sql for the given dns.
 
void connect ()
 Opens the sql.
 
void reconnect ()
 
bool is_connected () const
 Returns true if sql is open.
 
void disconnect ()
 Closes the sql.
 
void begin ()
 Executes the BEGIN TRANSACTION sql command.
 
void commit ()
 Executes the COMMIT TRANSACTION sql command.
 
void rollback ()
 Executes the ROLLBACK TRANSACTION sql command.
 
std::string type () const
 Return the database type of the connection.
 
version client_version () const
 Return the version string of the current database type.
 
version server_version () const
 Return the version string of the current database type.
 
void execute (const std::string &stmt)
 Execute a sql string statement with retrieving any result.
 
bool exists (const std::string &table_name) const
 returns true if a table with given name exists.
 
std::vector< fielddescribe (const std::string &table) const
 Retrieve a field description list of a table.
 
basic_dialectdialect ()
 Get the underlying sql dialect object.
 
bool is_valid () const
 Returns true if connection is valid.
 
void enable_log ()
 
void disable_log ()
 
bool is_log_enabled () const
 

Friends

template<class T >
class query
 

Detailed Description

The connection class represents a connection to a database.

Constructor & Destructor Documentation

◆ connection() [1/4]

matador::connection::connection ( const std::string &  dns)
explicit

Creates a database connection from a connection string.

Parameters
dnsThe database connection string

◆ connection() [2/4]

matador::connection::connection ( const std::string &  dns,
std::shared_ptr< basic_sql_logger sql_logger 
)

Creates a database connection from a connection string.

Parameters
dnsThe database connection string
sql_loggerThe logger handler to write sql log messages to

◆ connection() [3/4]

matador::connection::connection ( const connection x)

Copies a given connection

Parameters
xThe connection to copy

◆ connection() [4/4]

matador::connection::connection ( connection &&  x)
noexcept

Copy moves a given connection

Parameters
xThe connection to copy move

Member Function Documentation

◆ client_version()

version matador::connection::client_version ( ) const

Return the version string of the current database type.

Returns
Version string of the current database type

◆ connect() [1/2]

void matador::connection::connect ( )

Opens the sql.

Opens the sql. If sql couldn't be opened an exception is thrown.

◆ connect() [2/2]

void matador::connection::connect ( const std::string &  dns)

Opens the sql for the given dns.

Opens the sql. If sql couldn't be opened an exception is thrown.

◆ describe()

std::vector< field > matador::connection::describe ( const std::string &  table) const

Retrieve a field description list of a table.

Parameters
tableThe name of the requested table
Returns
A list of fields

◆ dialect()

basic_dialect * matador::connection::dialect ( )

Get the underlying sql dialect object.

Returns
Sql dialect object.

◆ disable_log()

void matador::connection::disable_log ( )

Disable console log of sql statements

◆ disconnect()

void matador::connection::disconnect ( )

Closes the sql.

Closes the sql.

◆ enable_log()

void matador::connection::enable_log ( )

Enable console log of sql statements

◆ execute()

void matador::connection::execute ( const std::string &  stmt)
inline

Execute a sql string statement with retrieving any result.

Parameters
stmtThe statement to be executed

◆ exists()

bool matador::connection::exists ( const std::string &  table_name) const

returns true if a table with given name exists.

Parameters
table_nameName of table to be checked
Returns
True if table exists.

◆ is_connected()

bool matador::connection::is_connected ( ) const

Returns true if sql is open.

Returns true if sql is open

Returns
True on open sql.

◆ is_log_enabled()

bool matador::connection::is_log_enabled ( ) const

Returns true if logging is enabled.

Returns
True if logging is enabled

◆ is_valid()

bool matador::connection::is_valid ( ) const

Returns true if connection is valid.

Returns true if connection is valid, i.e. the database connection string is set correctly

Returns
True if connection is valid

◆ operator=() [1/2]

connection & matador::connection::operator= ( connection &&  x)
noexcept

Assigns moves from the given connection

Parameters
xThe connection to assign move
Returns
The reference to the assigned connection

◆ operator=() [2/2]

connection & matador::connection::operator= ( const connection x)

Assigns from the given connection

Parameters
xThe connection to assign
Returns
The reference to the assigned connection

◆ reconnect()

void matador::connection::reconnect ( )

Reconnect to the database. This means to close and open the connection.

◆ server_version()

version matador::connection::server_version ( ) const

Return the version string of the current database type.

Returns
Version string of the current database type

◆ type()

std::string matador::connection::type ( ) const

Return the database type of the connection.

Returns the database type of the connection which is currently one of

  • mssql
  • mysql
  • sqlite
  • postgressql
Returns
The database type string

The documentation for this class was generated from the following file:
  • matador/sql/connection.hpp