Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

AnyConfig::AcMySQLConfig Class Reference

An AcWriteableConfig which uses a MySQL database as source. More...

#include <AnyConfig.h>

Inheritance diagram for AnyConfig::AcMySQLConfig::

AnyConfig::AcWriteableConfig AnyConfig::AcConfiguration List of all members.

Public Methods

 AcMySQLConfig ()
 Constructor method. More...

virtual ~AcMySQLConfig ()
 Destructor method. More...

virtual bool copyTo (AcWriteableConfig *pWriteableConfig)
 Copy this configuration to another configuration. More...

virtual AcConfigurationcreateFromSection (const char *section)
 Extract a sub-configuration containing only the indicated section. More...

virtual void display ()
 Mostly for debugging purposes, write out the configuration to stdout. More...

virtual bool getSectionStr (const char *pSection, const char *pKey, CString &rValue)
 Like getStr() but can fetch keys from another section than the current one. More...

virtual bool getStr (const char *pKey, CString &rValue)
 Retrieve a string from the configuration for the specified key. More...

virtual bool initialize (AcConfiguration &parentConfig)
 Initialize the configuration using another, probably more primitive, parent configuration. More...

virtual bool initRequired ()
 Returns true if the derived AcConfiguration requires to be initialized. More...

virtual bool keyExists (const char *pKey)
 Check if a given key exists. More...

virtual void setSectionStr (const char *pSection, const char *pKey, const char *pValue)
 Like setStr() but can set keys in another section than the current one. More...

virtual void setStr (const char *pKey, const char *pValue)
 Set the configuration item to the passed string value. More...

bool GetKeepconn () const
 Returns the value of member '_keepconn'. More...

void SetKeepconn (bool keepconn)
 Set the value of member '_keepconn' to 'keepconn'. More...


Protected Methods

virtual void* query (const char *pKey, const char *pSection)
 Perform the query to obtain the value for the key. More...

virtual void release (void *pRes)
 Release the result of a MySQL query. More...


Protected Attributes

bool _keepconn
void* _hdl
CString _database
CString _hostname
CString _password
CString _cfgtable
CString _username

Private Methods

void ConstructorInclude ()
 Method which must be called first in a constructor. More...

void DestructorInclude ()
 Method which must be called first in a destructor. More...


Detailed Description

An AcWriteableConfig which uses a MySQL database as source.


Constructor & Destructor Documentation

AnyConfig::AcMySQLConfig::AcMySQLConfig ( )
 

Constructor method.

AnyConfig::AcMySQLConfig::~AcMySQLConfig ( ) [virtual]
 

Destructor method.


Member Function Documentation

void AnyConfig::AcMySQLConfig::ConstructorInclude ( ) [private]
 

Method which must be called first in a constructor.

Reimplemented from AnyConfig::AcWriteableConfig.

void AnyConfig::AcMySQLConfig::DestructorInclude ( ) [private]
 

Method which must be called first in a destructor.

Reimplemented from AnyConfig::AcWriteableConfig.

bool AnyConfig::AcMySQLConfig::GetKeepconn ( ) const [inline]
 

Returns the value of member '_keepconn'.

void AnyConfig::AcMySQLConfig::SetKeepconn ( bool keepconn ) [inline]
 

Set the value of member '_keepconn' to 'keepconn'.

bool AnyConfig::AcMySQLConfig::copyTo ( AcWriteableConfig * pWriteableConfig ) [virtual]
 

Copy this configuration to another configuration.

This method is specifically handy when the source configuration comes from a text file and the destination configuration is AcMemConfig, which offers much more functionality. Along the same lines, this method can be used to save an AcMemConfig in a file. If the target configuration already has filled-in items, the result of this operation is undefined. Some derived classes may end up containing a merged result of the old and the new values (AcMemConfig, AcEnvConfig), other may only contain the copied values (like AcFileConfig).

Parameters:
pWriteableConfig   A pointer to an initialized AcWriteableConfig.
return   True if the derived configuration supports copying, false otherwise.

Reimplemented from AnyConfig::AcConfiguration.

AcConfiguration * AnyConfig::AcMySQLConfig::createFromSection ( const char * section ) [virtual]
 

Extract a sub-configuration containing only the indicated section.

Parameters:
section   The section to extract.
Returns:
An AcConfiguration pointer if the section existed or NULL if it didn't or the derived class does not support this operation. The returned configuration will already have its one and only section selected.

