/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

35
35
class database;
36
36
 
37
37
 
 
38
/**
 
39
 * A basic (default, deferred) transaction.
 
40
 */
38
41
class basic_transaction
39
42
        :
40
43
        private boost::noncopyable
73
76
//                                                                implementation
74
77
protected:
75
78
 
76
 
        /* the database on which to act */
 
79
        /** close any in-progress statements */
 
80
        void invalidate_queries();
 
81
 
 
82
        /** the database on which to act */
77
83
        database &_database;
78
84
 
79
85
};
82
88
////////////////////////////////////////////////////////////////////////////////
83
89
 
84
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
 */
85
127
class exclusive_transaction
86
128
        :
87
129
        public basic_transaction
112
154
////////////////////////////////////////////////////////////////////////////////
113
155
 
114
156
 
 
157
/**
 
158
 * A recursive transaction, allowing transactions to be nested.
 
159
 */
115
160
class recursive_transaction
116
161
        :
117
162
        public basic_transaction
159
204
////////////////////////////////////////////////////////////////////////////////
160
205
 
161
206
 
 
207
/**
 
208
 * A scope guard, or sentinel for use with one of the transaction classes.
 
209
 */
162
210
template< class T = basic_transaction >
163
211
class transaction_guard
164
212
        :
176
224
                database &database )
177
225
                :
178
226
                _transaction( database ),
 
227
                _database( database ),
179
228
                _released( false )
180
229
        {
181
230
                _transaction.begin();
211
260
//                                                                implementation
212
261
protected:
213
262
 
214
 
        /* the transaction */
 
263
        /** the transaction */
215
264
        T _transaction;
216
265
 
217
 
        /* have we released the transaction yet? */
 
266
        /** the database */
 
267
        database &_database;
 
268
 
 
269
        /** have we released the transaction yet? */
218
270
        bool _released;
219
271
 
220
272
};