WORM 0.2
A C++ DAL/ORM code generation framework

src/sql/wsqldriver.h

Go to the documentation of this file.
00001 /*
00002  *    WORM - a DAL/ORM code generation framework
00003  *    Copyright (C) 2011  Erik Winn <erikwinnmail@yahoo.com>
00004  * 
00005  *    This program is free software: you can redistribute it and/or modify
00006  *    it under the terms of the GNU General Public License as published by
00007  *    the Free Software Foundation, either version 3 of the License, or
00008  *    (at your option) any later version.
00009  * 
00010  *    This program is distributed in the hope that it will be useful,
00011  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *    GNU General Public License for more details.
00014  * 
00015  *    You should have received a copy of the GNU General Public License
00016  *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017  */
00018 
00019 #ifndef WSQLDRIVER_H
00020 #define WSQLDRIVER_H
00021 
00022 #include <string>
00023 #include "wsqldatabase.h"
00024 #include "wsqlerror.h"
00025 #include "wsqlresult.h"
00026 
00027 namespace WSql
00028 {
00029 
00030 class WSqlTable;
00031 class WSqlDatabase;
00032 
00033 class WSqlDriver
00034 {
00035 
00036     public:
00037         WSqlDriver( WSqlDatabase *db );
00038         virtual ~WSqlDriver();
00039 
00040         virtual bool open() = 0;
00041         virtual void close() = 0;
00042         virtual bool query(std::string sql) = 0;
00043         //virtual bool execute(std::string sql) = 0;
00044         // virtual WSqlResult exec(const WSqlQuery &queryObject) = 0;
00045         virtual std::vector<std::string> tableNames() = 0;
00046         virtual WSqlTable tableMetaData( const std::string &tableName ) = 0;
00047                 
00048         virtual WSqlResult* result(bool iscached=true){return _result;}
00049         virtual WSqlError error() const { return _error;}
00050         virtual bool isValid()const { return _isValid;}
00051         virtual bool isOpen()const { return _isOpen;}
00052         
00053         WSqlTable findTable( std::string tablename )const;
00054         
00055         bool hasError()const { return _hasError;}
00056 
00057 //note: maybe auto disconnect/reconnect here?  or, do we even need this?              
00058         void setDatabase( WSqlDatabase *dp ) { _database = dp;}
00059 
00060     protected:
00061         friend class WSqlDatabase;
00062 
00063         WSqlTable* getTable( const std::string& tablename );
00064         
00065         void setIsValid( bool b ) { _isValid = b;}
00066         void setIsOpen( bool o ) { _isOpen = o;}
00067         void setHasError( bool e ) { _hasError = e;}
00068         
00069         void setError(const WSqlError& e );
00070         void setError(const std::string& text,
00071                       WSqlError::ErrorType type,
00072                       WSqlError::ErrorSeverity severity,
00073                       bool isvalid = true );
00074         inline void setError(const std::string& text){
00075             setError(text,WSql::WSqlError::DRIVER, WSql::WSqlError::WARNING);
00076         }
00077         inline void setError(const char * text){setError(std::string(text));}
00078         
00079         WSqlDatabase *_database;
00080         WSqlResult * _result;
00081         std::vector<WSqlTable> _tables;
00082         
00083     private:
00084         bool _isValid;
00085         bool _isOpen;
00086         bool _hasError;
00087         std::string _databaseName;
00088         WSqlError _error;
00089         std::vector<WSqlError> _errors;
00090 };
00091 
00092 } // namespace WSql
00093 
00094 #endif // WSQLDRIVER_H
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Defines