WORM 0.2
A C++ DAL/ORM code generation framework
Public Member Functions | Protected Member Functions | Protected Attributes | Friends

WSql::WSqlDriver Class Reference

The WSqlDriver class is an abstract base class for database drivers. More...

#include <wsqldriver.h>

Inheritance diagram for WSql::WSqlDriver:

List of all members.

Public Member Functions

 WSqlDriver (WSqlDatabase *db)
 Construct a driver with the given database db.
virtual ~WSqlDriver ()
 Destroys the driver and created resources.
virtual bool open ()=0
virtual void close ()=0
virtual bool query (std::string sql)=0
virtual std::vector< std::string > tableNames ()=0
virtual WSqlTable tableMetaData (const std::string &tableName)=0
virtual WSqlResultresult (bool iscached=true)
virtual WSqlError error () const
virtual bool isValid () const
virtual bool isOpen () const
WSqlTable findTable (std::string tablename) const
 Locate the metadata table for tablename in the cache.
bool hasError () const
void setDatabase (WSqlDatabase *dp)

Protected Member Functions

WSqlTablegetTable (const std::string &tablename)
 Return a reference to the metadata table for tablename in the cache.
void setIsValid (bool b)
void setIsOpen (bool o)
void setHasError (bool e)
void setError (const WSqlError &e)
 Sets the the current error to error.
void setError (const std::string &text, WSqlError::ErrorType type, WSqlError::ErrorSeverity severity, bool isvalid=true)
 Set an error with text and types and also set isValid.
void setError (const std::string &text)
void setError (const char *text)

Protected Attributes

WSqlDatabase_database
WSqlResult_result
std::vector< WSqlTable_tables

Friends

class WSqlDatabase

Detailed Description

The WSqlDriver class is an abstract base class for database drivers.

This class can not be used directly. This must be implemented for a specific database server (eg. SQLite or MySQL ).Also, prefer not to use a driver directly but rather an instance of WSqlDatabase to access the database (recommended).

See also:
WSqlDatabase WSqliteDriver WMysqlDriver

Definition at line 33 of file wsqldriver.h.


Constructor & Destructor Documentation

WSql::WSqlDriver::WSqlDriver ( WSqlDatabase db)

Construct a driver with the given database db.

Constructs a driver with a pointer to the database - note that this is the only way to create a driver; all connection information (eg. database name, user name, etc. ) is set in and managed by WSqlDatabase - the driver will obtain what it needs to know from there.

Parameters:
WSqlDatabase*db - the database using this driver.

Definition at line 45 of file wsqldriver.cpp.

WSql::WSqlDriver::~WSqlDriver ( ) [virtual]

Destroys the driver and created resources.

Note that the result pointer obtained from getResult() is invalid after the object is destroyed! This means you do not need to (and should not) delete a result from the driver and that you also must be careful not to use it after a WSqlDriver object has been destroyed.

Definition at line 61 of file wsqldriver.cpp.


Member Function Documentation

bool WSql::WSqlDriver::close ( ) [pure virtual]

Derived classes must reimplement this pure virtual function in order to close the database connection. Return true on success, false on failure.

See also:
open(), setOpen()

Implemented in WSql::WMysqlDriver, and WSql::WSqliteDriver.

WSqlError WSql::WSqlDriver::error ( ) const [inline, virtual]

Returns a WSqlError object which contains information about the last error that occurred on the database.

Definition at line 49 of file wsqldriver.h.

WSqlTable WSql::WSqlDriver::findTable ( std::string  tablename) const

Locate the metadata table for tablename in the cache.

This returns a WSqlTable of metadata for a given table by looking it up in the local cache. If the table has been initialized it will be returned if not an invalid (ie. empty) WSqlTable object will be returned.

Parameters:
std::stringtablename - the name of the table to find
Return values:
WSqlTablevalid if found in cache

Definition at line 109 of file wsqldriver.cpp.

WSqlTable * WSql::WSqlDriver::getTable ( const std::string &  tablename) [protected]

Return a reference to the metadata table for tablename in the cache.

