/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-01-28 12:21:03 UTC
  • Revision ID: edam@waxworlds.org-20100128122103-v3gs6hro5h7ffnhb
- further initial development
- basic support for: queries, rows (query results)
- filename, comment header and project name consistency

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <sqlite3cc/basic_statement.h>
24
24
#include <sqlite3cc/exception.h>
25
25
#include <sqlite3cc/database.h>
 
26
#include <sqlite3cc/manipulator.h>
26
27
#include <string.h>
 
28
#include <iomanip>
27
29
 
28
30
 
29
31
sqlite::basic_statement::basic_statement(
34
36
        _handle( NULL ),
35
37
        _bind_index( 1 )
36
38
{
37
 
        int code = prepare( sql );
38
 
        if( code != SQLITE_OK ) throw sqlite_error( database, code );
 
39
        int error_code = prepare( sql );
 
40
        if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
39
41
}
40
42
 
41
43
 
49
51
}
50
52
 
51
53
 
52
 
sqlite::basic_statement::~basic_statement()
 
54
sqlite::basic_statement::~basic_statement() throw( )
53
55
{
54
56
        finalize();
55
57
}
144
146
 
145
147
int sqlite::basic_statement::finalize()
146
148
{
147
 
        int code = SQLITE_OK;
 
149
        int error_code = SQLITE_OK;
148
150
 
149
151
        if( _handle ) {
150
 
                code = sqlite3_finalize( _handle );
 
152
                error_code = sqlite3_finalize( _handle );
151
153
                _handle = NULL;
152
154
        }
153
155
 
154
 
        return code;
 
156
        return error_code;
 
157
}
 
158
 
 
159
 
 
160
int sqlite::basic_statement::step()
 
161
{
 
162
        return sqlite3_step( _handle );
155
163
}
156
164
 
157
165
 
164
172
}
165
173
 
166
174
 
167
 
int sqlite::basic_statement::step()
168
 
{
169
 
        return sqlite3_step( _handle );
 
175
template< >
 
176
sqlite::basic_statement &sqlite::basic_statement::operator <<
 
177
        < sqlite::_null_t >(
 
178
        const sqlite::_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::_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 )
 
207
{
 
208
        _bind_index = t._index;
 
209
        return *this;
170
210
}