Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

Dv::MySql::Db Class Reference

A connection to a mysql database. More...

#include <mysqldb.h>

Inheritance diagram for Dv::MySql::Db:

Inheritance graph
[legend]
Collaboration diagram for Dv::MySql::Db:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Db (const char *dbname=0, const char *username="root", const char *passwd=0, const char *hostname=0)
 Open a connection, check result with Dv::Sql::Db::ok() and friends.

 Db (const Dv::Util::Props &config, const std::string &prefix="") throw (Sql::Exception)
 Get database name etc. from configuration Dv::Util::Props object.

virtual ~Db ()
 Destructor.

std::string user () const
 Return user of this database connection.

std::string passwd () const
 Return password used to open this connection.

std::string database () const
 Return name of current database of connection.

bool database (const std::string &database)
 Switch connection to another database.

std::vector< std::string > databases ()
 Return the names of all databases available through this connection.

std::vector< std::string > tables ()
 Return the names of all tables available in the current database.

std::vector< Sql::Fieldfields (const std::string &table)
 Return ordered list of fields in a table.


Private Member Functions

 Db (const Db &)
 Cctor is forbidden.

Dboperator= (const Db &)
 Assignment is forbidden.

Sql::Command_command_ (Sql::Command &cmd)
 Implementation of Sql::Db pure virtual factory function.


Private Attributes

void * mysql_
std::string user_
std::string passwd_

Friends

class Command_
 Command_ has access to mdbms-dependent private info, e.g. mysql_.


Detailed Description

A connection to a mysql database.

Definition at line 36 of file mysqldb.h.


Constructor & Destructor Documentation

Dv::MySql::Db::Db const char *  dbname = 0,
const char *  username = "root",
const char *  passwd = 0,
const char *  hostname = 0
 

Open a connection, check result with Dv::Sql::Db::ok() and friends.

Dv::MySql::Db::Db const Dv::Util::Props config,
const std::string &  prefix = ""
throw (Sql::Exception)
 

Get database name etc. from configuration Dv::Util::Props object.

The configuration file uses the following attribute names (each preceded by prefix):

      mysqldb = 
      mysqluser = 
      mysqlpasswd = 
      mysqlhost = 
If, e.g. prefix = "abc:", this would become
      abc:mysqldb = 
      abc:mysqluser = 
      abc:mysqlpasswd = 
      abc:mysqlhost = 
Any missing or empty attribute is equivalent to a corresponding 0 argument for the other constructor.

Example usage: (from tmysql.C in the distribution)

      try {
        static const std::string CONFIG("tmysql.config");
        ifstream        ifs(CONFIG.c_str());
        if (!ifs)
          throw runtime_error(CONFIG+": cannot open");
        
        Dv::Util::Props config(ifs);
        std::string dictfn(config["dict"]);
  
        MySql::Db       db(config,"tmysql::");
        ..
      catch (exception& e) {
        cerr << e.what() << endl;
        return 1;
        }
where ``tmysql.config'' may contain e.g.
      tmeta::mysqldb=mysql
      tmeta::mysqluser=root
      #tmeta::mysqlpasswd=
      #
      tmysql::mysqldb=test
      tmysql::mysqluser=root
      #mysqlpasswd=
      dict=/usr/dict/words

virtual Dv::MySql::Db::~Db  )  [virtual]
 

Destructor.

Reimplemented from Dv::Sql::Db.

Dv::MySql::Db::Db const Db  )  [private]
 

Cctor is forbidden.

Reimplemented from Dv::Sql::Db.


Member Function Documentation

std::string Dv::MySql::Db::user  )  const [inline]
 

Return user of this database connection.

Definition at line 97 of file mysqldb.h.

References user_.

std::string Dv::MySql::Db::passwd  )  const [inline]
 

Return password used to open this connection.

Definition at line 99 of file mysqldb.h.

References passwd_.

std::string Dv::MySql::Db::database  )  const [inline]
 

Return name of current database of connection.

Reimplemented from Dv::Sql::Db.

Definition at line 101 of file mysqldb.h.

bool Dv::MySql::Db::database const std::string &  database  )  [virtual]
 

Switch connection to another database.

Implements Dv::Sql::Db.

std::vector<std::string> Dv::MySql::Db::databases  )  [virtual]
 

Return the names of all databases available through this connection.

Implements Dv::Sql::Db.

std::vector<std::string> Dv::MySql::Db::tables  )  [virtual]
 

Return the names of all tables available in the current database.

Implements Dv::Sql::Db.

std::vector<Sql::Field> Dv::MySql::Db::fields const std::string &  table  )  [virtual]
 

Return ordered list of fields in a table.

Implements Dv::Sql::Db.

Db& Dv::MySql::Db::operator= const Db  )  [private]
 

Assignment is forbidden.

Reimplemented from Dv::Sql::Db.

Sql::Command_* Dv::MySql::Db::command_ Sql::Command cmd  )  [private]
 

Implementation of Sql::Db pure virtual factory function.


Friends And Related Function Documentation

friend class Command_ [friend]
 

Command_ has access to mdbms-dependent private info, e.g. mysql_.

Definition at line 38 of file mysqldb.h.


Member Data Documentation

void* Dv::MySql::Db::mysql_ [private]
 

Definition at line 113 of file mysqldb.h.

std::string Dv::MySql::Db::user_ [private]
 

Definition at line 114 of file mysqldb.h.

Referenced by user().

std::string Dv::MySql::Db::passwd_ [private]
 

Definition at line 115 of file mysqldb.h.

Referenced by passwd().


The documentation for this class was generated from the following file:
dvmysql-0.4.11 [15 February, 2004]