ionflux.org | Impressum

Ionflux::Tools::Database Class Reference
[Database interface]

Database. More...

#include <Database.hpp>

Inheritance diagram for Ionflux::Tools::Database:

Inheritance graph
[legend]
Collaboration diagram for Ionflux::Tools::Database:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Database ()
 Constructor.
 Database (const DatabaseConfig &initConfig)
 Constructor.
virtual ~Database ()
 Destructor.
virtual void setConfig (const DatabaseConfig &newConfig)=0
 Set database configuration.
virtual void setConfig (Ionflux::Tools::Node &newConfig)=0
 Set database configuration.
virtual DatabaseConfig getConfig ()=0
 Get database configuration.
virtual bool connect ()=0
 Connect to database.
virtual void close ()=0
 Close database connection.
virtual bool query (const std::string &command)=0
 Execute database query.
virtual bool listTables (DbTables &tables, const std::string &pattern="")=0
 List tables.
virtual bool listColumns (DbColumns &columns, const std::string &table)=0
 List columns.
virtual unsigned int getNumRows (const std::string &table)=0
 Get number of rows.
virtual unsigned int getNumRows ()=0
 Get number of rows returned.
virtual unsigned int getNumAffectedRows ()=0
 Get number of rows affected.
virtual bool fetchRow (DbRow &row)=0
 Get a result row.
virtual bool fetchRowMap (DbRowMap &rowMap)=0
 Get a result row as a map.
virtual bool fetchRowTree (Node &rowNode)=0
 Get a result row as a tree.
virtual bool fetchResult (DbResult &result)=0
 Get a complete result.
virtual bool fetchResultMap (DbResultMap &resultMap)=0
 Get a complete result as a map.
virtual bool fetchResultTree (Node &resultNode, int nodeOrder)=0
 Get a complete result as a tree.
virtual std::string sqlEscape (const std::string &source)=0
 Escape string.
virtual bool validateTable (const std::string &tableName, const std::string &createTemplate="", Node *createConfig=0)=0
 Validate existence of table.
virtual DatabaseError getError ()=0
 Get error.

Static Public Attributes

static const int NODE_ORDER_ROWS = 0
 Node order: First level represents rows.
static const int NODE_ORDER_NAMED_FIELDS = 1
 Node order: First level represents rows with named field nodes.
static const int NODE_ORDER_COLUMNS = 2
 Node order: First level represents columns.
static const DatabaseClassInfo databaseClassInfo
 Class information instance.
static const ClassInfoCLASS_INFO
 Class information.

Detailed Description

Database.

Abstract wrapper class for a database connection.


Constructor & Destructor Documentation

Ionflux::Tools::Database::Database  ) 
 

Constructor.

Construct new Database object.

Ionflux::Tools::Database::Database const DatabaseConfig initConfig  ) 
 

Constructor.

Construct new Database object.

Ionflux::Tools::Database::~Database  )  [virtual]
 

Destructor.

Destruct Database object.


Member Function Documentation

virtual void Ionflux::Tools::Database::close  )  [pure virtual]
 

Close database connection.

Implemented in Ionflux::Tools::MySQLDatabase.

virtual bool Ionflux::Tools::Database::connect  )  [pure virtual]
 

Connect to database.

Establish a database connection.

Returns:
true on success, false otherwise.

Implemented in Ionflux::Tools::MySQLDatabase.

virtual bool Ionflux::Tools::Database::fetchResult DbResult result  )  [pure virtual]
 

Get a complete result.

Initializes a DbResult to contain all result rows.

Parameters:
result Object to store the result rows in.
Returns:
true on success, false otherwise.

Implemented in Ionflux::Tools::MySQLDatabase.

virtual bool Ionflux::Tools::Database::fetchResultMap DbResultMap resultMap  )  [pure virtual]
 

Get a complete result as a map.

Initializes a DbResultMap to contain all result rows as maps. Use this to get a complete result as maps.

Parameters:
resultMap Object to store the result row maps in.
Returns:
true on success, false otherwise.

Implemented in Ionflux::Tools::MySQLDatabase.

virtual bool Ionflux::Tools::Database::fetchResultTree Node resultNode,
int  nodeOrder
[pure virtual]
 

Get a complete result as a tree.

Initializes a tree node to contain all result rows. Use this to get a complete result as a tree. You can specify either Database::NODE_ORDER_ROWS, Database::NODE_ORDER_NAMED_FIELDS, or Database::NODE_ORDER_COLUMNS as 'nodeOrder'. In row order mode, each node on the first level represents a row, and each data entry contains field data. The first node contains the field names as data entries. In named field order mode, each node on the first level represents a row. Each node on the second level contains field data and has its name set to the field name. In column order mode, each node on the first level represents a column and has its name set to the corresponding field name. Each data entry contains field data for a row.

Parameters:
resultNode Node to store the result rows in.
nodeOrder Node order.
Returns:
true on success, false otherwise.

Implemented in Ionflux::Tools::MySQLDatabase.

virtual bool Ionflux::Tools::Database::fetchRow DbRow row  )  [pure virtual]
 

Get a result row.

Initializes a DbRow to contain the fields of a result row.

Parameters:
row Object to store the row in.
Returns:
true on success, false otherwise.

Implemented in Ionflux::Tools::MySQLDatabase.

virtual bool Ionflux::Tools::Database::fetchRowMap DbRowMap rowMap  )  [pure virtual]
 

Get a result row as a map.

