Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Private Attributes | Friends
Arc::MySQLDatabase Class Reference

Implement the database accessing interface in DBInterface.h by using mysql client library for accessing mysql database. More...

#include <MysqlWrapper.h>

Inheritance diagram for Arc::MySQLDatabase:
Inheritance graph
[legend]
Collaboration diagram for Arc::MySQLDatabase:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 MySQLDatabase (std::string &server, int port)
 MySQLDatabase (const MySQLDatabase &other)
virtual ~MySQLDatabase ()
virtual bool connect (std::string &dbname, std::string &user, std::string &password)
 Do connection with database server.
virtual bool isconnected () const
 Get the connection status.
virtual void close ()
 Close the connection with database server.
virtual bool enable_ssl (const std::string keyfile="", const std::string certfile="", const std::string cafile="", const std::string capath="")
 Enable ssl communication for the connection.
virtual bool shutdown ()
 Ask database server to shutdown.

Private Attributes

bool is_connected
std::string server_
int port_
std::string dbname_
std::string user_
std::string password_
bool secured
MYSQL * mysql

Friends

class MySQLQuery

Detailed Description

Implement the database accessing interface in DBInterface.h by using mysql client library for accessing mysql database.

Definition at line 15 of file MysqlWrapper.h.


Constructor & Destructor Documentation

Arc::MySQLDatabase::MySQLDatabase ( std::string &  server,
int  port 
)

Definition at line 11 of file MysqlWrapper.cpp.

    : server_(server),
      port_(port),
      mysql(NULL),
      is_connected(false)
  {}

Definition at line 18 of file MysqlWrapper.cpp.

    : is_connected(false) {
    if (other.isconnected()) {
      if (isconnected())
        close();
      mysql_real_connect(mysql, other.server_.c_str(), other.user_.c_str(),
                         other.password_.c_str(), other.dbname_.c_str(), other.port_, NULL, 0);
      if(mysql == NULL) is_connected = false;
      else is_connected = true;
    }
    else
      is_connected = false;
  }

Here is the call graph for this function:

Definition at line 32 of file MysqlWrapper.cpp.

                                {
    if (isconnected())
      close();
  }

Here is the call graph for this function:


Member Function Documentation

void Arc::MySQLDatabase::close ( ) [virtual]

Close the connection with database server.

Implements Arc::Database.

Definition at line 47 of file MysqlWrapper.cpp.

                            {
    if (mysql)
      mysql_close(mysql);
    mysql = NULL;
    is_connected = false;
  }

Here is the caller graph for this function:

bool Arc::MySQLDatabase::connect ( std::string &  dbname,
std::string &  user,
std::string &  password 
) [virtual]

Do connection with database server.

Parameters:
dbnameThe database name which will be used.
userThe username which will be used to access database.
passwordThe password which will be used to access database.

Implements Arc::Database.

Definition at line 37 of file MysqlWrapper.cpp.

                                                                                     {
    mysql = mysql_init(NULL);
    if (!mysql_real_connect(mysql, server_.c_str(), user.c_str(), password.c_str(), dbname.c_str(), port_, NULL, 0)) {
      std::cerr << "Database connection failed" << std::endl;
      return false;
    }
    is_connected = true;
    return true;
  }

Here is the caller graph for this function:

bool Arc::MySQLDatabase::enable_ssl ( const std::string  keyfile = "",
const std::string  certfile = "",
const std::string  cafile = "",
const std::string  capath = "" 
) [virtual]

Enable ssl communication for the connection.

Parameters:
keyfileThe location of key file.
certfileThe location of certificate file.
cafileThe location of ca file.
capathThe location of ca directory

Implements Arc::Database.

Definition at line 54 of file MysqlWrapper.cpp.

                                                                                 {
    return mysql_ssl_set(mysql, keyfile.c_str(), certfile.c_str(), cafile.c_str(), capath.c_str(), NULL) == 0;

  }
virtual bool Arc::MySQLDatabase::isconnected ( ) const [inline, virtual]

Get the connection status.

Implements Arc::Database.

Definition at line 26 of file MysqlWrapper.h.

                                     {
      return is_connected;
    }

Here is the caller graph for this function:

bool Arc::MySQLDatabase::shutdown ( ) [virtual]

Ask database server to shutdown.

Implements Arc::Database.

Definition at line 60 of file MysqlWrapper.cpp.

                               {
    return mysql_shutdown(mysql, SHUTDOWN_DEFAULT);

  }

Friends And Related Function Documentation

friend class MySQLQuery [friend]

Definition at line 17 of file MysqlWrapper.h.


Member Data Documentation

std::string Arc::MySQLDatabase::dbname_ [private]

Definition at line 41 of file MysqlWrapper.h.

Definition at line 38 of file MysqlWrapper.h.

MYSQL* Arc::MySQLDatabase::mysql [private]

Definition at line 46 of file MysqlWrapper.h.

std::string Arc::MySQLDatabase::password_ [private]

Definition at line 43 of file MysqlWrapper.h.

Definition at line 40 of file MysqlWrapper.h.

Definition at line 44 of file MysqlWrapper.h.

std::string Arc::MySQLDatabase::server_ [private]

Definition at line 39 of file MysqlWrapper.h.

std::string Arc::MySQLDatabase::user_ [private]

Definition at line 42 of file MysqlWrapper.h.


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