/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

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/>.
44
44
        /**
45
45
         * Constructor that provides a connection upon which to act and the SQL
46
46
         * query to execute.
47
 
         *
48
47
         * @param connection a reference to a connection
49
48
         * @param sql an SQL statement in UTF-8
50
49
         */
54
53
 
55
54
        /**
56
55
         * Constructor that provides a connection upon which to act.
57
 
         *
58
56
         * @param connection a reference to a connection
59
57
         */
60
58
        explicit query(
66
64
 
67
65
        /**
68
66
         * Prepare an SQL statement.
69
 
         *
70
67
         * @param sql an SQL statement in UTF-8
71
68
         * @returns an sqlite error code
72
69
         * @see sqlite3_prepare_v2()
75
72
                const std::string &sql );
76
73
 
77
74
        /**
78
 
         * 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
79
76
         * the values bound to the statement.
80
 
         *
81
77
         * @returns an sqlite error code
82
78
         * @see sqlite3_reset()
83
79
         */
86
82
        /**
87
83
         * Perform a step() and return row object that can be used to retrieve the
88
84
         * results.
89
 
         *
90
85
         * @return a row object
91
86
         */
92
87
        row step();
93
88
 
94
89
        /**
95
 
         * Get the number of columns in the results.
96
 
         *
 
90
         * Get the number of columns in the results
97
91
         * @see sqlite3_column_count()
98
92
         */
99
93
        unsigned int column_count();
100
94
 
101
95
        /**
102
 
         * Get the name of a column in the results.
103
 
         *
 
96
         * Get the name of a column in the results
104
97
         * @param index column index
105
98
         * @see sqlite3_column_name()
106
99
         */
108
101
                unsigned int index );
109
102
 
110
103
        /**
111
 
         * Gets the number of results.  Be aware that this merely step()s over the
112
 
         * 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
113
106
         * method is intended to be used for convenience, where you only need know
114
 
         * 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
115
108
         * SQL like this: "SELECT COUNT(*) ...", but this only causes SQLite to
116
 
         * 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
117
110
         * method reset()s the query.
118
 
         *
119
 
         * @returns the number of results
120
111
         */
121
112
        unsigned long long num_results();
122
113
 
123
114
        /**
124
 
         * Query iterator which can be used to obtain rows.
 
115
         * Query iterator which can be used to obtain rows
125
116
         */
126
117
        class iterator
127
118
                :
146
137
        };
147
138
 
148
139
        /**
149
 
         * 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
150
141
         * causes step() to be called, so it should only be called to begin
151
142
         * iterating over the rows and not for comparison.
152
 
         *
153
143
         * @return a query iterator
154
144
         */
155
145
        iterator begin();
156
146
 
157
147
        /**
158
148
         * Get an iterator to after the last row (i.e., an invalid row).
159
 
         *
160
149
         * @return an invalid query iterator
161
150
         */
162
151
        iterator end();