/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: 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

24
24
#define SQLITE3CC_QUERY_H_
25
25
 
26
26
 
27
 
#include <boost/iterator/iterator_facade.hpp>
28
27
#include <sqlite3cc/basic_statement.h>
29
 
#include <sqlite3cc/row.h>
30
28
 
31
29
 
32
30
namespace sqlite
33
31
{
34
32
 
35
33
 
 
34
class row;
 
35
 
 
36
 
36
37
class query
37
38
        :
38
 
        public detail::basic_statement
 
39
        public basic_statement
39
40
{
40
41
//______________________________________________________________________________
41
42
//                                                                 instantiation
42
43
public:
43
44
 
44
45
        /**
45
 
         * 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
46
47
         * query to execute.
47
 
         * @param connection a reference to a connection
 
48
         * @param database a reference to a database
48
49
         * @param sql an SQL statement in UTF-8
49
50
         */
50
51
        explicit query(
51
 
                connection &connection,
 
52
                database &database,
52
53
                const std::string &sql );
53
54
 
54
55
        /**
55
 
         * Constructor that provides a connection upon which to act.
56
 
         * @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
57
59
         */
58
60
        explicit query(
59
 
                connection &connection );
 
61
                database &database );
60
62
 
61
63
//______________________________________________________________________________
62
64
//                                                              public interface
72
74
                const std::string &sql );
73
75
 
74
76
        /**
75
 
         * Reset the statement, ready to re-execute it. This does not clear any of
76
 
         * the values bound to the statement.
77
 
         * @returns an sqlite error code
78
 
         * @see sqlite3_reset()
79
 
         */
80
 
        virtual int reset();
81
 
 
82
 
        /**
83
 
         * 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
84
78
         * results.
85
79
         * @return a row object
86
80
         */
87
81
        row step();
88
82
 
89
83
        /**
90
 
         * Get the number of columns in the results
91
 
         * @see sqlite3_column_count()
 
84
         * Get the number of columns in the result of
92
85
         */
93
86
        unsigned int column_count();
94
87
 
95
 
        /**
96
 
         * Get the name of a column in the results
97
 
         * @param index column index
98
 
         * @see sqlite3_column_name()
99
 
         */
100
 
        const std::string column_name(
101
 
                unsigned int index );
102
 
 
103
 
        /**
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
106
 
         * method is intended to be used for convenience, where you only need know
107
 
         * the number of results and not what they are. You could also execute some
108
 
         * SQL like this: "SELECT COUNT(*) ...", but this only causes SQLite to
109
 
         * internally do the same counting as this method does. Also note that this
110
 
         * method reset()s the query.
111
 
         */
112
 
        unsigned long long num_results();
113
 
 
114
 
        /**
115
 
         * Query iterator which can be used to obtain rows
116
 
         */
117
 
        class iterator
118
 
                :
119
 
                public boost::iterator_facade< iterator, row,
120
 
                        boost::single_pass_traversal_tag, row >
121
 
        {
122
 
        public:
123
 
                explicit iterator( query &query, bool step );
124
 
 
125
 
        private:
126
 
                friend class boost::iterator_core_access;
127
 
 
128
 
                row dereference() const;
129
 
                void increment();
130
 
                bool equal( iterator const &other ) const;
131
 
 
132
 
                /** the current row */
133
 
                row _row;
134
 
 
135
 
                /** the query */
136
 
                query &_query;
137
 
        };
138
 
 
139
 
        /**
140
 
         * Get an iterator to the initial row. Note that creating an iterator
141
 
         * causes step() to be called, so it should only be called to begin
142
 
         * iterating over the rows and not for comparison.
143
 
         * @return a query iterator
144
 
         */
145
 
        iterator begin();
146
 
 
147
 
        /**
148
 
         * Get an iterator to after the last row (i.e., an invalid row).
149
 
         * @return an invalid query iterator
150
 
         */
151
 
        iterator end();
152
 
 
153
 
//______________________________________________________________________________
154
 
//                                                                implementation
155
 
private:
156
 
 
157
 
        /** next row number */
158
 
        unsigned long long _next_row_number;
159
 
 
160
88
};
161
89
 
162
90