/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 20:56:19 UTC
  • Revision ID: edam@waxworlds.org-20100729205619-a9yo4uzu647nvnsj
- renamed database to connection to better identify what it is (would database_connection be better though?)
- moved basic_statement and basic_transaction to sqlite::detail
- made sqlite::threadsafe() return the threading mode int, not a bool
- renamed row::index() to row_number() so it isn't confused with column index
- added typedef for deferred_transaction
- added early rollback method to transaction_guard
- allowed transaction_guard::~transaction_guard() to throw exceptions, since when it needs to, we're really screwed anyway
- bugfix: query::reset() didn't reset the internal row counter
- added query::num_results()
- added docs/design-notes
- reimplemented query::iterator so that increment() (which performs a step() on the query) now caches the returned row to be returned during dereference() (previously it stashed details and returned new row!?)
- bugfix: resetting active queries during rollbacks would hang!

Show diffs side-by-side

added added

removed removed

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