Public Member Functions | Private Attributes

ASql::MySQL::Connection Class Reference

Connection to a MySQL database. More...

#include <mysql.hpp>

Inheritance diagram for ASql::MySQL::Connection:
ASql::ConnectionPar< MySQL::Statement > ASql::Connection

List of all members.

Public Member Functions

 Connection (const char *host, const char *user, const char *passwd, const char *db, unsigned int port, const char *unix_socket, unsigned long client_flag, const char *const charset="latin1", const int threads_=1)
 Complete Constructor.
 Connection (const int threads_=1)
 Incomplete Constructor.
 ~Connection ()
void connect (const char *host, const char *user, const char *passwd, const char *db, unsigned int port, const char *unix_socket, unsigned long client_flag, const char *const charset="latin1")
 Connect to a MySQL server.
void getFoundRows (unsigned long long *const &rows, const unsigned int id)
 Returns the number of rows found in the last query. Designed for use with SQL_CALC_FOUND_ROWS in the query itself.
MYSQL & connection (unsigned int id)
void commit (const unsigned int thread=0)
void rollback (const unsigned int thread=0)

Private Attributes

boost::scoped_array< MYSQL > m_connection
 Actual MySQL C API connection object.
boost::scoped_array< MYSQL_STMT * > foundRowsStatement
 Pointer to the statement used to return the number of rows found.
boost::scoped_array< MYSQL_BIND > foundRowsBinding
 Bind object for storing the total number of results from a query.
bool m_initialized

Detailed Description

Connection to a MySQL database.

Definition at line 42 of file mysql.hpp.


Constructor & Destructor Documentation

ASql::MySQL::Connection::Connection ( const char *  host,
const char *  user,
const char *  passwd,
const char *  db,
unsigned int  port,
const char *  unix_socket,
unsigned long  client_flag,
const char *const   charset = "latin1",
const int  threads_ = 1 
) [inline]

Complete Constructor.

Parameters:
[in]hostThe value of host may be either a hostname or an IP address. If host is NULL or the string "localhost", a connection to the local host is assumed. For Windows, the client connects using a shared-memory connection, if the server has shared-memory connections enabled. Otherwise, TCP/IP is used. For Unix, the client connects using a Unix socket file.
[in]userThe user parameter contains the user's MySQL login ID. If user is NULL or the empty string "", the current user is assumed. Under Unix, this is the current login name. Under Windows ODBC, the current username must be specified explicitly.
[in]passwdThe passwd parameter contains the password for user. If passwd is NULL, only entries in the user table for the user that have a blank (empty) password field are checked for a match. This allows the database administrator to set up the MySQL privilege system in such a way that users get different privileges depending on whether they have specified a password.
[in]dbdb is the database name. If db is not NULL, the connection sets the default database to this value.
[in]portIf port is not 0, the value is used as the port number for the TCP/IP connection. Note that the host parameter determines the type of the connection.
[in]unix_socketIf unix_socket is not NULL, the string specifies the socket or named pipe that should be used. Note that the host parameter determines the type of the connection.
[in]client_flagThe value of client_flag is usually 0, but can be set to a combination of the following flags to enable certain features. See the mysql c api reference manual for more details.
[in]charsetNull terminated string representation of desired connection character set (latin1, utf8, ...)
[in]threads_Number of threads to have for simultaneous queries. The higher this number is the more concurrent SQL requeries can be processed.

Definition at line 77 of file mysql.hpp.

References connect().

ASql::MySQL::Connection::Connection ( const int  threads_ = 1 ) [inline]

Incomplete Constructor.

Parameters:
[in]threads_Number of threads to have for simultaneous queries. The higher this number is the more concurrent SQL requeries can be processed.

Reimplemented from ASql::Connection.

Definition at line 88 of file mysql.hpp.

ASql::MySQL::Connection::~Connection (  )

Definition at line 65 of file mysql.cpp.


Member Function Documentation

void ASql::MySQL::Connection::commit ( const unsigned int  thread = 0 ) [inline, virtual]

Implements ASql::Connection.

Definition at line 119 of file mysql.hpp.

References m_connection.

void ASql::MySQL::Connection::connect ( const char *  host,
const char *  user,
const char *  passwd,
const char *  db,
unsigned int  port,
const char *  unix_socket,
unsigned long  client_flag,
const char *const   charset = "latin1" 
)

Connect to a MySQL server.

Parameters:
[in]hostThe value of host may be either a hostname or an IP address. If host is NULL or the string "localhost", a connection to the local host is assumed. For Windows, the client connects using a shared-memory connection, if the server has shared-memory connections enabled. Otherwise, TCP/IP is used. For Unix, the client connects using a Unix socket file.
[in]userThe user parameter contains the user's MySQL login ID. If user is NULL or the empty string "", the current user is assumed. Under Unix, this is the current login name. Under Windows ODBC, the current username must be specified explicitly.
[in]passwdThe passwd parameter contains the password for user. If passwd is NULL, only entries in the user table for the user that have a blank (empty) password field are checked for a match. This allows the database administrator to set up the MySQL privilege system in such a way that users get different privileges depending on whether they have specified a password.
[in]dbdb is the database name. If db is not NULL, the connection sets the default database to this value.
[in]portIf port is not 0, the value is used as the port number for the TCP/IP connection. Note that the host parameter determines the type of the connection.
[in]unix_socketIf unix_socket is not NULL, the string specifies the socket or named pipe that should be used. Note that the host parameter determines the type of the connection.
[in]client_flagThe value of client_flag is usually 0, but can be set to a combination of the following flags to enable certain features. See the mysql c api reference manual for more details.
[in]charsetNull terminated string representation of desired connection character set (latin1, utf8, ...)

Definition at line 25 of file mysql.cpp.

References foundRowsBinding, foundRowsStatement, m_connection, m_initialized, and ASql::Connection::threads().

Referenced by Connection().

MYSQL& ASql::MySQL::Connection::connection ( unsigned int  id ) [inline]

Definition at line 117 of file mysql.hpp.

References m_connection.

void ASql::MySQL::Connection::getFoundRows ( unsigned long long *const &  rows,
const unsigned int  id 
)

Returns the number of rows found in the last query. Designed for use with SQL_CALC_FOUND_ROWS in the query itself.

Parameters:
rowsA reference to a pointer to the integer to write the value to.

Definition at line 77 of file mysql.cpp.

void ASql::MySQL::Connection::rollback ( const unsigned int  thread = 0 ) [inline, virtual]

Implements ASql::Connection.

Definition at line 120 of file mysql.hpp.

References m_connection.


Member Data Documentation

boost::scoped_array<MYSQL_BIND> ASql::MySQL::Connection::foundRowsBinding [private]

Bind object for storing the total number of results from a query.

Definition at line 58 of file mysql.hpp.

Referenced by connect().

boost::scoped_array<MYSQL_STMT*> ASql::MySQL::Connection::foundRowsStatement [private]

Pointer to the statement used to return the number of rows found.

Definition at line 53 of file mysql.hpp.

Referenced by connect().

boost::scoped_array<MYSQL> ASql::MySQL::Connection::m_connection [private]

Actual MySQL C API connection object.

Definition at line 48 of file mysql.hpp.

Referenced by commit(), connect(), connection(), and rollback().

Definition at line 60 of file mysql.hpp.

Referenced by connect().


The documentation for this class was generated from the following files: