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

src/sql/wsqldriver.cpp

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 #include "wsqldriver.h"
00020 #include "wsqlerror.h"
00021 #include "wsqlfield.h"
00022 
00023 namespace WSql {
00024 
00045 WSqlDriver::WSqlDriver(WSqlDatabase* db)
00046 {
00047     _database=db;
00048     _result=0;
00049     _isOpen=false;
00050     _isValid=false;
00051     _hasError=false;
00052 }
00053 
00061 WSqlDriver::~WSqlDriver()
00062 {
00063     delete _result;
00064     _result = 0;
00065     _tables.clear();
00066     _errors.clear();
00067 }
00068 
00080 void WSqlDriver::setError(const std::string& text, WSqlError::ErrorType type, 
00081                           WSqlError::ErrorSeverity severity, bool isvalid)
00082 {
00083     setError(WSqlError(text,-1,type,severity)); 
00084     setIsValid(isvalid);
00085     setHasError(true);
00086 }
00093 void WSqlDriver::setError(const WSqlError& error ) 
00094 {
00095     if(_hasError)  
00096         _errors.push_back(_error);
00097     _error = error; 
00098     _hasError = true;
00099 }
00100 
00109 WSqlTable WSqlDriver::findTable( std::string tablename ) const
00110 {
00111     if ( !_tables.empty() ) {
00112         std::vector<WSqlTable>::const_iterator it = _tables.begin();
00113         for ( ; it != _tables.end();++it )
00114             if ( it->name().compare( tablename ) == 0 )
00115                 return *it;
00116     }
00117     return WSqlTable();
00118 }
00119 
00130 WSqlTable* WSqlDriver::getTable( const std::string& tablename )
00131 {
00132     WSqlTable* ptrToReturn = 0;
00133     if ( !_tables.empty() ) {
00134         std::vector<WSqlTable>::iterator it = _tables.begin();
00135         for ( ; it != _tables.end();++it )
00136             if ( it->name().compare( tablename ) == 0 )
00137             {
00138                 ptrToReturn = &(*it);
00139                 break;
00140             }
00141     }
00142     return ptrToReturn;
00143 }
00144 
00215 } //namespace WSql
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Defines