/sqlite3cc

To get this branch, use:
bzr branch http://bzr.ed.am/sqlite3cc

« back to all changes in this revision

Viewing changes to include/sqlite3cc/transaction.h

  • Committer: edam
  • Date: 2010-07-29 06:28:53 UTC
  • Revision ID: edam@waxworlds.org-20100729062853-4i2fec52m86mh724
- made basic_statement::step() protected, for use by query and command only
- moved basic_statement::operator<<() to command and query instead; one needs to accept sqlite::exec, the other doesn't
- added tests for query::operator<<()
- added code to invlaidate in-progress queries during any transaction rollbacks (currently segfaults in basic_statement::finalize())
- added new sqlite_error constructor that obtains a full error message
- implemented database::database_mutex_guard class
- swapped command's step mutex in favour of the database mutex

Show diffs side-by-side

added added

removed removed

25
25
 
26
26
 
27
27
#include <boost/utility.hpp>
 
28
#include <string>
28
29
 
29
30
 
30
31
namespace sqlite
34
35
class database;
35
36
 
36
37
 
 
38
/**
 
39
 * A basic (default, deferred) transaction.
 
40
 */
37
41
class basic_transaction
38
42
        :
39
43
        private boost::noncopyable
72
76
//                                                                implementation
73
77
protected:
74
78
 
75
 
        /* the database on which to act */
 
79
        /** close any in-progress statements */
 
80
        void invalidate_queries();
 
81
 
 
82
        /** the database on which to act */
76
83
        database &_database;
77
84
 
78
85
};
81
88
////////////////////////////////////////////////////////////////////////////////
82
89
 
83
90
 
 
91
/**
 
92
 * An exclusive transaction
 
93
 */
 
94
class immediate_transaction
 
95
        :
 
96
        public basic_transaction
 
97
{
 
98
//______________________________________________________________________________
 
99
//                                                                 instantiation
 
100
public:
 
101
 
 
102
        /**
 
103
         * Constructor that provides a database upon which to act
 
104
         * @param database a database
 
105
         */
 
106
        explicit immediate_transaction(
 
107
                database &database );
 
108
 
 
109
//______________________________________________________________________________
 
110
//                                                              public interface
 
111
public:
 
112
 
 
113
        /**
 
114
         * Begin the transaction
 
115
         */
 
116
        virtual void begin();
 
117
 
 
118
};
 
119
 
 
120
 
 
121
////////////////////////////////////////////////////////////////////////////////
 
122
 
 
123
 
 
124
/**
 
125
 * An exclusive transaction
 
126
 */
84
127
class exclusive_transaction
85
128
        :
86
129
        public basic_transaction
111
154
////////////////////////////////////////////////////////////////////////////////
112
155
 
113
156
 
 
157
/**
 
158
 * A recursive transaction, allowing transactions to be nested.
 
159
 */
114
160
class recursive_transaction
115
161
        :
116
162
        public basic_transaction
158
204
////////////////////////////////////////////////////////////////////////////////
159
205
 
160
206
 
 
207
/**
 
208
 * A scope guard, or sentinel for use with one of the transaction classes.
 
209
 */
161
210
template< class T = basic_transaction >
162
211
class transaction_guard
163
212
        :
175
224
                database &database )
176
225
                :
177
226
                _transaction( database ),
 
227
                _database( database ),
178
228
                _released( false )
179
229
        {
180
230
                _transaction.begin();
182
232
 
183
233
        ~transaction_guard()
184
234
        {
185
 
                if( !_released )
186
 
                        _transaction.rollback();
 
235
                if( !_released ) {
 
236
                        try {
 
237
                                _transaction.rollback();
 
238
                        }
 
239
                        catch( ... ) {
 
240
                        }
 
241
                }
187
242
        }
188
243
 
189
244
//______________________________________________________________________________
205
260
//                                                                implementation
206
261
protected:
207
262
 
208
 
        /* the transaction */
 
263
        /** the transaction */
209
264
        T _transaction;
210
265
 
211
 
        /* have we released the transaction yet? */
 
266
        /** the database */
 
267
        database &_database;
 
268
 
 
269
        /** have we released the transaction yet? */
212
270
        bool _released;
213
271
 
214
272
};