/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-02-07 15:28:23 UTC
  • Revision ID: edam@waxworlds.org-20100207152823-42k206h6gwy7vla4
- fixed .am files so the library gets built!

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
 
namespace detail {
40
 
        struct null_t;
41
 
        struct exec_t;
42
 
        struct set_index_t;
43
 
}
44
 
 
45
 
 
46
 
namespace detail
47
 
{
 
39
struct _null_t;
 
40
struct _exec_t;
 
41
struct _set_index_t;
48
42
 
49
43
 
50
44
/**
61
55
protected:
62
56
 
63
57
        /**
64
 
         * Constructor that provides a connection upon which to act and the SQL
 
58
         * Constructor that provides a database upon which to act and the SQL
65
59
         * statement.
66
 
         * @param connection a reference to a connection
 
60
         * @param database a reference to a database
67
61
         * @param sql an SQL statement in UTF-8
68
62
         */
69
63
        explicit basic_statement(
70
 
                connection &connection,
 
64
                database &database,
71
65
                const std::string &sql );
72
66
 
73
67
        /**
74
 
         * Constructor that provides a connection upon which to act.
75
 
         * @param connection a reference to a connection
 
68
         * Constructor that provides a database upon which to act.
 
69
         * @param database a reference to a database
 
70
         * @param sql an SQL statement in UTF-8
76
71
         */
77
72
        explicit basic_statement(
78
 
                connection &connection );
 
73
                database &database );
79
74
 
80
 
        virtual ~basic_statement();
 
75
        virtual ~basic_statement() throw( );
81
76
 
82
77
//______________________________________________________________________________
83
78
//                                                              public interface
98
93
         * @returns an sqlite error code
99
94
         * @see sqlite3_reset()
100
95
         */
101
 
        virtual int reset();
 
96
        int reset();
102
97
 
103
98
        /**
104
99
         * Clears the values bound to a statement to NULL.
130
125
        /**
131
126
         * Bind a string value to the SQL statement via it's index where the value
132
127
         * 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
 
128
         * more optimal because sqlite will not have to make it's own copy of the
134
129
         * data.
135
130
         * @param index the index of the parameter to bind to
136
131
         * @param value the invariant string value
137
 
         * @param value_length the length of the string including zero-terminator
138
132
         * @returns an sqlite error code
139
133
         * @see sqlite3_bind_text()
140
134
         */
146
140
        /**
147
141
         * Bind a string value to the SQL statement via it's index where the value
148
142
         * 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
 
143
         * more optimal  because sqlite will not have to make it's own copy of the
150
144
         * data.
151
145
         * @param index the index of the parameter to bind to
152
146
         * @param value the invariant string value
160
154
        /**
161
155
         * Bind a string value to the SQL statement via it's index where the value
162
156
         * 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
 
157
         * more optimal because sqlite will not have to make it's own copy of the
164
158
         * data.
165
159
         * @param index the index of the parameter to bind to
166
160
         * @param value the invariant string value
201
195
        /**
202
196
         * Bind a string value to the SQL statement via a named parameter where the
203
197
         * string value will not change for the duration of the statement. This
204
 
         * prevents sqlite from taking its own copy of the string.
 
198
         * prevents a copy of the string being taken.
205
199
         * @param name the named parameter to bind to
206
200
         * @param value the invariant string value
207
 
         * @param value_length the length of the string including zero-terminator
208
201
         * @returns an sqlite error code
209
202
         * @see sqlite3_bind_text()
210
203
         */
250
243
 
251
244
        /**
252
245
         * 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.
 
246
         * ascending order. In addition, the null, set_index() and execute auto-
 
247
         * binding manipulators can be used.
255
248
         * @param value a value to bind
256
249
         */
257
250
        template< class T >
258
251
        basic_statement &operator <<(
259
252
                const T &value )
260
253
        {
261
 
                int code = bind( _bind_index, value );
262
 
                if( code != SQLITE_OK ) throw sqlite_error( _connection, code );
 
254
                int error_code = bind( _bind_index, value );
 
255
                if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
263
256
                _bind_index++;
264
257
                return *this;
265
258
        }
278
271
        int finalize();
279
272
 
280
273
        /**
 
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
        /**
281
283
         * Get the index number of a named parameter
282
284
         * @param parameter name
283
285
         * @return index of named parameter
285
287
        int bind_parameter_index(
286
288
                const std::string &name );
287
289
 
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;
 
290
        /** the database upon which to act */
 
291
        database &_database;
297
292
 
298
293
        /** the statement handle */
299
294
        sqlite3_stmt *_handle;
300
295
 
 
296
private:
 
297
 
301
298
        /** index used when auto-binding */
302
299
        unsigned int _bind_index;
303
300
 
304
301
};
305
302
 
306
303
 
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
 
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 );
317
314
 
318
315
 
319
316
} // namespace sqlite