/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/basic_statement.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

36
36
 
37
37
class database;
38
38
class row;
39
 
struct _null_t;
40
 
struct _exec_t;
41
 
struct _set_index_t;
 
39
namespace detail {
 
40
        struct null_t;
 
41
        struct exec_t;
 
42
        struct set_index_t;
 
43
}
42
44
 
43
45
 
44
46
/**
72
74
        explicit basic_statement(
73
75
                database &database );
74
76
 
75
 
        virtual ~basic_statement() throw( );
 
77
        virtual ~basic_statement();
76
78
 
77
79
//______________________________________________________________________________
78
80
//                                                              public interface
241
243
        int bind_null(
242
244
                const std::string &name );
243
245
 
244
 
        /**
245
 
         * Stream operator is used to bind values to parameters automatically, in
246
 
         * ascending order. In addition, the null, set_index() and execute auto-
247
 
         * binding manipulators can be used.
248
 
         * @param value a value to bind
249
 
         */
250
 
        template< class T >
251
 
        basic_statement &operator <<(
252
 
                const T &value )
253
 
        {
254
 
                int error_code = bind( _bind_index, value );
255
 
                if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
256
 
                _bind_index++;
257
 
                return *this;
258
 
        }
259
 
 
260
246
//______________________________________________________________________________
261
247
//                                                                implementation
262
248
protected:
271
257
        int finalize();
272
258
 
273
259
        /**
274
 
         * Step through one execution cycle of the SQL statement. If this is an SQL
275
 
         * statement that doesn't return any rows, only one cycle is required,
276
 
         * otherwise, each cycle will return another row
277
 
         * @return an sqlite error code
278
 
         * @see sqlite3_step()
279
 
         */
280
 
        int step();
281
 
 
282
 
        /**
283
260
         * Get the index number of a named parameter
284
261
         * @param parameter name
285
262
         * @return index of named parameter
287
264
        int bind_parameter_index(
288
265
                const std::string &name );
289
266
 
 
267
        /**
 
268
         * Perform a step
 
269
         * @return sqlite error code
 
270
         * @see sqlite3_step()
 
271
         */
 
272
        int step();
 
273
 
290
274
        /** the database upon which to act */
291
275
        database &_database;
292
276
 
293
277
        /** the statement handle */
294
278
        sqlite3_stmt *_handle;
295
279
 
296
 
private:
297
 
 
298
280
        /** index used when auto-binding */
299
281
        unsigned int _bind_index;
300
282
 
301
283
};
302
284
 
303
285
 
304
 
// template specialisations for statement::operator <<()
305
 
template< >
306
 
basic_statement &basic_statement::operator << < _null_t >(
307
 
        const _null_t & );
308
 
template< >
309
 
basic_statement &basic_statement::operator << < _exec_t >(
310
 
        const _exec_t & );
311
 
template< >
312
 
basic_statement &basic_statement::operator << < _set_index_t >(
313
 
        const _set_index_t &t );
314
 
 
315
 
 
316
286
} // namespace sqlite
317
287
 
318
288