/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: 2012-01-23 13:46:27 UTC
  • Revision ID: edam@waxworlds.org-20120123134627-i6hi9aftfvwgp8vw
updated autotols stuff

Show diffs side-by-side

added added

removed removed

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