4
* Copyright (C) 2009 Tim Marston <edam@waxworlds.org>
4
* Copyright (C) 2009 Tim Marston <tim@ed.am>
6
6
* This file is part of sqlite3cc (hereafter referred to as "this program").
7
* See http://www.waxworlds.org/edam/software/sqlite3cc for more information.
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.
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.
7
* See http://ed.am/dev/sqlite3cc for more information.
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
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
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/>.
23
23
#include <sqlite3cc/basic_statement.h>
24
24
#include <sqlite3cc/exception.h>
25
#include <sqlite3cc/database.h>
25
#include <sqlite3cc/connection.h>
26
#include <sqlite3cc/manipulator.h>
26
27
#include <string.h>
29
sqlite::basic_statement::basic_statement(
30
sqlite::detail::basic_statement::basic_statement(
31
connection &connection,
31
32
const std::string &sql )
33
_database( database ),
34
_connection( connection ),
37
38
int code = prepare( sql );
38
if( code != SQLITE_OK ) throw sqlite_error( database, code );
39
if( code != SQLITE_OK ) throw sqlite_error( connection, code );
42
sqlite::basic_statement::basic_statement(
43
sqlite::detail::basic_statement::basic_statement(
44
connection &connection )
45
_database( database ),
46
_connection( connection ),
52
sqlite::basic_statement::~basic_statement()
53
sqlite::detail::basic_statement::~basic_statement()
58
int sqlite::basic_statement::prepare(
59
int sqlite::detail::basic_statement::prepare(
59
60
const std::string &sql )
62
return sqlite3_prepare_v2( _database._handle, sql.c_str(),
63
return sqlite3_prepare_v2( _connection._handle, sql.c_str(),
63
64
sql.length() + 1, &_handle, NULL );
67
int sqlite::basic_statement::reset()
68
int sqlite::detail::basic_statement::reset()
69
70
return sqlite3_reset( _handle );
73
int sqlite::basic_statement::clear_bindings()
74
int sqlite::detail::basic_statement::clear_bindings()
76
77
return sqlite3_clear_bindings( _handle );
80
int sqlite::basic_statement::bind_static(
81
int sqlite::detail::basic_statement::bind_static(
81
82
unsigned int index,
83
84
unsigned int value_length )
106
int sqlite::basic_statement::bind_null(
107
int sqlite::detail::basic_statement::bind_null(
107
108
unsigned int index )
109
110
return sqlite3_bind_null( _handle, index );
113
int sqlite::basic_statement::bind_static(
114
int sqlite::detail::basic_statement::bind_static(
114
115
const std::string &name,
115
116
const char *value,
116
117
unsigned int value_length )
138
int sqlite::basic_statement::bind_null(
139
int sqlite::detail::basic_statement::bind_null(
139
140
const std::string &name )
141
142
return bind_null( bind_parameter_index( name ) );
145
int sqlite::basic_statement::finalize()
146
int sqlite::detail::basic_statement::finalize()
147
148
int code = SQLITE_OK;
158
int sqlite::basic_statement::bind_parameter_index(
159
int sqlite::detail::basic_statement::bind_parameter_index(
159
160
const std::string &name )
161
162
unsigned int index = sqlite3_bind_parameter_index( _handle, name.c_str() );
167
int sqlite::basic_statement::step()
168
int sqlite::detail::basic_statement::step()
169
170
return sqlite3_step( _handle );
176
sqlite::detail::basic_statement &sqlite::detail::basic_statement::operator <<
177
< sqlite::detail::null_t >(
178
const sqlite::detail::null_t & )
180
int code = bind_null( _bind_index );
181
if( code != SQLITE_OK ) throw sqlite_error( _connection, code );
188
sqlite::detail::basic_statement &sqlite::detail::basic_statement::operator <<
189
< sqlite::detail::set_index_t >(
190
const sqlite::detail::set_index_t &t )
192
_bind_index = t._index;