Initializes a DbRowMap to contain the fields of a result row. Use this to get a result row as a map (associative array).

Parameters:
rowMap Object to store the row map in.
Returns:
true on success, false otherwise.

Implemented in Ionflux::Tools::MySQLDatabase.

virtual bool Ionflux::Tools::Database::fetchRowTree Node rowNode  )  [pure virtual]
 

Get a result row as a tree.

Initializes a tree node to contain the fields of a result row. Use this to get a result row as a tree.

Parameters:
rowNode Node to store the row in.
Returns:
true on success, false otherwise.

Implemented in Ionflux::Tools::MySQLDatabase.

virtual DatabaseConfig Ionflux::Tools::Database::getConfig  )  [pure virtual]
 

Get database configuration.

Get the database configuration currently used.

Returns:
Database configuration.

Implemented in Ionflux::Tools::MySQLDatabase.

virtual DatabaseError Ionflux::Tools::Database::getError  )  [pure virtual]
 

Get error.

Get the last error.

Returns:
The last error that occured.

Implemented in Ionflux::Tools::MySQLDatabase.

virtual unsigned int Ionflux::Tools::Database::getNumAffectedRows  )  [pure virtual]
 

Get number of rows affected.

Get the number of rows affected by the previous query.

Returns:
Number of rows affected.

Implemented in Ionflux::Tools::MySQLDatabase.

virtual unsigned int Ionflux::Tools::Database::getNumRows  )  [pure virtual]
 

Get number of rows returned.

Get the number of rows returned by the previous query.

Returns:
Number of rows in result set.

Implemented in Ionflux::Tools::MySQLDatabase.

virtual unsigned int Ionflux::Tools::Database::getNumRows const std::string &  table  )  [pure virtual]
 

Get number of rows.

Get the number of rows for the specified table.

Parameters:
table Table.
Returns:
Number of rows for the specified table.

Implemented in Ionflux::Tools::MySQLDatabase.

virtual bool Ionflux::Tools::Database::listColumns DbColumns columns,
const std::string &  table
[pure virtual]
 

List columns.

Fetches a list of columns for the specified table.

Parameters:
columns Where to store the list of columns.
table Table.
Returns:
true on success, false otherwise.

Implemented in Ionflux::Tools::MySQLDatabase.

virtual bool Ionflux::Tools::Database::listTables DbTables tables,
const std::string &  pattern = ""
[pure virtual]
 

List tables.

Fetches a list of tables from the current database that match the specified pattern. Pass an empty string to match all tables.

Parameters:
tables Where to store the list of tables.
pattern A pattern to match table names.
Returns:
true on success, false otherwise.

Implemented in Ionflux::Tools::MySQLDatabase.

virtual bool Ionflux::Tools::Database::query const std::string &  command  )  [pure virtual]
 

Execute database query.

Execute a database query.

Parameters:
command Command to execute as a database query.
Returns:
true on success, false otherwise.

Implemented in Ionflux::Tools::MySQLDatabase.

virtual void Ionflux::Tools::Database::setConfig Ionflux::Tools::Node newConfig  )  [pure virtual]
 

Set database configuration.

Set configuration options for the database.

Note:
This allows to set the database configuration from the contents of a configuration node. Each first level node corresponds to a field of the DatabaseConfig struct, with its name set to the field name and its first data entry set to the field value.
Parameters:
newConfig Database configuration node.

Implemented in Ionflux::Tools::MySQLDatabase.

virtual void Ionflux::Tools::Database::setConfig const DatabaseConfig newConfig  )  [pure virtual]
 

Set database configuration.

Set configuration options for the database.

Parameters:
newConfig Database configuration.

Implemented in Ionflux::Tools::MySQLDatabase.

virtual std::string Ionflux::Tools::Database::sqlEscape const std::string &  source  )  [pure virtual]
 

Escape string.

Escapes a string so it represents a valid SQL string.

Parameters:
source String to be escaped.
Returns:
Escaped string.

Implemented in Ionflux::Tools::MySQLDatabase.

virtual bool Ionflux::Tools::Database::validateTable const std::string &  tableName,
const std::string &  createTemplate = "",
Node createConfig = 0
[pure virtual]
 

Validate existence of table.

Validate the existence of the table with the specified name. If the table does not exist and a create template is specified, try to create the table.

Parameters:
tableName Table name.
createTemplate Template for the table creation query.
createConfig Configuration to be used for table creation.
Returns:
true if the table exists or has been successfully created, false if the table does not exist and could not be created automatically.

Implemented in Ionflux::Tools::MySQLDatabase.


Member Data Documentation

const ClassInfo * Ionflux::Tools::Database::CLASS_INFO [static]
 

Initial value:

Class information.

Reimplemented from Ionflux::Tools::ManagedObject.

Reimplemented in Ionflux::Tools::MySQLDatabase.

const DatabaseClassInfo Ionflux::Tools::Database::databaseClassInfo [static]
 

Class information instance.

const int Ionflux::Tools::Database::NODE_ORDER_COLUMNS = 2 [static]
 

Node order: First level represents columns.

const int Ionflux::Tools::Database::NODE_ORDER_NAMED_FIELDS = 1 [static]
 

Node order: First level represents rows with named field nodes.

const int Ionflux::Tools::Database::NODE_ORDER_ROWS = 0 [static]
 

Node order: First level represents rows.


The documentation for this class was generated from the following files:
Generated on Tue Mar 14 21:08:00 2006 for Ionflux Tools Class Library (iftools) by  doxygen 1.4.6