Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | Related Pages | Examples

Database.h

00001 /* -*- c++ -*-
00002  * __BEGIN_COPYRIGHT
00003  * SimpleDB API
00004  * 
00005  * Copyright (C) 2005 Eminence Technology Pty Ltd
00006  * 
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  * 
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  * 
00017  * You can view the GNU Lesser General Public Licence at
00018  * http://www.gnu.org/licenses/lgpl.html or you can write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  * 
00021  * Eminence Technology Pty Ltd can be contacted by writing to
00022  * Eminence Technology, PO Box 118, Moorooka QLD 4105, Australia.
00023  * Alternatively, you may email opensource [at] eminence [dot] com [dot] au
00024  * __END_COPYRIGHT
00025  */
00026 
00027 #ifndef __SIMPLEDB_DATABASE_H_
00028 #define __SIMPLEDB_DATABASE_H_ 1
00029 
00030 #include <string>
00031 #include <sql.h>
00032 #include <sqlext.h>
00033 #include <iostream>
00034 #include "Query.h"
00035 #include "Exception.h"
00036 
00037 namespace SimpleDB {
00038 
00045   class Database {
00046 
00047   public:
00048 
00052     class Exception : public SimpleDB::Exception {
00053     public:
00054       Exception(const std::string& message) : SimpleDB::Exception(message) {};
00055     };
00056 
00060     class NoDataException : public Exception {
00061     public:
00062       
00066       NoDataException() : Exception("No data returned.") {
00067       }
00068     };
00069   
00074     Database(std::string dsn);
00075   
00080     Query newQuery() const;
00081 
00086     void voidQuery (const std::string& query) const;
00087     
00098     long intQuery (const std::string& query) const;
00099     
00105     std::string strQuery (const std::string& query, long bufSize = 1000) const;
00106     
00113     static const std::string escapeString(const std::string& input);
00114     
00119     static const std::string  boolToStr (const bool in);
00120     
00125     const SQLHDBC getConnectionHandle() const;
00126     
00130     virtual ~Database() ;
00131   protected:
00132   
00135     SQLHDBC connectionHandle;
00136 
00141     SQLHENV odbc_environment_handle;
00142   };
00143 
00144 }
00145 
00146 inline
00147 std::ostream& operator<<(std::ostream& strm, const std::exception &e) {
00148   strm << "Database::Exception: " << e.what();
00149   return strm;
00150 }
00151 
00152 #endif

Copyright (C) 2005 Eminence Technology Pty Ltd.
Documentation pages generated by doxygen.

SourceForge.net Logo