SQLDatabase.h++

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002    commonc++ - A C++ Common Class Library
00003    Copyright (C) 2005-2012  Mark A Lindner
00004 
00005    This file is part of commonc++.
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 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    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public
00018    License along with this library; if not, write to the Free
00019    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020    ---------------------------------------------------------------------------
00021 */
00022 
00023 #ifndef __ccxx_SQLDatabase_hxx
00024 #define __ccxx_SQLDatabase_hxx
00025 
00026 #include <commonc++/Common.h++>
00027 #include <commonc++/IOException.h++>
00028 #include <commonc++/InterruptedException.h++>
00029 #include <commonc++/String.h++>
00030 #include <commonc++/SQLException.h++>
00031 
00032 namespace ccxx {
00033 
00034 class SQLQuery; // fdw decl
00035 
00043 class COMMONCPPDB_API SQLDatabase
00044 {
00045   public:
00046 
00048   SQLDatabase();
00049 
00051   virtual ~SQLDatabase() throw();
00052 
00054   String getVersion() throw();
00055 
00065   void open(const String &path, bool create = true, bool readOnly = false)
00066     throw(IOException);
00067 
00071   void close() throw();
00072 
00081   uint_t executeSQL(const String &sql)
00082     throw(SQLException, InterruptedException);
00083 
00089   void interrupt() throw(SQLException);
00090 
00096   bool isAutoCommit() throw(SQLException);
00097 
00105   SQLQuery *prepareQuery(const String &sql) throw(SQLException);
00106 
00112   int64_t getGeneratedKey() throw(SQLException);
00113 
00115   uint_t getModifiedRowCount() throw(SQLException);
00116 
00121   void begin() throw(SQLException);
00122 
00129   void commit() throw(SQLException, TimeoutException);
00130 
00137   void rollback() throw(SQLException, TimeoutException);
00138 
00139   protected:
00140 
00148   virtual bool onProgress();
00149 
00153   virtual void onCommit();
00154 
00158   virtual void onRollback();
00159 
00160   private:
00161 
00162   void _checkOpened() throw(SQLException);
00163 
00164   static int _progressCallback(void *self);
00165   static int _commitCallback(void *self);
00166   static void _rollbackCallback(void *self);
00167   static int _execCallback(void *self, int cols, char **values,
00168                            char **colnames);
00169 
00170   class Private; // fwd decl
00171   Private *_private;
00172 
00173   CCXX_COPY_DECLS(SQLDatabase);
00174 };
00175 
00184 class COMMONCPPDB_API ScopedTransaction
00185 {
00186   public:
00187 
00193   ScopedTransaction(SQLDatabase &database) throw(SQLException);
00194 
00198   ~ScopedTransaction() throw();
00199 
00206   void commit() throw(SQLException, TimeoutException);
00207 
00208   private:
00209 
00210   SQLDatabase &_database;
00211   bool _committed;
00212 
00213   CCXX_COPY_DECLS(ScopedTransaction);
00214 };
00215 
00216 }; // namespace ccxx
00217 
00218 #endif // __ccxx_SQLDatabase_hxx
00219 
00220 /* end of header file */
Generated on Sat Nov 26 16:49:07 2011 for libcommonc++ by  doxygen 1.6.3