ionflux.org | Impressum

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

MySQLDatabase. More...

#include <MySQLDatabase.hpp>

Inheritance diagram for Ionflux::Tools::MySQLDatabase:

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

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

Static Public Attributes

static const std::string DEFAULT_SERVER = "localhost"
 Default server.
static const unsigned int DEFAULT_PORT = 3306
 Default port.
static const std::string DEFAULT_USERNAME = "anonymous"
 Default username.
static const std::string DEFAULT_PASSWORD = ""
 Default password.
static const std::string DEFAULT_DATABASE = "test"
 Default database.
static const MySQLDatabaseClassInfo mySQLDatabaseClassInfo
 Class information instance.
static const ClassInfoCLASS_INFO
 Class information.

Protected Member Functions

void freeResult ()
 Free the result.

Protected Attributes

DatabaseConfig config
 Database configuration.
MYSQL * mysql
 MySQL Connection handle.
MYSQL_RES * queryResult
 MySQL result handle.
unsigned int numRows
 Rows in result set.
unsigned int numFields
 Fields in result set.
int numAffectedRows
 Affected rows.
DatabaseError lastError
 Error.

Detailed Description

MySQLDatabase.

An Interface to MySQL databases. After initializing the object with a suitable database configuration, you can immediately perform database operations (the interface will automatically establish a connection on demand). You can retrieve query results either as nested STL-style containers, or as a Node object.


Constructor & Destructor Documentation

Ionflux::Tools::MySQLDatabase::MySQLDatabase  ) 
 

Constructor.

Construct new MySQLDatabase object.

Ionflux::Tools::MySQLDatabase::MySQLDatabase const DatabaseConfig initConfig  ) 
 

Constructor.

Construct new MySQLDatabase object.

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

Destructor.

Destruct MySQLDatabase object.


Member Function Documentation

void Ionflux::Tools::MySQLDatabase::close  )  [virtual]
 

Close database connection.

Implements Ionflux::Tools::Database.

bool Ionflux::Tools::MySQLDatabase::connect  )  [virtual]
 

Connect to database.

Establish a database connection.

Returns:
true on success, false otherwise.

Implements Ionflux::Tools::Database.

bool Ionflux::Tools::MySQLDatabase::fetchResult DbResult result  )  [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.

Implements Ionflux::Tools::Database.

bool Ionflux::Tools::MySQLDatabase::fetchResultMap DbResultMap resultMap  )  [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.

Implements Ionflux::Tools::Database.

bool Ionflux::Tools::MySQLDatabase::fetchResultTree Node resultNode,
int  nodeOrder
[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.

Implements Ionflux::Tools::Database.

bool Ionflux::Tools::MySQLDatabase::fetchRow DbRow row  )  [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.

Implements Ionflux::Tools::Database.

bool Ionflux::Tools::MySQLDatabase::fetchRowMap DbRowMap rowMap  )  [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.

Implements Ionflux::Tools::Database.

bool Ionflux::Tools::MySQLDatabase::fetchRowTree Node rowNode  )  [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.

Implements Ionflux::Tools::Database.

void Ionflux::Tools::MySQLDatabase::freeResult  )  [protected]
 

Free the result.

DatabaseConfig Ionflux::Tools::MySQLDatabase::getConfig  )  [virtual]
 

Get database configuration.

Get the database configuration currently used.

Returns:
Database configuration.

Implements Ionflux::Tools::Database.

DatabaseError Ionflux::Tools::MySQLDatabase::getError  )  [virtual]
 

Get error.

Get the last error.

Returns:
The last error that occured.

Implements Ionflux::Tools::Database.

unsigned int Ionflux::Tools::MySQLDatabase::getNumAffectedRows  )  [virtual]
 

Get number of rows affected.

Get the number of rows affected by the previous query.

Returns:
Number of rows affected.

Implements Ionflux::Tools::Database.

unsigned int Ionflux::Tools::MySQLDatabase::getNumRows  )  [virtual]
 

Get number of rows returned.

Get the number of rows returned by the previous query.

Returns:
Number of rows in result set.

Implements Ionflux::Tools::Database.

unsigned int Ionflux::Tools::MySQLDatabase::getNumRows const std::string &  table  )  [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.

Implements Ionflux::Tools::Database.

bool Ionflux::Tools::MySQLDatabase::listColumns DbColumns columns,
const std::string &  table
[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.

Implements Ionflux::Tools::Database.

bool Ionflux::Tools::MySQLDatabase::listTables DbTables tables,
const std::string &  pattern = ""
[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.

Implements Ionflux::Tools::Database.

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

Execute database query.

Execute a database query.

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

Implements Ionflux::Tools::Database.

void Ionflux::Tools::MySQLDatabase::setConfig Ionflux::Tools::Node newConfig  )  [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.

Implements Ionflux::Tools::Database.

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

Set database configuration.

Set configuration options for the database.

Parameters:
newConfig Database configuration.

Implements Ionflux::Tools::Database.

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

Escape string.

Escapes a string so it represents a valid SQL string.

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

Implements Ionflux::Tools::Database.

bool Ionflux::Tools::MySQLDatabase::validateTable const std::string &  tableName,
const std::string &  createTemplate = "",
Node createConfig = 0
[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.

Implements Ionflux::Tools::Database.


Member Data Documentation

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

Initial value:

Class information.

Reimplemented from Ionflux::Tools::Database.

DatabaseConfig Ionflux::Tools::MySQLDatabase::config [protected]
 

Database configuration.

const string Ionflux::Tools::MySQLDatabase::DEFAULT_DATABASE = "test" [static]
 

Default database.

const string Ionflux::Tools::MySQLDatabase::DEFAULT_PASSWORD = "" [static]
 

Default password.

const unsigned int Ionflux::Tools::MySQLDatabase::DEFAULT_PORT = 3306 [static]
 

Default port.

const string Ionflux::Tools::MySQLDatabase::DEFAULT_SERVER = "localhost" [static]
 

Default server.

const string Ionflux::Tools::MySQLDatabase::DEFAULT_USERNAME = "anonymous" [static]
 

Default username.

DatabaseError Ionflux::Tools::MySQLDatabase::lastError [protected]
 

Error.

MYSQL* Ionflux::Tools::MySQLDatabase::mysql [protected]
 

MySQL Connection handle.

const MySQLDatabaseClassInfo Ionflux::Tools::MySQLDatabase::mySQLDatabaseClassInfo [static]
 

Class information instance.

int Ionflux::Tools::MySQLDatabase::numAffectedRows [protected]
 

Affected rows.

unsigned int Ionflux::Tools::MySQLDatabase::numFields [protected]
 

Fields in result set.

unsigned int Ionflux::Tools::MySQLDatabase::numRows [protected]
 

Rows in result set.

MYSQL_RES* Ionflux::Tools::MySQLDatabase::queryResult [protected]
 

MySQL result handle.


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