/sqlite3cc

To get this branch, use:
bzr branch http://bzr.ed.am/sqlite3cc

« back to all changes in this revision

Viewing changes to src/basic_statement.cc

  • Committer: edam
  • Date: 2010-07-29 06:28:53 UTC
  • Revision ID: edam@waxworlds.org-20100729062853-4i2fec52m86mh724
- made basic_statement::step() protected, for use by query and command only
- moved basic_statement::operator<<() to command and query instead; one needs to accept sqlite::exec, the other doesn't
- added tests for query::operator<<()
- added code to invlaidate in-progress queries during any transaction rollbacks (currently segfaults in basic_statement::finalize())
- added new sqlite_error constructor that obtains a full error message
- implemented database::database_mutex_guard class
- swapped command's step mutex in favour of the database mutex

Show diffs side-by-side

added added

removed removed

23
23
#include <sqlite3cc/basic_statement.h>
24
24
#include <sqlite3cc/exception.h>
25
25
#include <sqlite3cc/database.h>
26
 
#include <sqlite3cc/manipulator.h>
27
26
#include <string.h>
28
 
#include <iomanip>
29
27
 
30
28
 
31
29
sqlite::basic_statement::basic_statement(
36
34
        _handle( NULL ),
37
35
        _bind_index( 1 )
38
36
{
39
 
        int error_code = prepare( sql );
40
 
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
 
37
        int code = prepare( sql );
 
38
        if( code != SQLITE_OK ) throw sqlite_error( database, code );
41
39
}
42
40
 
43
41
 
146
144
 
147
145
int sqlite::basic_statement::finalize()
148
146
{
149
 
        int error_code = SQLITE_OK;
 
147
        int code = SQLITE_OK;
150
148
 
151
149
        if( _handle ) {
152
 
                error_code = sqlite3_finalize( _handle );
 
150
                code = sqlite3_finalize( _handle );
153
151
                _handle = NULL;
154
152
        }
155
153
 
156
 
        return error_code;
157
 
}
158
 
 
159
 
 
160
 
int sqlite::basic_statement::step()
161
 
{
162
 
        return sqlite3_step( _handle );
 
154
        return code;
163
155
}
164
156
 
165
157
 
172
164
}
173
165
 
174
166
 
175
 
template< >
176
 
sqlite::basic_statement &sqlite::basic_statement::operator <<
177
 
        < sqlite::detail::null_t >(
178
 
        const sqlite::detail::null_t & )
179
 
{
180
 
        int error_code = bind_null( _bind_index );
181
 
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
182
 
        _bind_index++;
183
 
        return *this;
184
 
}
185
 
 
186
 
 
187
 
template< >
188
 
sqlite::basic_statement &sqlite::basic_statement::operator <<
189
 
        < sqlite::detail::exec_t >(
190
 
        const sqlite::detail::exec_t & )
191
 
{
192
 
        int error_code = step();
193
 
        if( error_code != SQLITE_DONE ) {
194
 
                if( error_code == SQLITE_ROW )
195
 
                        throw sqlite_error( "statement returned results" );
196
 
                else
197
 
                        throw sqlite_error( error_code );
198
 
        }
199
 
        return *this;
200
 
}
201
 
 
202
 
 
203
 
template< >
204
 
sqlite::basic_statement &sqlite::basic_statement::operator <<
205
 
        < sqlite::detail::set_index_t >(
206
 
        const sqlite::detail::set_index_t &t )
207
 
{
208
 
        _bind_index = t._index;
209
 
        return *this;
 
167
int sqlite::basic_statement::step()
 
168
{
 
169
        return sqlite3_step( _handle );
210
170
}