libcommonc++  0.7
SQLDatabase.h++
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2  commonc++ - A C++ Common Class Library
3  Copyright (C) 2005-2014 Mark A Lindner
4 
5  This file is part of commonc++.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public
18  License along with this library; if not, write to the Free
19  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  ---------------------------------------------------------------------------
21 */
22 
23 #ifndef __ccxx_SQLDatabase_hxx
24 #define __ccxx_SQLDatabase_hxx
25 
26 #include <commonc++/Common.h++>
29 #include <commonc++/String.h++>
31 
32 namespace ccxx {
33 
34 class SQLQuery; // fdw decl
35 
44 {
45  public:
46 
48  SQLDatabase();
49 
51  virtual ~SQLDatabase();
52 
54  String getVersion();
55 
66  void open(const String& path, bool create = true, bool readOnly = false);
67 
73  void close();
74 
84  uint_t executeSQL(const String& sql);
85 
92  void interrupt();
93 
100  bool isAutoCommit();
101 
110  SQLQuery* prepareQuery(const String& sql);
111 
118  int64_t getGeneratedKey();
119 
121  uint_t getModifiedRowCount();
122 
128  void begin();
129 
137  void commit();
138 
146  void rollback();
147 
148  protected:
149 
158  virtual bool onProgress();
159 
164  virtual void onCommit();
165 
170  virtual void onRollback();
171 
172  private:
173 
174  void _checkOpened();
175 
176  static int _progressCallback(void* self);
177  static int _commitCallback(void* self);
178  static void _rollbackCallback(void* self);
179  static int _execCallback(void* self, int cols, char** values,
180  char** colnames);
181 
182  class Private; // fwd decl
183  Private* _private;
184 
186 };
187 
197 {
198  public:
199 
206  SQLTransaction(SQLDatabase& database);
207 
212  ~SQLTransaction();
213 
221  void commit();
222 
223  private:
224 
225  SQLDatabase& _database;
226  bool _committed;
227 
229 };
230 
231 } // namespace ccxx
232 
233 #endif // __ccxx_SQLDatabase_hxx
unsigned int uint_t
An alias for unsigned int.
Definition: Integers.h++:74
A scoped database transaction.
Definition: SQLDatabase.h++:196
An SQL prepared statement that can be efficiently executed multiple times.
Definition: SQLQuery.h++:57
A class representing a session with an embedded SQL database.
Definition: SQLDatabase.h++:43
A flexible, reference counted, copy-on-write, thread-safe, nullable string.
Definition: String.h++:50
#define CCXX_COPY_DECLS(CLASS)
Inlines declarations of a copy constructor and assignment operator for the class CLASS.
Definition: Common.h++:295
Definition: AllocationMap.c++:25
#define COMMONCPPDB_API
Definition: Common.h++:127