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

Dv::Sql::Db Class Reference

An connection to an SQL database. More...

#include <sqldb.h>

Inheritance diagram for Dv::Sql::Db:

Inheritance graph
[legend]
List of all members.

Public Member Functions

virtual ~Db ()
 Since this class will be subclassed, its destructor must be virtual.

bool ok () const
 Return true iff status is ok; e.g. db was succesfully opened.

 operator bool () const
 Same as Dv::Sql::Db::ok().

bool operator! () const
 Same as !DvSql::Db::ok().

std::string err () const
 Return string representation of last error.

std::string host () const
 Name of host machine on which database resides.

std::string database () const
 Name of current database of connection.

std::ostream * log () const
 Logging is turned on if log()!=0.

void log (std::ostream *os)
 Turn logging on/off, see Db::log().

virtual bool database (const std::string &database)=0
 Switch connection to database, return true iff succeeded.

virtual std::vector< std::string > databases ()=0
 Return names of available databases.

virtual std::vector< std::string > tables ()=0
 Return names of tables in databases.

virtual std::vector< Fieldfields (const std::string &table)=0
 Return fields in table.


Protected Member Functions

bool ok (bool b)
 Set status.

void err (const std::string &s)
 Set error string returned by Dv::Sql::err().

void name (const std::string &dbname)
 Set database name.

virtual Command_command_ (Command &)=0
 Return dbms-specific command.

 Db (const char *name, const char *host)
 Constructor.


Private Member Functions

 Db (const Db &)
 Cctor is forbidden.

Dboperator= (const Db &)
 Assignment is forbidden.


Private Attributes

std::string host_
bool ok_
std::string err_
std::ostream * log_
std::string name_
 Name of database, may be "".


Friends

class Command
 Friend.


Detailed Description

An connection to an SQL database.

Definition at line 138 of file sqldb.h.


Constructor & Destructor Documentation

virtual Dv::Sql::Db::~Db  )  [inline, virtual]
 

Since this class will be subclassed, its destructor must be virtual.

The destructor will close the connection.

Reimplemented in Dv::MySql::Db.

Definition at line 147 of file sqldb.h.

Dv::Sql::Db::Db const char *  name,
const char *  host
[protected]
 

Constructor.

The constructor takes the name of the database and the name of the host where the database resides. If name == 0, there is no database yet, if host == 0, we use "localhost"

Copy ctor and assignment are forbidden.

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

Cctor is forbidden.

Reimplemented in Dv::MySql::Db.


Member Function Documentation

bool Dv::Sql::Db::ok  )  const [inline]
 

Return true iff status is ok; e.g. db was succesfully opened.

Definition at line 150 of file sqldb.h.

References ok_.

Dv::Sql::Db::operator bool  )  const [inline]
 

Same as Dv::Sql::Db::ok().

Definition at line 152 of file sqldb.h.

References ok_.

bool Dv::Sql::Db::operator!  )  const [inline]
 

Same as !DvSql::Db::ok().

Definition at line 154 of file sqldb.h.

References ok_.

std::string Dv::Sql::Db::err  )  const [inline]
 

Return string representation of last error.

Definition at line 157 of file sqldb.h.

References err_.

std::string Dv::Sql::Db::host  )  const [inline]
 

Name of host machine on which database resides.

Definition at line 159 of file sqldb.h.

References host_.

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

Name of current database of connection.

Reimplemented in Dv::MySql::Db.

Definition at line 161 of file sqldb.h.

References name_.

std::ostream* Dv::Sql::Db::log  )  const [inline]
 

Logging is turned on if log()!=0.

The amount of logging is decided by the DBMS-dependent classes. E.g. Dv::MySql::Db logs the execution of every command as well as indication of the result.

Definition at line 168 of file sqldb.h.

References log_.

void Dv::Sql::Db::log std::ostream *  os  )  [inline]
 

Turn logging on/off, see Db::log().

Definition at line 170 of file sqldb.h.

References log_.

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

Switch connection to database, return true iff succeeded.

Implemented in Dv::MySql::Db.

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

Return names of available databases.

Implemented in Dv::MySql::Db.

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

Return names of tables in databases.

Implemented in Dv::MySql::Db.

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

Return fields in table.

Implemented in Dv::MySql::Db.

bool Dv::Sql::Db::ok bool  b  )  [inline, protected]
 

Set status.

Definition at line 183 of file sqldb.h.

References ok_.

void Dv::Sql::Db::err const std::string &  s  )  [inline, protected]
 

Set error string returned by Dv::Sql::err().

Definition at line 185 of file sqldb.h.

References err_.

void Dv::Sql::Db::name const std::string &  dbname  )  [inline, protected]
 

Set database name.

Definition at line 187 of file sqldb.h.

References name_.

virtual Command_* Dv::Sql::Db::command_ Command  )  [protected, pure virtual]
 

Return dbms-specific command.

Factory method; a concrete subclass X of Db implements this to return (a pointer to) an instance of the subclass of Command_ corresponding to X's Command_.

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

Assignment is forbidden.

Reimplemented in Dv::MySql::Db.


Friends And Related Function Documentation

friend class Command [friend]
 

Friend.

Definition at line 141 of file sqldb.h.


Member Data Documentation

std::string Dv::Sql::Db::host_ [private]
 

Definition at line 208 of file sqldb.h.

Referenced by host().

bool Dv::Sql::Db::ok_ [private]
 

Definition at line 209 of file sqldb.h.

Referenced by ok(), operator bool(), and operator!().

std::string Dv::Sql::Db::err_ [private]
 

Definition at line 210 of file sqldb.h.

Referenced by err().

std::ostream* Dv::Sql::Db::log_ [private]
 

Definition at line 211 of file sqldb.h.

Referenced by log().

std::string Dv::Sql::Db::name_ [private]
 

Name of database, may be "".

Definition at line 214 of file sqldb.h.

Referenced by database(), and name().


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