fastcgi++
Public Member Functions | Static Public Attributes | Protected Attributes | 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)
 ~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")
void getFoundRows (unsigned long long *const &rows, const unsigned int id)
MYSQL & connection (unsigned int id)
void commit (const unsigned int thread=0)
void rollback (const unsigned int thread=0)
int queriesSize () const
 Returns the number of queued queries.
void start ()
 Start all threads of the handler.
void terminate ()
 Terminate all thread of the handler.
void queue (Transaction< MySQL::Statement > &transaction, int instance)
 Queue up a transaction for completion.
void queue (MySQL::Statement *const &statement, QueryPar &query, int instance)
int threads () const
 Returns the number of threads.
bool running () const
 Return true if the handler is running.

Static Public Attributes

static const bool s_false

Protected Attributes

const int maxThreads
 Number of threads to pool for simultaneous queries.
boost::mutex threadsMutex
boost::condition_variable threadsChanged
int m_threads
boost::scoped_array
< boost::condition_variable > 
wakeUp
boost::mutex terminateMutex
bool terminateBool

Private Attributes

boost::scoped_array< MYSQL > m_connection
boost::scoped_array< MYSQL_STMT * > foundRowsStatement
boost::scoped_array< MYSQL_BIND > foundRowsBinding
bool m_initialized

Detailed Description

Connection to a MySQL database.

Definition at line 41 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 76 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 87 of file mysql.hpp.

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

Definition at line 66 of file mysql.cpp.


Member Function Documentation

void ASql::MySQL::Connection::commit ( const unsigned int  thread = 0)
inlinevirtual

Implements ASql::Connection.

Definition at line 118 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 26 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 116 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 78 of file mysql.cpp.

int ASql::ConnectionPar< MySQL::Statement >::queriesSize ( ) const
inherited

Returns the number of queued queries.

void ASql::ConnectionPar< MySQL::Statement >::queue ( Transaction< MySQL::Statement > &  transaction,
int  instance 
)
inherited

Queue up a transaction for completion.

void ASql::ConnectionPar< MySQL::Statement >::queue ( MySQL::Statement *const &  statement,
QueryPar query,
int  instance 
)
inlineinherited
void ASql::MySQL::Connection::rollback ( const unsigned int  thread = 0)
inlinevirtual

Implements ASql::Connection.

Definition at line 119 of file mysql.hpp.

References m_connection.

bool ASql::Connection::running ( ) const
inlineinherited

Return true if the handler is running.

Definition at line 119 of file asql.hpp.

References ASql::Connection::m_threads.

void ASql::ConnectionPar< MySQL::Statement >::start ( )
inherited

Start all threads of the handler.

void ASql::ConnectionPar< MySQL::Statement >::terminate ( )
inherited

Terminate all thread of the handler.

int ASql::Connection::threads ( ) const
inlineinherited

Returns the number of threads.

Definition at line 116 of file asql.hpp.

References ASql::Connection::maxThreads.

Referenced by connect().


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 57 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 52 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 47 of file mysql.hpp.

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

bool ASql::MySQL::Connection::m_initialized
private

Definition at line 59 of file mysql.hpp.

Referenced by connect().

int ASql::Connection::m_threads
protectedinherited

Definition at line 127 of file asql.hpp.

Referenced by ASql::Connection::running().

const int ASql::Connection::maxThreads
protectedinherited

Number of threads to pool for simultaneous queries.

Definition at line 124 of file asql.hpp.

Referenced by ASql::Connection::threads().

const bool ASql::ConnectionPar< MySQL::Statement >::s_false
staticinherited

Definition at line 195 of file asql.hpp.

bool ASql::Connection::terminateBool
protectedinherited

Definition at line 135 of file asql.hpp.

boost::mutex ASql::Connection::terminateMutex
protectedinherited

Definition at line 134 of file asql.hpp.

boost::condition_variable ASql::Connection::threadsChanged
protectedinherited

Definition at line 126 of file asql.hpp.

boost::mutex ASql::Connection::threadsMutex
protectedinherited

Definition at line 125 of file asql.hpp.

boost::scoped_array<boost::condition_variable> ASql::Connection::wakeUp
protectedinherited

Definition at line 132 of file asql.hpp.


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