Public Member Functions | Protected Attributes | Private Member Functions

MySqlPL::MSqlConnection Struct Reference

simple MySQL login to database More...

#include <mysqlpl.h>

Collaboration diagram for MySqlPL::MSqlConnection:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 MSqlConnection (MSqlEnv &env)
 MSqlConnection (MSqlEnv &env, const char *username, const char *password, const char *db_name, const char *host="localhost", unsigned port=3306, unsigned long clientflag=0)
void connect (const char *username, const char *password, const char *db_name, const char *host="localhost", unsigned port=3306, unsigned long clientflag=0)
 ~MSqlConnection ()
const char * get_info () const
void print_warnings (std::ostream &out)
LONGLONG get_insert_id () const
void commit ()
void rollback ()
 operator MYSQL * () const

Protected Attributes

MSqlEnv_env
MYSQL * _db
bool _connected

Private Member Functions

 MSqlConnection (const MSqlConnection &)

Detailed Description

simple MySQL login to database

Definition at line 218 of file mysqlpl.h.


Constructor & Destructor Documentation

MySqlPL::MSqlConnection::MSqlConnection ( MSqlEnv env ) [inline]

Definition at line 220 of file mysqlpl.h.

     :  _env(env),
        _db(NULL),
        _connected(false)
    {
    }
MySqlPL::MSqlConnection::MSqlConnection ( MSqlEnv env,
const char *  username,
const char *  password,
const char *  db_name,
const char *  host = "localhost",
unsigned  port = 3306,
unsigned long  clientflag = 0 
) [inline]

Definition at line 227 of file mysqlpl.h.

References connect().

     :  _env(env),
        _db(NULL),
        _connected(false)
    {
        connect(username, password, db_name, host, port, clientflag);
    }

Here is the call graph for this function:

MySqlPL::MSqlConnection::~MSqlConnection (  ) [inline]

Definition at line 239 of file mysqlpl.h.

    {
        /*see MSqlEnv::~MSqlEnv()
        if (_connected)
            mysql_close(_mysql);
        */
    }
MySqlPL::MSqlConnection::MSqlConnection ( const MSqlConnection  ) [private]

Member Function Documentation

void MySqlPL::MSqlConnection::commit (  ) [inline]

Definition at line 278 of file mysqlpl.h.

References _db, _env, and MySqlPL::mysqlpl_check_error().

    {
#if MYSQLPL_PREP_STMT
        my_bool res = mysql_commit(_db);
#else
        my_bool res = mysql_query(_db, "commit");
#endif
        mysqlpl_check_error(_env, res);
    }

Here is the call graph for this function:

void MySqlPL::MSqlConnection::connect ( const char *  username,
const char *  password,
const char *  db_name,
const char *  host = "localhost",
unsigned  port = 3306,
unsigned long  clientflag = 0 
)

Definition at line 154 of file mysqlpl.cpp.

References _connected, _db, _env, MySqlPL::SqlStatement::execute(), MySqlPL::mysqlpl_check_error(), and THROW_MYSQLPL_EXCEPTION.

Referenced by MSqlConnection().

{
    _connected = false;

    _db = mysql_real_connect(_env, host, username, password, db_name, port, NULL, clientflag);

    if (!_db)
        THROW_MYSQLPL_EXCEPTION(_env);

    _connected = true;

#if MYSQLPL_PREP_STMT
     // disable auto commit mode
    my_bool res = mysql_autocommit(_db, 0);
    mysqlpl_check_error(_env, res);
#else
    SqlStatement(*this).execute("set autocommit=0");    // "set autocommit=0" is not supported before MySQL 4.1
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char * MySqlPL::MSqlConnection::get_info (  ) const

Definition at line 197 of file mysqlpl.cpp.

References _db.

Referenced by print_warnings().

{
    return mysql_info(_db);
}

Here is the caller graph for this function:

LONGLONG MySqlPL::MSqlConnection::get_insert_id (  ) const [inline]

Definition at line 272 of file mysqlpl.h.

References _db.

    {
        return mysql_insert_id(_db);
    }
MySqlPL::MSqlConnection::operator MYSQL * (  ) const [inline]

Definition at line 298 of file mysqlpl.h.

References _db.

{return _db;}
void MySqlPL::MSqlConnection::print_warnings ( std::ostream &  out ) [inline]

Definition at line 262 of file mysqlpl.h.

References get_info().

    {
        const char* info = get_info();

        if (info)
            out << info << std::endl;
    }

Here is the call graph for this function:

void MySqlPL::MSqlConnection::rollback (  ) [inline]

Definition at line 288 of file mysqlpl.h.

References _db, _env, and MySqlPL::mysqlpl_check_error().

    {
#if MYSQLPL_PREP_STMT   //@@
        my_bool res = mysql_rollback(_db);
#else
        my_bool res = mysql_query(_db, "rollback");
#endif
        mysqlpl_check_error(_env, res);
    }

Here is the call graph for this function:


Member Data Documentation

Definition at line 304 of file mysqlpl.h.

Referenced by connect().

MYSQL* MySqlPL::MSqlConnection::_db [protected]

Definition at line 302 of file mysqlpl.h.

Referenced by commit(), connect(), get_info(), get_insert_id(), operator MYSQL *(), and rollback().

Definition at line 301 of file mysqlpl.h.

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


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