/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:39:13 UTC
  • Revision ID: edam@waxworlds.org-20100729063913-wvcvkogsa2alwkhr
- moved basic_statement::operator <<() back to basic_statement and just create another specialisation in command so that it can use sqlite::exec

Show diffs side-by-side

added added

removed removed

32
32
{
33
33
 
34
34
 
35
 
class connection;
36
 
 
37
 
 
38
 
namespace detail
 
35
class database;
 
36
 
 
37
 
 
38
/**
 
39
 * A basic (default, deferred) transaction.
 
40
 */
 
41
class basic_transaction
 
42
        :
 
43
        private boost::noncopyable
39
44
{
40
 
 
41
 
        /**
42
 
         * A basic (default, deferred) transaction.
43
 
         */
44
 
        class basic_transaction
45
 
                :
46
 
                private boost::noncopyable
47
 
        {
48
 
        //__________________________________________________________________________
49
 
        //                                                             instantiation
50
 
        public:
51
 
 
52
 
                /**
53
 
                 * Constructor that provides a connection upon which to act
54
 
                 * @param connection a connection
55
 
                 */
56
 
                explicit basic_transaction(
57
 
                        connection &connection );
58
 
 
59
 
        //__________________________________________________________________________
60
 
        //                                                          public interface
61
 
        public:
62
 
 
63
 
                /**
64
 
                 * Begin the transaction
65
 
                 */
66
 
                virtual void begin();
67
 
 
68
 
                /**
69
 
                 * Commit the transaction
70
 
                 */
71
 
                virtual void commit();
72
 
 
73
 
                /**
74
 
                 * Rollback the transaction
75
 
                 */
76
 
                virtual void rollback();
77
 
 
78
 
        //__________________________________________________________________________
79
 
        //                                                            implementation
80
 
        protected:
81
 
 
82
 
                /** reset any in-progress statements */
83
 
                void reset_active_queries();
84
 
 
85
 
                /** the connection on which to act */
86
 
                connection &_connection;
87
 
 
88
 
        };
89
 
 
90
 
} // namespace detail
91
 
 
92
 
 
93
 
////////////////////////////////////////////////////////////////////////////////
94
 
 
95
 
 
96
 
/**
97
 
 * A deferred transaction (the default)
98
 
 */
99
 
typedef detail::basic_transaction deferred_tranaction;
100
 
 
101
 
 
102
 
////////////////////////////////////////////////////////////////////////////////
103
 
 
104
 
 
105
 
/**
106
 
 * An immediate transaction
 
45
//______________________________________________________________________________
 
46
//                                                                 instantiation
 
47
public:
 
48
 
 
49
        /**
 
50
         * Constructor that provides a database upon which to act
 
51
         * @param database a database
 
52
         */
 
53
        explicit basic_transaction(
 
54
                database &database );
 
55
 
 
56
//______________________________________________________________________________
 
57
//                                                              public interface
 
58
public:
 
59
 
 
60
        /**
 
61
         * Begin the transaction
 
62
         */
 
63
        virtual void begin();
 
64
 
 
65
        /**
 
66
         * Commit the transaction
 
67
         */
 
68
        virtual void commit();
 
69
 
 
70
        /**
 
71
         * Rollback the transaction
 
72
         */
 
73
        virtual void rollback();
 
74
 
 
75
//______________________________________________________________________________
 
76
//                                                                implementation
 
77
protected:
 
78
 
 
79
        /** close any in-progress statements */
 
80
        void invalidate_queries();
 
81
 
 
82
        /** the database on which to act */
 
83
        database &_database;
 
84
 
 
85
};
 
86
 
 
87
 
 
88
////////////////////////////////////////////////////////////////////////////////
 
89
 
 
90
 
 
91
/**
 
92
 * An exclusive transaction
107
93
 */
108
94
class immediate_transaction
109
95
        :
110
 
        public detail::basic_transaction
 
96
        public basic_transaction
111
97
{
112
98
//______________________________________________________________________________
113
99
//                                                                 instantiation
114
100
public:
115
101
 
116
102
        /**
117
 
         * Constructor that provides a connection upon which to act
118
 
         * @param connection a connection
 
103
         * Constructor that provides a database upon which to act
 
104
         * @param database a database
119
105
         */
120
106
        explicit immediate_transaction(
121
 
                connection &connection );
 
107
                database &database );
122
108
 
123
109
//______________________________________________________________________________
124
110
//                                                              public interface
140
126
 */
141
127
class exclusive_transaction
142
128
        :
143
 
        public detail::basic_transaction
 
129
        public basic_transaction
144
130
{
145
131
//______________________________________________________________________________
146
132
//                                                                 instantiation
147
133
public:
148
134
 
149
135
        /**
150
 
         * Constructor that provides a connection upon which to act
151
 
         * @param connection a connection
 
136
         * Constructor that provides a database upon which to act
 
137
         * @param database a database
152
138
         */
153
139
        explicit exclusive_transaction(
154
 
                connection &connection );
 
140
                database &database );
155
141
 
156
142
//______________________________________________________________________________
157
143
//                                                              public interface
173
159
 */
174
160
class recursive_transaction
175
161
        :
176
 
        public detail::basic_transaction
 
162
        public basic_transaction
177
163
{
178
164
//______________________________________________________________________________
179
165
//                                                                 instantiation
180
166
public:
181
167
 
182
168
        /**
183
 
         * Constructor that provides a connection upon which to act
184
 
         * @param connection a connection
 
169
         * Constructor that provides a database upon which to act
 
170
         * @param database a database
185
171
         */
186
172
        explicit recursive_transaction(
187
 
                connection &connection );
 
173
                database &database );
188
174
 
189
175
//______________________________________________________________________________
190
176
//                                                              public interface
219
205
 
220
206
 
221
207
/**
222
 
 * A scope guard (sentinel) for use with one of the transaction classes to
223
 
 * provide RIAA-style transactions.
 
208
 * A scope guard, or sentinel for use with one of the transaction classes.
224
209
 */
225
 
template< class T = deferred_tranaction >
 
210
template< class T = basic_transaction >
226
211
class transaction_guard
227
212
        :
228
213
        private boost::noncopyable
232
217
public:
233
218
 
234
219
        /**
235
 
         * Constructor that provides a connection upon which to act
236
 
         * @param connection a connection
 
220
         * Constructor that provides a database upon which to act
 
221
         * @param database a database
237
222
         */
238
223
        explicit transaction_guard(
239
 
                connection &connection )
 
224
                database &database )
240
225
                :
241
 
                _transaction( connection ),
 
226
                _transaction( database ),
242
227
                _released( false )
243
228
        {
244
229
                _transaction.begin();
246
231
 
247
232
        ~transaction_guard()
248
233
        {
249
 
                if( !_released )
250
 
                        _transaction.rollback();
 
234
                if( !_released ) {
 
235
                        try {
 
236
                                _transaction.rollback();
 
237
                        }
 
238
                        catch( ... ) {
 
239
                        }
 
240
                }
251
241
        }
252
242
 
253
243
//______________________________________________________________________________
265
255
                }
266
256
        }
267
257
 
268
 
        /**
269
 
         * Rollback the transaction early
270
 
         */
271
 
        void rollback()
272
 
        {
273
 
                if( !_released ) {
274
 
                        _transaction.rollback();
275
 
                        _released = true;
276
 
                }
277
 
        }
278
 
 
279
258
//______________________________________________________________________________
280
259
//                                                                implementation
281
260
protected: