23
23
#include <sqlite3cc/basic_statement.h>
24
24
#include <sqlite3cc/exception.h>
25
#include <sqlite3cc/connection.h>
25
#include <sqlite3cc/database.h>
26
26
#include <sqlite3cc/manipulator.h>
27
27
#include <string.h>
30
sqlite::detail::basic_statement::basic_statement(
31
connection &connection,
32
const std::string &sql )
34
_connection( connection ),
38
int code = prepare( sql );
39
if( code != SQLITE_OK ) throw sqlite_error( connection, code );
43
sqlite::detail::basic_statement::basic_statement(
44
connection &connection )
46
_connection( connection ),
53
sqlite::detail::basic_statement::~basic_statement()
59
int sqlite::detail::basic_statement::prepare(
60
const std::string &sql )
63
return sqlite3_prepare_v2( _connection._handle, sql.c_str(),
31
sqlite::basic_statement::basic_statement(
33
const std::string &sql )
35
_database( database ),
39
int error_code = prepare( sql );
40
if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
44
sqlite::basic_statement::basic_statement(
47
_database( database ),
54
sqlite::basic_statement::~basic_statement()
60
int sqlite::basic_statement::prepare(
61
const std::string &sql )
64
return sqlite3_prepare_v2( _database._handle, sql.c_str(),
64
65
sql.length() + 1, &_handle, NULL );
68
int sqlite::detail::basic_statement::reset()
69
int sqlite::basic_statement::reset()
70
71
return sqlite3_reset( _handle );
74
int sqlite::detail::basic_statement::clear_bindings()
75
int sqlite::basic_statement::clear_bindings()
77
78
return sqlite3_clear_bindings( _handle );
81
int sqlite::detail::basic_statement::bind_static(
82
int sqlite::basic_statement::bind_static(
82
83
unsigned int index,
84
85
unsigned int value_length )
107
int sqlite::detail::basic_statement::bind_null(
108
int sqlite::basic_statement::bind_null(
108
109
unsigned int index )
110
111
return sqlite3_bind_null( _handle, index );
114
int sqlite::detail::basic_statement::bind_static(
115
int sqlite::basic_statement::bind_static(
115
116
const std::string &name,
116
117
const char *value,
117
118
unsigned int value_length )
139
int sqlite::detail::basic_statement::bind_null(
140
int sqlite::basic_statement::bind_null(
140
141
const std::string &name )
142
143
return bind_null( bind_parameter_index( name ) );
146
int sqlite::detail::basic_statement::finalize()
147
int sqlite::basic_statement::finalize()
148
int code = SQLITE_OK;
149
int error_code = SQLITE_OK;
151
code = sqlite3_finalize( _handle );
152
error_code = sqlite3_finalize( _handle );
159
int sqlite::detail::basic_statement::bind_parameter_index(
160
int sqlite::basic_statement::step()
162
return sqlite3_step( _handle );
166
int sqlite::basic_statement::bind_parameter_index(
160
167
const std::string &name )
162
169
unsigned int index = sqlite3_bind_parameter_index( _handle, name.c_str() );
168
int sqlite::detail::basic_statement::step()
170
return sqlite3_step( _handle );
176
sqlite::detail::basic_statement &sqlite::detail::basic_statement::operator <<
176
sqlite::basic_statement &sqlite::basic_statement::operator <<
177
177
< sqlite::detail::null_t >(
178
178
const sqlite::detail::null_t & )
180
int code = bind_null( _bind_index );
181
if( code != SQLITE_OK ) throw sqlite_error( _connection, code );
180
int error_code = bind_null( _bind_index );
181
if( error_code != SQLITE_OK ) throw sqlite_error( error_code );
188
sqlite::detail::basic_statement &sqlite::detail::basic_statement::operator <<
188
sqlite::basic_statement &sqlite::basic_statement::operator <<
189
< sqlite::detail::exec_t >(
190
const sqlite::detail::exec_t & )
192
int error_code = step();
193
if( error_code != SQLITE_DONE ) {
194
if( error_code == SQLITE_ROW )
195
throw sqlite_error( "statement returned results" );
197
throw sqlite_error( error_code );
204
sqlite::basic_statement &sqlite::basic_statement::operator <<
189
205
< sqlite::detail::set_index_t >(
190
206
const sqlite::detail::set_index_t &t )