/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

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