/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-04-23 18:41:32 UTC
  • Revision ID: tim@ed.am-20120423184132-uuicu56b79w0xxdp
updated autotools

Show diffs side-by-side

added added

removed removed

1
1
/*
2
2
 * basic_statement.h
3
3
 *
4
 
 * Copyright (C) 2009 Tim Marston <edam@waxworlds.org>
 
4
 * Copyright (C) 2009 Tim Marston <tim@ed.am>
5
5
 *
6
6
 * This file is part of sqlite3cc (hereafter referred to as "this program").
7
 
 * See http://www.waxworlds.org/edam/software/sqlite3cc for more information.
8
 
 *
9
 
 * This program is free software: you can redistribute it and/or modify
10
 
 * it under the terms of the GNU Lesser General Public License as published
11
 
 * by the Free Software Foundation, either version 3 of the License, or
12
 
 * (at your option) any later version.
13
 
 *
14
 
 * This program is distributed in the hope that it will be useful,
15
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 
 * GNU Lesser General Public License for more details.
 
7
 * See http://ed.am/dev/sqlite3cc for more information.
 
8
 *
 
9
 * This program is free software: you can redistribute it and/or modify it under
 
10
 * the terms of the GNU Lesser General Public License as published by the Free
 
11
 * Software Foundation, either version 3 of the License, or (at your option) any
 
12
 * later version.
 
13
 *
 
14
 * This program is distributed in the hope that it will be useful, but WITHOUT
 
15
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
16
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
 
17
 * details.
18
18
 *
19
19
 * You should have received a copy of the GNU Lesser General Public License
20
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
48
48
 
49
49
 
50
50
/**
51
 
 * The statement class represents an SQL statement. It is the base class for
 
51
 * The statement class represents an SQL statement.  It is the base class for
52
52
 * both the command and the query classes, which should be used for those
53
 
 * purposes. The basic_statement class its self has protected instantiation.
 
53
 * purposes.  The basic_statement class its self has protected instantiation.
54
54
 */
55
55
class basic_statement
56
 
        :
57
 
        private boost::noncopyable