Note to implementors:
If your implementation returns a specialized sub-class for this, make sure it is either not an AcWriteableConfig implementation or if it is that writing to it does not alter the original section's information.
Probably your best solution is to return an AcMemConfig with a copy of the section, like the original classes do.

Reimplemented from AnyConfig::AcConfiguration.

void AnyConfig::AcMySQLConfig::display ( ) [virtual]
 

Mostly for debugging purposes, write out the configuration to stdout.

Reimplemented from AnyConfig::AcConfiguration.

bool AnyConfig::AcMySQLConfig::getSectionStr ( const char * pSection,
const char * pKey,
CString & rValue ) [virtual]
 

Like getStr() but can fetch keys from another section than the current one.

The default implementation just pushes _currentSection on stack, replaces it with the supplied section and calls the regular getStr() function.

Parameters:
pKey   The key to fetch.
pSection   The section to fetch it from.
rValue   The value found, if any.
Returns:
False if the key could not be found in the specified section.

Reimplemented from AnyConfig::AcConfiguration.

bool AnyConfig::AcMySQLConfig::getStr ( const char * pKey,
CString & rValue ) [virtual]
 

Retrieve a string from the configuration for the specified key.

Parameters:
pKey   The key to look for (in the current section).
rValue   Will be filled in with the value found.
Returns:
False if the key could not be located in the current section (if any).

Reimplemented from AnyConfig::AcConfiguration.

bool AnyConfig::AcMySQLConfig::initRequired ( ) [virtual]
 

Returns true if the derived AcConfiguration requires to be initialized.

See the initialize() function for the various derived classes for more details. Note that this function must return false once the initialization has been done once.

Reimplemented from AnyConfig::AcConfiguration.

bool AnyConfig::AcMySQLConfig::initialize ( AcConfiguration & parentConfig ) [virtual]
 

Initialize the configuration using another, probably more primitive, parent configuration.

Parameters:
parentConfig   The parent configuration to use. The MySQL configuration needs to gain access to the MySQL database server (duh). Therefore it needs to obtain all of the following items from the parent configuration:
  • HOSTNAME The hostname of the MySQL database server. Defaults to localhost if not provided.
  • USERNAME The username for MySQL. Defaults to blank if not provided.
  • PASSWORD The password for the above user. Defaults to blank if not provided.
  • DATABASE The MySQL database to use. Defaults to 'test' if not provided.
  • CFGTABLE The name of the table to use. Defaults to 'config' if not provided. Also, it the table does not exist, it will be created (yielding an empty configuration).
  • KEEPCONN Optional. If true the MySQL class will keep its connection open. Defaults to true for performance reasons.
Returns:
False if the initialization failed.

Reimplemented from AnyConfig::AcConfiguration.

bool AnyConfig::AcMySQLConfig::keyExists ( const char * pKey ) [virtual]
 

Check if a given key exists.

Parameters:
key   The key to look for in [the current section in] the configuration.
Returns:
True if the key exists.

Reimplemented from AnyConfig::AcConfiguration.

void * AnyConfig::AcMySQLConfig::query ( const char * pKey,
const char * pSection ) [protected, virtual]
 

Perform the query to obtain the value for the key.

Parameters:
pKey   The key to find.
pSection   The section to find it in.
Returns:
Is either a MYSQL_RES pointer or a NULL pointer.

void AnyConfig::AcMySQLConfig::release ( void * pRes ) [protected, virtual]
 

Release the result of a MySQL query.

void AnyConfig::AcMySQLConfig::setSectionStr ( const char * pSection,
const char * pKey,
const char * pValue ) [virtual]
 

Like setStr() but can set keys in another section than the current one.

The default implementation just pushes _currentSection on stack, replaces it with the supplied section and calls the regular setStr() function.

Parameters:
pKey   The key to set.
pSection   The section to set it in.
pValue   The value to set it to.

Reimplemented from AnyConfig::AcWriteableConfig.

void AnyConfig::AcMySQLConfig::setStr ( const char * pKey,
const char * pValue ) [virtual]
 

Set the configuration item to the passed string value.

Parameters:
pKey   The item to set.
pValue   The value to set it to. This must be a valid pointer to a valid C string.

Reimplemented from AnyConfig::AcWriteableConfig.


The documentation for this class was generated from the following files:
Generated at Wed Nov 21 11:34:19 2001 for AnyConfig by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001