sqlite3_db.h

Go to the documentation of this file.
00001 /*                                                              
00002  * A database abstraction layer for C++ and ACE framework
00003  * 
00004  * (C) 2006-2007 Thralling Penguin LLC. All rights reserved.
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA                                                                
00019  */
00020 #include <fstream>
00021 #include <iomanip>
00022 #include "ace/os_include/os_stddef.h"
00023 #include "ace/OS_Memory.h"
00024 #include "db.h"
00025 #include "sqlite3.h"
00026 
00027 namespace DB
00028 {
00029     class Sqlite3_Connection;
00030 
00031     class Sqlite3_ResultSet : public ResultSet
00032     {
00033         friend class Sqlite3_Connection;
00034     protected:
00035         Sqlite3_ResultSet(sqlite3_stmt *res) : res_(res) {};
00036         ~Sqlite3_ResultSet();
00037     private:
00038         Sqlite3_ResultSet() {};
00039         Sqlite3_ResultSet(const Sqlite3_ResultSet &old);
00040         const Sqlite3_ResultSet &operator=(const Sqlite3_ResultSet &old);
00041 
00042     public:
00043         bool close(void);
00044         bool next(void);
00045 
00046         unsigned long recordCount(void) const;
00047         unsigned int findColumn(const char *field) const;
00048 
00049         const char *getString(const int idx) const;
00050         const int getInteger(const int idx) const;
00051         const bool getBool(const int idx) const;
00052         const time_t getUnixTime(const int idx) const;
00053         const double getDouble(const int idx) const;
00054         const float getFloat(const int idx) const;
00055         const long getLong(const int idx) const;
00056         const short getShort(const int idx) const;
00057 
00058         // Overload the new/delete opertors so the object will be
00059         // created/deleted using the memory allocator associated with the
00060         // DLL/SO.
00061         void *operator new (size_t bytes);
00062         #if defined (ACE_HAS_NEW_NOTHROW)
00063         // Overloaded new operator, nothrow_t variant.
00064         void *operator new (size_t bytes, const ACE_nothrow_t&);
00065         #if !defined (ACE_LACKS_PLACEMENT_OPERATOR_DELETE)
00066         void operator delete (void *p, const ACE_nothrow_t&) throw ();
00067         #endif /* ACE_LACKS_PLACEMENT_OPERATOR_DELETE */
00068         #endif
00069         void operator delete (void *ptr);
00070 
00071     private:
00072         sqlite3_stmt *res_;
00073     };
00074 
00075     class Sqlite3_Connection : public Connection
00076     {
00077     private:
00078         Sqlite3_Connection(const Sqlite3_Connection &old);
00079         const Sqlite3_Connection &operator=(const Sqlite3_Connection &old);
00080 
00081     public:
00082         Sqlite3_Connection() : db_(NULL) {};
00083         ~Sqlite3_Connection() { close(); }
00084 
00085         bool open(const char *database, const char *host, const int port, const char *user, const char *pass);
00086         bool close(void);
00087         bool isConnected(void);
00088         bool execute(const char *sql);
00089         ResultSet *executeQuery(const char *sql);
00090         char *escape(const char *);
00091         const char *unixtimeToSql(const time_t);
00092         const unsigned long insertId(void);
00093 
00094         bool beginTrans(void);
00095         bool commitTrans(void);
00096         bool rollbackTrans(void);
00097         bool setTransactionMode(const enum TRANS_MODE mode);
00098 
00099         unsigned int errorno(void) const;
00100         const char *errormsg(void) const;
00101 
00102         const char *version(void) const;
00103 
00104         // Overload the new/delete opertors so the object will be
00105         // created/deleted using the memory allocator associated with the
00106         // DLL/SO.
00107         void *operator new (size_t bytes);
00108         #if defined (ACE_HAS_NEW_NOTHROW)
00109         // Overloaded new operator, nothrow_t variant.
00110         void *operator new (size_t bytes, const ACE_nothrow_t&);
00111         #if !defined (ACE_LACKS_PLACEMENT_OPERATOR_DELETE)
00112         void operator delete (void *p, const ACE_nothrow_t&) throw ();
00113         #endif /* ACE_LACKS_PLACEMENT_OPERATOR_DELETE */
00114         #endif
00115         void operator delete (void *ptr);
00116 
00117     private:
00118         sqlite3 *db_;
00119         int errorno_;
00120         std::string errormsg_;
00121     };
00122 }

Generated on Tue Apr 24 18:59:42 2007 for DbAbstract by  doxygen 1.4.7