MCS  0.3.3-alpha7
mcs::DBConn Class Reference

Handle database connection. More...

#include <mcs.hh>

Public Member Functions

void close ()
 Closes a db connection. More...
 
void connect (string user, string pass, string db, string host="")
 Connect to a databae server. More...
 
 DBConn (const DBConn &)
 Declared to avoid using of default copy constructor. More...
 
 DBConn ()
 Constructor. More...
 
unsigned long id ()
 Returns the same value as mysql_thread_id. More...
 
bool isOpen ()
 Tell if a connection to the server is opened. More...
 
DBConnnewDBConn ()
 Creates a new DB connection with the same parameters. More...
 
DBConnoperator= (const DBConn &)
 Declared to avoid using of default assignment operator. More...
 
 ~DBConn ()
 Destructor, calls close(). More...
 

Private Attributes

MYSQL * lconn
 MYSQL connection structure. More...
 
bool lconnInitialized
 True if the connection has been initialized. More...
 
bool lconnOpened
 True if the connection has been opened. More...
 
string ldb
 Database name to connect to. More...
 
string lhost
 Host running database server. More...
 
string lpass
 User password. More...
 
string luser
 User name. More...
 
 MCS_DEBUG_ALLOC
 

Friends

class Query
 

Detailed Description

Handle database connection.

You can use this class to connect to a database. To perform queries on the database you should use a Query object, whose methods require a DBConn object as parameter.

Definition at line 5432 of file mcs.hh.

Constructor & Destructor Documentation

◆ DBConn() [1/2]

mcs::DBConn::DBConn ( const DBConn )

Declared to avoid using of default copy constructor.

Warning
This constructor is declared but not implemented. If you try to use it you will get a compilation error.

◆ DBConn() [2/2]

mcs::DBConn::DBConn ( )

Constructor.

Definition at line 30 of file Db.cc.

◆ ~DBConn()

mcs::DBConn::~DBConn ( )

Destructor, calls close().

Definition at line 39 of file Db.cc.

Member Function Documentation

◆ close()

void mcs::DBConn::close ( )

Closes a db connection.

Definition at line 71 of file Db.cc.

◆ connect()

void mcs::DBConn::connect ( string  user,
string  pass,
string  db,
string  host = "" 
)

Connect to a databae server.

Parameters
userUser name.
passUser password.
dbDatabase name to connect to.
hostHost running database server, if empty localhost will be used.
Exceptions
ERRORMSG_CANT_ALLOCATE_MYSQL;
ERRORMSG_CANT_OPEN_MYSQL_CONNECTION.
See also
DBConn_connect().

Definition at line 44 of file Db.cc.

◆ id()

unsigned long mcs::DBConn::id ( )

Returns the same value as mysql_thread_id.

Definition at line 97 of file Db.cc.

◆ isOpen()

bool mcs::DBConn::isOpen ( )

Tell if a connection to the server is opened.

Definition at line 91 of file Db.cc.

◆ newDBConn()

DBConn * mcs::DBConn::newDBConn ( )

Creates a new DB connection with the same parameters.

A DBConn object can maintain only one prepared statement at a time. So if you want to use several prepared statement you must use different DBConn objects. With this method you istantiate on the heap a new DBConn object and call its connect method() with the same parameters used to connect with the actual object. It's user responsibility to delete objects created with this method.

Returns
Address of the newly created DBConn object.
Exceptions
ERRORMSG_CANT_OPEN_MYSQL_CONNECTION.

Definition at line 103 of file Db.cc.

◆ operator=()

DBConn& mcs::DBConn::operator= ( const DBConn )

Declared to avoid using of default assignment operator.

Warning
This operator is declared but not implemented. If you try to use it you will get a compilation error.

Member Data Documentation

◆ lconn

MYSQL* mcs::DBConn::lconn
private

MYSQL connection structure.

Definition at line 5438 of file mcs.hh.

◆ lconnInitialized

bool mcs::DBConn::lconnInitialized
private

True if the connection has been initialized.

Definition at line 5441 of file mcs.hh.

◆ lconnOpened

bool mcs::DBConn::lconnOpened
private

True if the connection has been opened.

Definition at line 5444 of file mcs.hh.

◆ ldb

string mcs::DBConn::ldb
private

Database name to connect to.

Definition at line 5453 of file mcs.hh.

◆ lhost

string mcs::DBConn::lhost
private

Host running database server.

Definition at line 5456 of file mcs.hh.

◆ lpass

string mcs::DBConn::lpass
private

User password.

Definition at line 5450 of file mcs.hh.

◆ luser

string mcs::DBConn::luser
private

User name.

Definition at line 5447 of file mcs.hh.


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

mcslogo

MCS (My Customizable Server) ver. 0.3.3-alpha7
Documentation generated on Mon May 28 07:39:41 UTC 2018