/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:39:13 UTC
  • Revision ID: edam@waxworlds.org-20100729063913-wvcvkogsa2alwkhr
- moved basic_statement::operator <<() back to basic_statement and just create another specialisation in command so that it can use sqlite::exec

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include <sqlite3cc/database.h>
26
26
#include <sqlite3cc/manipulator.h>
27
27
#include <string.h>
28
 
#include <iomanip>
29
28
 
30
29
 
31
30
sqlite::basic_statement::basic_statement(
36
35
        _handle( NULL ),
37
36
        _bind_index( 1 )
38
37
{
39
 
        int error_code = prepare( sql );
40
 
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
 
38
        int code = prepare( sql );
 
39
        if( code != SQLITE_OK ) throw sqlite_error( database, code );
41
40
}
42
41
 
43
42
 
51
50
}
52
51
 
53
52
 
54
 
sqlite::basic_statement::~basic_statement() throw( )
 
53
sqlite::basic_statement::~basic_statement()
55
54
{
56
55
        finalize();
57
56
}
146
145
 
147
146
int sqlite::basic_statement::finalize()
148
147
{
149
 
        int error_code = SQLITE_OK;
 
148
        int code = SQLITE_OK;
150
149
 
151
150
        if( _handle ) {
152
 
                error_code = sqlite3_finalize( _handle );
 
151
                code = sqlite3_finalize( _handle );
153
152
                _handle = NULL;
154
153
        }
155
154
 
156
 
        return error_code;
157
 
}
158
 
 
159
 
 
160
 
int sqlite::basic_statement::step()
161
 
{
162
 
        return sqlite3_step( _handle );
 
155
        return code;
163
156
}
164
157
 
165
158
 
172
165
}
173
166
 
174
167
 
 
168
int sqlite::basic_statement::step()
 
169
{
 
170
        return sqlite3_step( _handle );
 
171
}
 
172
 
 
173
 
 
174
 
175
175
template< >
176
176
sqlite::basic_statement &sqlite::basic_statement::operator <<
177
 
        < sqlite::_null_t >(
178
 
        const sqlite::_null_t & )
 
177
        < sqlite::detail::null_t >(
 
178
        const sqlite::detail::null_t & )
179
179
{
180
 
        int error_code = bind_null( _bind_index );
181
 
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
 
180
        int code = bind_null( _bind_index );
 
181
        if( code != SQLITE_OK ) throw sqlite_error( _database, code );
182
182
        _bind_index++;
183
183
        return *this;
184
184
}
186
186
 
187
187
template< >
188
188
sqlite::basic_statement &sqlite::basic_statement::operator <<
189
 
        < sqlite::_exec_t >(
190
 
        const sqlite::_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::_set_index_t >(
206
 
        const sqlite::_set_index_t &t )
 
189
        < sqlite::detail::set_index_t >(
 
190
        const sqlite::detail::set_index_t &t )
207
191
{
208
192
        _bind_index = t._index;
209
193
        return *this;