/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 14:27:08 UTC
  • Revision ID: edam@waxworlds.org-20120123142708-w12277ptwtlspa6f
updated email and web addresses

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
56
        :
63
63
        /**
64
64
         * Constructor that provides a connection upon which to act and the SQL
65
65
         * statement.
 
66
         *
66
67
         * @param connection a reference to a connection
67
68
         * @param sql an SQL statement in UTF-8
68
69
         */
72
73
 
73
74
        /**
74
75
         * Constructor that provides a connection upon which to act.
 
76
         *
75
77
         * @param connection a reference to a connection
76
78
         */
77
79
        explicit basic_statement(
85
87
 
86
88
        /**
87
89
         * Prepare an SQL statement.
 
90
         *
88
91
         * @param sql an SQL statement in UTF-8
89
92
         * @returns an sqlite error code
90
93
         * @see sqlite3_prepare_v2()
93
96
                const std::string &sql );
94
97
 
95
98
        /**
96
 
         * Reset the statement, ready to re-execute it. This does not clear any of
 
99
         * Reset the statement, ready to re-execute it.  This does not clear any of
97
100
         * the values bound to the statement.
 
101
         *
98
102
         * @returns an sqlite error code
99
103
         * @see sqlite3_reset()
100
104
         */
102
106
 
103
107
        /**
104
108
         * Clears the values bound to a statement to NULL.
 
109
         *
105
110
         * @returns an sqlite error code
106
111
         * @see sqlite3_clear_bindings()
107
112
         */
108
113
        int clear_bindings();
109
114
 
110
115
        /**
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
 
116
         * Bind a value to the SQL statement via it's index.  This template will
 
117
         * take a variety of data types and bind them as text.  This is how sqlite
113
118
         * internally stores the data anyway, so always binding as text just means
114
119
         * we do the conversion instead of sqlite and is no less efficient.
 
120
         *
115
121
         * @param index the index of the parameter to bind to
116
122
         * @param value the value to bind
117
123
         * @returns an sqlite error code
129
135
 
130
136
        /**
131
137
         * 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
 
138
         * of that string will not change for the duration of the statement.  This
 
139
         * is more optimal because sqlite will not have to take it's own copy of the
134
140
         * data.
 
141
         *
135
142
         * @param index the index of the parameter to bind to
136
143
         * @param value the invariant string value
137
144
         * @param value_length the length of the string including zero-terminator
145
152
 
146
153
        /**
147
154
         * 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
 
155
         * of that string will not change for the duration of the statement.  This
 
156
         * is more optimal because sqlite will not have to take it's own copy of the
150
157
         * data.
 
158
         *
151
159
         * @param index the index of the parameter to bind to
152
160
         * @param value the invariant string value
153
161
         * @returns an sqlite error code
159
167
 
160
168
        /**
161
169
         * 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
 
170
         * of that string will not change for the duration of the statement.  This
 
171
         * is more optimal because sqlite will not have to take it's own copy of the
164
172
         * data.
 
173
         *
165
174
         * @param index the index of the parameter to bind to
166
175
         * @param value the invariant string value
167
176
         * @returns an sqlite error code
173
182
 
174
183
        /**
175
184
         * Bind a NULL value to the SQL statement via it's index.
 
185
         *
176
186
         * @param index the index of the parameter to bind to
177
187
         * @returns an sqlite error code
178
188
         * @see sqlite3_bind_null()
181
191
                unsigned int index );
182
192
 
183
193
        /**
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
 
194
         * Bind a value to the SQL statement via a named parameter.  This template
 
195
         * will take a variety of data types and bind them as text.  This is how
186
196
         * sqlite internally stores the data anyway, so always binding as text just
187
197
         * means we do the conversion instead of sqlite and is no less efficient.
 
198
         *
188
199
         * @param name the named parameter to bind to
189
200
         * @param value the value to bind
190
201
         * @returns an sqlite error code
200
211
 
201
212
        /**
202
213
         * 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
 
214
         * string value will not change for the duration of the statement.  This
204
215
         * prevents sqlite from taking its own copy of the string.
 
216
         *
205
217
         * @param name the named parameter to bind to
206
218
         * @param value the invariant string value
207
219
         * @param value_length the length of the string including zero-terminator
215
227
 
216
228
        /**
217
229
         * 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
 
230
         * string value will not change for the duration of the statement.  This
219
231
         * prevents a copy of the string being taken.
 
232
         *
220
233
         * @param name the named parameter to bind to
221
234
         * @param value the invariant string value
222
235
         * @returns an sqlite error code
228
241
 
229
242
        /**
230
243
         * 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
 
244
         * string value will not change for the duration of the statement.  This
232
245
         * prevents a copy of the string being taken.
 
246
         *
233
247
         * @param name the named parameter to bind to
234
248
         * @param value the invariant string value
235
249
         * @returns an sqlite error code
241
255
 
242
256
        /**
243
257
         * Bind a NULL value to the SQL statement via a named parameter.
 
258
         *
244
259
         * @param name the named parameter to bind to
245
260
         * @returns an sqlite error code
246
261
         * @see sqlite3_bind_null()
250
265
 
251
266
        /**
252
267
         * Stream operator is used to bind values to parameters automatically, in
253
 
         * ascending order. In addition, the null and set_index() auto-binding
 
268
         * ascending order.  In addition, the null and set_index() auto-binding
254
269
         * manipulators can be used.
 
270
         *
255
271
         * @param value a value to bind
256
272
         */
257
273
        template< class T >
272
288
 
273
289
        /**
274
290
         * Finalise an SQL statement.
 
291
         *
275
292
         * @returns an sqlite error code
276
293
         * @see sqlite3_finalize()
277
294
         */
278
295
        int finalize();
279
296
 
280
297
        /**
281
 
         * Get the index number of a named parameter
 
298
         * Get the index number of a named parameter.
 
299
         *
282
300
         * @param parameter name
283
301
         * @return index of named parameter
284
302
         */
286
304
                const std::string &name );
287
305
 
288
306
        /**
289
 
         * Perform a step
 
307
         * Perform a step.
 
308
         *
290
309
         * @return sqlite error code
291
310
         * @see sqlite3_step()
292
311
         */