/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-07-29 09:16:26 UTC
  • Revision ID: edam@waxworlds.org-20100729091626-h8fmg0r74eyfo5ae
- fixed error caused by finialising in-progress queries during rollback that were later finaliased by RAII.

Show diffs side-by-side

added added

removed removed

35
35
 
36
36
class query
37
37
        :
38
 
        public detail::basic_statement
 
38
        public basic_statement
39
39
{
40
40
//______________________________________________________________________________
41
41
//                                                                 instantiation
42
42
public:
43
43
 
44
44
        /**
45
 
         * Constructor that provides a connection upon which to act and the SQL
 
45
         * Constructor that provides a database upon which to act and the SQL
46
46
         * query to execute.
47
 
         * @param connection a reference to a connection
 
47
         * @param database a reference to a database
48
48
         * @param sql an SQL statement in UTF-8
49
49
         */
50
50
        explicit query(
51
 
                connection &connection,
 
51
                database &database,
52
52
                const std::string &sql );
53
53
 
54
54
        /**
55
 
         * Constructor that provides a connection upon which to act.
56
 
         * @param connection a reference to a connection
 
55
         * Constructor that provides a database upon which to act.
 
56
         * @param database a reference to a database
 
57
         * @param sql an SQL statement in UTF-8
57
58
         */
58
59
        explicit query(
59
 
                connection &connection );
 
60
                database &database );
60
61
 
61
62
//______________________________________________________________________________
62
63
//                                                              public interface
72
73
                const std::string &sql );
73
74
 
74
75
        /**
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
76
         * Perform a step() and return row object that can be used to retrieve the
84
77
         * results.
85
78
         * @return a row object
101
94
                unsigned int index );
102
95
 
103
96
        /**
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
97
         * Query iterator which can be used to obtain rows
116
98
         */
117
99
        class iterator
120
102
                        boost::single_pass_traversal_tag, row >
121
103
        {
122
104
        public:
123
 
                explicit iterator( query &query, bool step );
 
105
                iterator();
 
106
                explicit iterator( query &query, bool valid );
124
107
 
125
108
        private:
126
109
                friend class boost::iterator_core_access;
129
112
                void increment();
130
113
                bool equal( iterator const &other ) const;
131
114
 
132
 
                /** the current row */
133
 
                row _row;
 
115
                /** is this iterator still pointing to a valid row? */
 
116
                bool _valid;
134
117
 
135
118
                /** the query */
136
119
                query &_query;
137
120
        };
138
121
 
139
122
        /**
140
 
         * Get an iterator to the initial row. Note that creating an iterator
 
123
         * Return an iterator to the initial row. Note that creating an iterator
141
124
         * causes step() to be called, so it should only be called to begin
142
125
         * iterating over the rows and not for comparison.
143
126
         * @return a query iterator
145
128
        iterator begin();
146
129
 
147
130
        /**
148
 
         * Get an iterator to after the last row (i.e., an invalid row).
149
 
         * @return an invalid query iterator
 
131
         * Return an iterator to after the last row (i.e., an invalid row).
150
132
         */
151
133
        iterator end();
152
134
 
154
136
//                                                                implementation
155
137
private:
156
138
 
157
 
        /** next row number */
158
 
        unsigned long long _next_row_number;
 
139
        /** next row index */
 
140
        unsigned long long _next_row;
159
141
 
160
142
};
161
143