4
* Copyright (C) 2009 Tim Marston <tim@ed.am>
4
* Copyright (C) 2009 Tim Marston <edam@waxworlds.org>
6
6
* This file is part of sqlite3cc (hereafter referred to as "this program").
7
* See http://ed.am/dev/sqlite3cc for more information.
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
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
7
* See http://www.waxworlds.org/edam/software/sqlite3cc for more information.
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.
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.
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/>.
24
24
#define SQLITE3CC_QUERY_H_
27
#include <boost/iterator/iterator_facade.hpp>
28
27
#include <sqlite3cc/basic_statement.h>
29
#include <sqlite3cc/row.h>
39
public detail::basic_statement
39
public basic_statement
41
41
//______________________________________________________________________________
46
* Constructor that provides a connection upon which to act and the SQL
46
* Constructor that provides a database upon which to act and the SQL
47
47
* query to execute.
49
* @param connection a reference to a connection
48
* @param database a reference to a database
50
49
* @param sql an SQL statement in UTF-8
53
connection &connection,
54
53
const std::string &sql );
57
* Constructor that provides a connection upon which to act.
59
* @param connection a reference to a connection
56
* Constructor that provides a database upon which to act.
57
* @param database a reference to a database
58
* @param sql an SQL statement in UTF-8
62
connection &connection );
64
63
//______________________________________________________________________________
65
64
// public interface
76
74
const std::string &sql );
79
* Reset the statement, ready to re-execute it. This does not clear any of
80
* the values bound to the statement.
82
* @returns an sqlite error code
83
* @see sqlite3_reset()
88
* Perform a step() and return row object that can be used to retrieve the
77
* Peform a step() and return row object that can be used to retrieve the
91
79
* @return a row object
96
* Get the number of columns in the results.
98
* @see sqlite3_column_count()
84
* Get the number of columns in the result of
100
86
unsigned int column_count();
103
* Get the name of a column in the results.
105
* @param index column index
106
* @see sqlite3_column_name()
108
const std::string column_name(
109
unsigned int index );
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
114
* 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
116
* 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
118
* method reset()s the query.
120
* @returns the number of results
122
unsigned long long num_results();
125
* Query iterator which can be used to obtain rows.
129
public boost::iterator_facade< iterator, row,
130
boost::single_pass_traversal_tag, row >
133
explicit iterator( query &query, bool step );
136
friend class boost::iterator_core_access;
138
row dereference() const;
140
bool equal( iterator const &other ) const;
142
/** the current row */
150
* Get an iterator to the initial row. Note that creating an iterator
151
* causes step() to be called, so it should only be called to begin
152
* iterating over the rows and not for comparison.
154
* @return a query iterator
159
* Get an iterator to after the last row (i.e., an invalid row).
161
* @return an invalid query iterator
165
//______________________________________________________________________________
169
/** next row number */
170
unsigned long long _next_row_number;