This returns a reference to the WSqlTable of metadata for a given table by looking it up in the local cache. If the table has been initialized it will be returned if not a null (0) pointer will be returned. This function is used internally to modify tables - it is not recommended for use otherwise.

Parameters:
std::stringtablename - the name of the table to find
Return values:
WSqlTable*valid if found in cache

Definition at line 130 of file wsqldriver.cpp.

bool WSql::WSqlDriver::hasError ( ) const [inline]

Returns true if the there was an error during the last action, otherwise returns false.

Definition at line 55 of file wsqldriver.h.

bool WSql::WSqlDriver::isOpen ( ) const [inline, virtual]

Returns true if the database connection is open; otherwise returns false.

Definition at line 51 of file wsqldriver.h.

virtual bool WSql::WSqlDriver::isValid ( ) const [inline, virtual]

Definition at line 50 of file wsqldriver.h.

bool WSql::WSqlDriver::open ( ) [pure virtual]

Derived classes must reimplement this pure virtual function to open a database connection on the database

The function must return true on success and false on failure.

See also:
setOpen()

Implemented in WSql::WMysqlDriver, and WSql::WSqliteDriver.

virtual bool WSql::WSqlDriver::query ( std::string  sql) [pure virtual]
virtual WSqlResult* WSql::WSqlDriver::result ( bool  iscached = true) [inline, virtual]

Reimplemented in WSql::WMysqlDriver, and WSql::WSqliteDriver.

Definition at line 48 of file wsqldriver.h.

void WSql::WSqlDriver::setDatabase ( WSqlDatabase dp) [inline]

Definition at line 58 of file wsqldriver.h.

void WSql::WSqlDriver::setError ( const WSqlError error) [protected]

Sets the the current error to error.

This method sets the current error and pushes any previous error onto the error stack.

Parameters:
WSqlErrorerror - the error to set

Definition at line 93 of file wsqldriver.cpp.

void WSql::WSqlDriver::setError ( const char *  text) [inline, protected]

Definition at line 77 of file wsqldriver.h.

void WSql::WSqlDriver::setError ( const std::string &  text) [inline, protected]

Definition at line 74 of file wsqldriver.h.

void WSql::WSqlDriver::setError ( const std::string &  text,
WSqlError::ErrorType  type,
WSqlError::ErrorSeverity  severity,
bool  isvalid = true 
) [protected]

Set an error with text and types and also set isValid.

A convenience function for creating and setting the error to an error with the message in text of ErrorType type and ErrorSeverity severity. Also sets hasError to be true and isValid to be isvalid - Note: the default for isvalid is "true".

Parameters:
std::stringtext - the message
WSqlError::ErrorTypetype - what kind of error
WSqlError::ErrorSeverityseverity - how severe the error is
boolisvalid - set the isValid flag of the driver to isvalid (default true).

Definition at line 80 of file wsqldriver.cpp.

void WSql::WSqlDriver::setHasError ( bool  e) [inline, protected]

Definition at line 67 of file wsqldriver.h.

void WSql::WSqlDriver::setIsOpen ( bool  o) [inline, protected]

Definition at line 66 of file wsqldriver.h.

void WSql::WSqlDriver::setIsValid ( bool  b) [inline, protected]

Definition at line 65 of file wsqldriver.h.

virtual WSqlTable WSql::WSqlDriver::tableMetaData ( const std::string &  tableName) [pure virtual]
std::vector< std::string > WSql::WSqlDriver::tableNames ( ) [pure virtual]

Returns a list of the names of the tables in the database.

tableType defines what types of tables to return in the list, meaning: normal tables, views, system tables or all of the above.

See also:
WSql::TableType

Implemented in WSql::WMysqlDriver, and WSql::WSqliteDriver.


Friends And Related Function Documentation

friend class WSqlDatabase [friend]

Definition at line 61 of file wsqldriver.h.


Member Data Documentation

Definition at line 79 of file wsqldriver.h.

Definition at line 80 of file wsqldriver.h.

std::vector<WSqlTable> WSql::WSqlDriver::_tables [protected]

Definition at line 81 of file wsqldriver.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Defines