/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

34
34
{
35
35
 
36
36
 
37
 
class connection;
 
37
class database;
38
38
class row;
39
39
namespace detail {
40
40
        struct null_t;
43
43
}
44
44
 
45
45
 
46
 
namespace detail
47
 
{
48
 
 
49
 
 
50
46
/**
51
47
 * The statement class represents an SQL statement. It is the base class for
52
48
 * both the command and the query classes, which should be used for those
61
57
protected:
62
58
 
63
59
        /**
64
 
         * Constructor that provides a connection upon which to act and the SQL
 
60
         * Constructor that provides a database upon which to act and the SQL
65
61
         * statement.
66
 
         * @param connection a reference to a connection
 
62
         * @param database a reference to a database
67
63
         * @param sql an SQL statement in UTF-8
68
64
         */
69
65
        explicit basic_statement(
70
 
                connection &connection,
 
66
                database &database,
71
67
                const std::string &sql );
72
68
 
73
69
        /**
74
 
         * Constructor that provides a connection upon which to act.
75
 
         * @param connection a reference to a connection
 
70
         * Constructor that provides a database upon which to act.
 
71
         * @param database a reference to a database
 
72
         * @param sql an SQL statement in UTF-8
76
73
         */
77
74
        explicit basic_statement(
78
 
                connection &connection );
 
75
                database &database );
79
76
 
80
77
        virtual ~basic_statement();
81
78
 
98
95
         * @returns an sqlite error code
99
96
         * @see sqlite3_reset()
100
97
         */
101
 
        virtual int reset();
 
98
        int reset();
102
99
 
103
100
        /**
104
101
         * Clears the values bound to a statement to NULL.
130
127
        /**
131
128
         * Bind a string value to the SQL statement via it's index where the value
132
129
         * of that string will not change for the duration of the statement. This is
133
 
         * more optimal because sqlite will not have to take it's own copy of the
 
130
         * more optimal because sqlite will not have to make it's own copy of the
134
131
         * data.
135
132
         * @param index the index of the parameter to bind to
136
133
         * @param value the invariant string value
137
 
         * @param value_length the length of the string including zero-terminator
138
134
         * @returns an sqlite error code
139
135
         * @see sqlite3_bind_text()
140
136
         */
146
142
        /**
147
143
         * Bind a string value to the SQL statement via it's index where the value
148
144
         * of that string will not change for the duration of the statement. This is
149
 
         * more optimal  because sqlite will not have to take it's own copy of the
 
145
         * more optimal  because sqlite will not have to make it's own copy of the
150
146
         * data.
151
147
         * @param index the index of the parameter to bind to
152
148
         * @param value the invariant string value
160
156
        /**
161
157
         * Bind a string value to the SQL statement via it's index where the value
162
158
         * of that string will not change for the duration of the statement. This is
163
 
         * more optimal because sqlite will not have to take it's own copy of the
 
159
         * more optimal because sqlite will not have to make it's own copy of the
164
160
         * data.
165
161
         * @param index the index of the parameter to bind to
166
162
         * @param value the invariant string value
201
197
        /**
202
198
         * Bind a string value to the SQL statement via a named parameter where the
203
199
         * string value will not change for the duration of the statement. This
204
 
         * prevents sqlite from taking its own copy of the string.
 
200
         * prevents a copy of the string being taken.
205
201
         * @param name the named parameter to bind to
206
202
         * @param value the invariant string value
207
 
         * @param value_length the length of the string including zero-terminator
208
203
         * @returns an sqlite error code
209
204
         * @see sqlite3_bind_text()
210
205
         */
248
243
        int bind_null(
249
244
                const std::string &name );
250
245
 
251
 
        /**
252
 
         * Stream operator is used to bind values to parameters automatically, in
253
 
         * ascending order. In addition, the null and set_index() auto-binding
254
 
         * manipulators can be used.
255
 
         * @param value a value to bind
256
 
         */
257
 
        template< class T >
258
 
        basic_statement &operator <<(
259
 
                const T &value )
260
 
        {
261
 
                int code = bind( _bind_index, value );
262
 
                if( code != SQLITE_OK ) throw sqlite_error( _connection, code );
263
 
                _bind_index++;
264
 
                return *this;
265
 
        }
266
 
 
267
246
//______________________________________________________________________________
268
247
//                                                                implementation
269
248
protected:
292
271
         */
293
272
        int step();
294
273
 
295
 
        /** the connection upon which to act */
296
 
        connection &_connection;
 
274
        /** the database upon which to act */
 
275
        database &_database;
297
276
 
298
277
        /** the statement handle */
299
278
        sqlite3_stmt *_handle;
304
283
};
305
284
 
306
285
 
307
 
// template specialisations for basic_statement::operator <<()
308
 
template< >
309
 
basic_statement &basic_statement::operator << < detail::null_t >(
310
 
        const detail::null_t & );
311
 
template< >
312
 
basic_statement &basic_statement::operator << < detail::set_index_t >(
313
 
        const detail::set_index_t &t );
314
 
 
315
 
 
316
 
} // namespace detail
317
 
 
318
 
 
319
286
} // namespace sqlite
320
287
 
321
288