58
56
{
59
57
//______________________________________________________________________________
60
58
//                                                                 instantiation
63
61
        /**
64
62
         * Constructor that provides a connection upon which to act and the SQL
65
63
         * statement.
 
64
         *
66
65
         * @param connection a reference to a connection
67
66
         * @param sql an SQL statement in UTF-8
68
67
         */
72
71
 
73
72
        /**
74
73
         * Constructor that provides a connection upon which to act.
 
74
         *
75
75
         * @param connection a reference to a connection
76
76
         */
77
77
        explicit basic_statement(
85
85
 
86
86
        /**
87
87
         * Prepare an SQL statement.
 
88
         *
88
89
         * @param sql an SQL statement in UTF-8
89
90
         * @returns an sqlite error code
90
91
         * @see sqlite3_prepare_v2()
93
94
                const std::string &sql );
94
95
 
95
96
        /**
96
 
         * Reset the statement, ready to re-execute it. This does not clear any of
 
97
         * Reset the statement, ready to re-execute it.  This does not clear any of
97
98
         * the values bound to the statement.
 
99
         *
98
100
         * @returns an sqlite error code
99
101
         * @see sqlite3_reset()
100
102
         */
102
104
 
103
105
        /**
104
106
         * Clears the values bound to a statement to NULL.
 
107
         *
105
108
         * @returns an sqlite error code
106
109
         * @see sqlite3_clear_bindings()
107
110
         */
108
111
        int clear_bindings();
109
112
 
110
113
        /**
111
 
         * Bind a value to the SQL statement via it's index. This template will take
112
 
         * a variety of data types and bind them as text. This is how sqlite
 
114
         * Bind a value to the SQL statement via it's index.  This template will
 
115
         * take a variety of data types and bind them as text.  This is how sqlite
113
116
         * internally stores the data anyway, so always binding as text just means
114
117
         * we do the conversion instead of sqlite and is no less efficient.
 
118
         *
115
119
         * @param index the index of the parameter to bind to
116
120
         * @param value the value to bind
117
121
         * @returns an sqlite error code
129
133
 
130
134
        /**
131
135
         * Bind a string value to the SQL statement via it's index where the value
132
 
         * 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
 
136
         * of that string will not change for the duration of the statement.  This
 
137
         * is more optimal because sqlite will not have to take it's own copy of the
134
138
         * data.
 
139
         *
135
140
         * @param index the index of the parameter to bind to
136
141
         * @param value the invariant string value
137
142
         * @param value_length the length of the string including zero-terminator
145
150
 
146
151
        /**
147
152
         * Bind a string value to the SQL statement via it's index where the value
148
 
         * 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
 
153
         * of that string will not change for the duration of the statement.  This
 
154
         * is more optimal because sqlite will not have to take it's own copy of the
150
155
         * data.
 
156
         *
151
157
         * @param index the index of the parameter to bind to
152
158
         * @param value the invariant string value
153
159
         * @returns an sqlite error code
159
165
 
160
166
        /**
161
167
         * Bind a string value to the SQL statement via it's index where the value
162
 
         * 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
 
168
         * of that string will not change for the duration of the statement.  This
 
169
         * is more optimal because sqlite will not have to take it's own copy of the
164
170
         * data.
 
171
         *
165
172
         * @param index the index of the parameter to bind to
166
173
         * @param value the invariant string value
167
174
         * @returns an sqlite error code
173
180
 
174
181
        /**
175
182
         * Bind a NULL value to the SQL statement via it's index.
 
183
         *
176
184
         * @param index the index of the parameter to bind to
177
185
         * @returns an sqlite error code
178
186
         * @see sqlite3_bind_null()
181
189
                unsigned int index );
182
190
 
183
191
        /**
184
 
         * Bind a value to the SQL statement via a named parameter. This template
185
 
         * will take a variety of data types and bind them as text. This is how
 
192
         * Bind a value to the SQL statement via a named parameter.  This template
 
193
         * will take a variety of data types and bind them as text.  This is how
186
194
         * sqlite internally stores the data anyway, so always binding as text just
187
195
         * means we do the conversion instead of sqlite and is no less efficient.
 
196
         *
188
197
         * @param name the named parameter to bind to
189
198
         * @param value the value to bind
190
199
         * @returns an sqlite error code
200
209
 
201
210
        /**
202
211
         * Bind a string value to the SQL statement via a named parameter where the
203
 
         * string value will not change for the duration of the statement. This
 
212
         * string value will not change for the duration of the statement.  This
204
213
         * prevents sqlite from taking its own copy of the string.
 
214
         *
205
215
         * @param name the named parameter to bind to
206
216
         * @param value the invariant string value
207
217
         * @param value_length the length of the string including zero-terminator
215
225
 
216
226
        /**
217
227
         * Bind a string value to the SQL statement via a named parameter where the
218
 
         * string value will not change for the duration of the statement. This
 
228
         * string value will not change for the duration of the statement.  This
219
229
         * prevents a copy of the string being taken.
 
230
         *
220
231
         * @param name the named parameter to bind to
221
232
         * @param value the invariant string value
222
233
         * @returns an sqlite error code
228
239
 
229
240
        /**
230
241
         * Bind a string value to the SQL statement via a named parameter where the
231
 
         * string value will not change for the duration of the statement. This
 
242
         * string value will not change for the duration of the statement.  This
232
243
         * prevents a copy of the string being taken.
 
244
         *
233
245
         * @param name the named parameter to bind to
234
246
         * @param value the invariant string value
235
247
         * @returns an sqlite error code
241
253
 
242
254
        /**
243
255
         * Bind a NULL value to the SQL statement via a named parameter.
 
256
         *
244
257
         * @param name the named parameter to bind to
245
258
         * @returns an sqlite error code
246
259
         * @see sqlite3_bind_null()
250
263
 
251
264
        /**
252
265
         * Stream operator is used to bind values to parameters automatically, in
253
 
         * ascending order. In addition, the null and set_index() auto-binding
 
266
         * ascending order.  In addition, the null and set_index() auto-binding
254
267
         * manipulators can be used.
 
268
         *
255
269
         * @param value a value to bind
256
270
         */
257
271
        template< class T >
272
286
 
273
287
        /**
274
288
         * Finalise an SQL statement.
 
289
         *
275
290
         * @returns an sqlite error code
276
291
         * @see sqlite3_finalize()
277
292
         */
278
293
        int finalize();
279
294
 
280
295
        /**
281
 
         * Get the index number of a named parameter
 
296
         * Get the index number of a named parameter.
 
297
         *
282
298
         * @param parameter name
283
299
         * @return index of named parameter
284
300
         */
286
302
                const std::string &name );
287
303
 
288
304
        /**
289
 
         * Perform a step
 
305
         * Perform a step.
 
306
         *
290
307
         * @return sqlite error code
291
308
         * @see sqlite3_step()
292
309
         */