/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: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

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
243
245
 
244
246
        /**
245
247
         * 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
         * ascending order. In addition, the null and set_index() auto-binding
 
249
         * manipulators can be used.
248
250
         * @param value a value to bind
249
251
         */
250
252
        template< class T >
251
253
        basic_statement &operator <<(
252
254
                const T &value )
253
255
        {
254
 
                int error_code = bind( _bind_index, value );
255
 
                if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
 
256
                int code = bind( _bind_index, value );
 
257
                if( code != SQLITE_OK ) throw sqlite_error( _database, code );
256
258
                _bind_index++;
257
259
                return *this;
258
260
        }
271
273
        int finalize();
272
274
 
273
275
        /**
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
276
         * Get the index number of a named parameter
284
277
         * @param parameter name
285
278
         * @return index of named parameter
287
280
        int bind_parameter_index(
288
281
                const std::string &name );
289
282
 
 
283
        /**
 
284
         * Perform a step
 
285
         * @return sqlite error code
 
286
         * @see sqlite3_step()
 
287
         */
 
288
        int step();
 
289
 
290
290
        /** the database upon which to act */
291
291
        database &_database;
292
292
 
293
293
        /** the statement handle */
294
294
        sqlite3_stmt *_handle;
295
295
 
296
 
private:
297
 
 
298
296
        /** index used when auto-binding */
299
297
        unsigned int _bind_index;
300
298
 
301
299
};
302
300
 
303
301
 
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 );
 
302
// template specialisations for basic_statement::operator <<()
 
303
template< >
 
304
basic_statement &basic_statement::operator << < detail::null_t >(
 
305
        const detail::null_t & );
 
306
template< >
 
307
basic_statement &basic_statement::operator << < detail::set_index_t >(
 
308
        const detail::set_index_t &t );
314
309
 
315
310
 
316
311
} // namespace sqlite