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

src/sql/wsqldatabase.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 WSQLDATABASE_H
00020 #define WSQLDATABASE_H
00021 
00022 #include <string>
00023 #include <vector>
00024 #include "wsql.h"
00025 #include "wsqlerror.h"
00026 #include "wsqltable.h"
00027 #include "wsqldriver.h"
00028 
00029 namespace WSql {
00030 
00031 class WSqlResult;
00032 class WSqlDriver;
00033 
00034 class WSqlDatabase
00035 {
00036     
00037 public:
00038     
00039     WSqlDatabase();
00040     WSqlDatabase(const WSql::DriverType &type);
00041     WSqlDatabase(const WSqlDatabase &other);
00042 
00043 ~WSqlDatabase();
00044 
00045     WSqlDatabase &operator=(const WSqlDatabase &other);
00046 
00047     // Connecting and errors ..
00048     bool open();
00049     bool open(const std::string& username, const std::string& password);
00050     void close();
00051     bool isOpen() const;
00052     bool hasError() const;
00053     WSqlError error() const;
00054     std::vector<std::string> errors();
00055     bool isValid() const;
00056     
00057     //General connection configurations ..
00058     std::string databaseName() const;
00059     std::string userName() const;
00060     std::string password() const;
00061     std::string hostName() const;
00062     int port() const {return _port;}
00063     std::string connectionOptions() const;
00064     WSql::DriverType driverType(){return _driverType;}
00065         
00066     void setDatabaseName(const std::string& name);
00067     void setUserName(const std::string& name);
00068     void setPassword(const std::string& password);
00069     void setHostName(const std::string& host);
00070     void setPort(int p);
00071     void setConnectOptions(const std::string& options = std::string());
00072     void setDriverType(WSql::DriverType t);
00073     
00074     void addError(const WSqlError& e){_errorStack.push_back(e);}
00075     //REMOVE:?
00076     void setDriver(WSqlDriver *d){_driver=d;}
00077     
00078     //Raw driver access ..
00079     WSqlDriver* driver() const;
00080     WSqlDriver* handle() const {return driver();}
00081     
00082     //Metadata
00083     const std::vector<std::string>& tableNames(WSql::TableType type = WSql::Tables);
00084     WSqlTable tableMetaData( const std::string &tableName ) const;
00085     void initMetaData();
00086    
00087     //Query interaction - wrapper around driver ..
00088     bool query(const std::string& sql );
00089 //    bool execute(const std::string& sql );
00090     WSqlResult* result(bool iscached=true);
00091     bool initDriver();
00092     
00093 private:
00094     void init();
00095     
00096     bool _isValid;
00097     WSql::DriverType _driverType;
00098     WSqlDriver* _driver;
00099     std::string _databaseName;
00100     std::string _userName;
00101     std::string _password;
00102     std::string _hostname;
00103     std::string _connectionOptions;
00104     int _port;
00105 
00106     std::vector<std::string> _tableNames;
00107     std::vector<WSqlError> _errorStack; 
00108 };
00109 
00110 } //namespace WSql
00111 
00112 #endif // WSQLDATABASE_H
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Defines