WORM 0.2
A C++ DAL/ORM code generation framework
|
The WSqlDriver class is an abstract base class for database drivers. More...
#include <wsqldriver.h>
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 WSqlResult * | result (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 | |
WSqlTable * | getTable (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 |
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).
Definition at line 33 of file wsqldriver.h.
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.
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.
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.
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.
std::string | tablename - the name of the table to find |
WSqlTable | valid 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.
std::string | tablename - the name of the table to find |
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.
Implemented in WSql::WMysqlDriver, and WSql::WSqliteDriver.
virtual bool WSql::WSqlDriver::query | ( | std::string | sql | ) | [pure virtual] |
Implemented in WSql::WMysqlDriver, and WSql::WSqliteDriver.
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.
WSqlError | error - 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".
std::string | text - the message |
WSqlError::ErrorType | type - what kind of error |
WSqlError::ErrorSeverity | severity - how severe the error is |
bool | isvalid - 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] |
Implemented in WSql::WMysqlDriver, and WSql::WSqliteDriver.
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.
Implemented in WSql::WMysqlDriver, and WSql::WSqliteDriver.
friend class WSqlDatabase [friend] |
Definition at line 61 of file wsqldriver.h.
WSqlDatabase* WSql::WSqlDriver::_database [protected] |
Definition at line 79 of file wsqldriver.h.
WSqlResult* WSql::WSqlDriver::_result [protected] |
Definition at line 80 of file wsqldriver.h.
std::vector<WSqlTable> WSql::WSqlDriver::_tables [protected] |
Definition at line 81 of file wsqldriver.h.