/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/query.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

1
1
/*
2
2
 * query.h
3
3
 *
4
 
 * Copyright (C) 2009 Tim Marston <tim@ed.am>
 
4
 * Copyright (C) 2009 Tim Marston <edam@waxworlds.org>
5
5
 *
6
6
 * This file is part of sqlite3cc (hereafter referred to as "this program").
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.
 
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.
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/>.
27
27
#include <boost/iterator/iterator_facade.hpp>
28
28
#include <sqlite3cc/basic_statement.h>
29
29
#include <sqlite3cc/row.h>
30
 
#include <string>
31
30
 
32
31
 
33
32
namespace sqlite
45
44
        /**
46
45
         * Constructor that provides a connection upon which to act and the SQL
47
46
         * query to execute.
48
 
         *
49
47
         * @param connection a reference to a connection
50
48
         * @param sql an SQL statement in UTF-8
51
49
         */
55
53
 
56
54
        /**
57
55
         * Constructor that provides a connection upon which to act.
58
 
         *
59
56
         * @param connection a reference to a connection
60
57
         */
61
58
        explicit query(
67
64
 
68
65
        /**
69
66
         * Prepare an SQL statement.
70
 
         *
71
67
         * @param sql an SQL statement in UTF-8
72
68
         * @returns an sqlite error code
73
69
         * @see sqlite3_prepare_v2()
76
72
                const std::string &sql );
77
73
 
78
74
        /**
79
 
         * Reset the statement, ready to re-execute it.  This does not clear any of
 
75
         * Reset the statement, ready to re-execute it. This does not clear any of
80
76
         * the values bound to the statement.
81
 
         *
82
77
         * @returns an sqlite error code
83
78
         * @see sqlite3_reset()
84
79
         */
87
82
        /**
88
83
         * Perform a step() and return row object that can be used to retrieve the
89
84
         * results.
90
 
         *
91
85
         * @return a row object
92
86
         */
93
87
        row step();
94
88
 
95
89
        /**
96
 
         * Get the number of columns in the results.
97
 
         *
 
90
         * Get the number of columns in the results
98
91
         * @see sqlite3_column_count()
99
92
         */
100
93
        unsigned int column_count();
101
94
 
102
95
        /**
103
 
         * Get the name of a column in the results.
104
 
         *
 
96
         * Get the name of a column in the results
105
97
         * @param index column index
106
98
         * @see sqlite3_column_name()
107
99
         */
109
101
                unsigned int index );
110
102
 
111
103
        /**
112
 
         * Gets the number of results.  Be aware that this merely step()s over the
113
 
         * results and counts them, which is something you could do yourself.  This
 
104
         * Gets the number of results. Be aware that this merely step()s over the
 
105
         * results and counts them, which is something you could do yourself. This
114
106
         * method is intended to be used for convenience, where you only need know
115
 
         * the number of results and not what they are.  You could also execute some
 
107
         * the number of results and not what they are. You could also execute some
116
108
         * SQL like this: "SELECT COUNT(*) ...", but this only causes SQLite to
117
 
         * internally do the same counting as this method does.  Also note that this
 
109
         * internally do the same counting as this method does. Also note that this
118
110
         * method reset()s the query.
119
 
         *
120
 
         * @returns the number of results
121
111
         */
122
112
        unsigned long long num_results();
123
113
 
124
114
        /**
125
 
         * Query iterator which can be used to obtain rows.
 
115
         * Query iterator which can be used to obtain rows
126
116
         */
127
117
        class iterator
128
118
                :
147
137
        };
148
138
 
149
139
        /**
150
 
         * Get an iterator to the initial row.  Note that creating an iterator
 
140
         * Get an iterator to the initial row. Note that creating an iterator
151
141
         * causes step() to be called, so it should only be called to begin
152
142
         * iterating over the rows and not for comparison.
153
 
         *
154
143
         * @return a query iterator
155
144
         */
156
145
        iterator begin();
157
146
 
158
147
        /**
159
148
         * Get an iterator to after the last row (i.e., an invalid row).
160
 
         *
161
149
         * @return an invalid query iterator
162
150
         */
163
151
        iterator end();