4
4
* Copyright (C) 2009 Tim Marston <edam@waxworlds.org>
6
* This file is part of sqlitepp (hereafter referred to as "this program").
7
* See http://www.waxworlds.org/edam/software/sqlitepp for more information.
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
9
* This program is free software: you can redistribute it and/or modify
10
10
* it under the terms of the GNU Lesser General Public License as published
20
20
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23
#include <sqlitepp/query.hpp>
23
#include <sqlite3cc/query.h>
24
#include <sqlite3cc/row.h>
25
#include <sqlite3cc/manipulator.h>
26
#include <sqlite3cc/database.h>
32
const std::string &sql )
34
basic_statement( database, sql ),
37
assert( sqlite3_column_count( _handle ) > 0 );
44
basic_statement( database ),
50
int sqlite::query::prepare(
51
const std::string &sql )
54
int code = basic_statement::prepare( sql );
55
assert( code != SQLITE_OK || sqlite3_column_count( _handle ) > 0 );
60
sqlite::row sqlite::query::step()
62
database::database_mutex_guard lock( _database );
64
int code = basic_statement::step();
65
if( code == SQLITE_DONE ) return row();
66
if( code == SQLITE_ROW ) return row( _handle, _next_row++ );
68
throw sqlite_error( _database, code );
72
unsigned int sqlite::query::column_count()
74
return sqlite3_column_count( _handle );
78
const std::string sqlite::query::column_name(
82
static_cast< unsigned int >( sqlite3_column_count( _handle ) ) );
83
return sqlite3_column_name( _handle, index );
87
sqlite::query::iterator::iterator(
100
sqlite::row sqlite::query::iterator::dereference() const
102
return sqlite::row( _query._handle, _query._next_row++ );
106
void sqlite::query::iterator::increment()
108
_valid = _query.step();
112
bool sqlite::query::iterator::equal(
113
sqlite::query::iterator const &other )
116
return _valid == other._valid;
120
sqlite::query::iterator sqlite::query::begin()
122
return sqlite::query::iterator( *this, true );
126
sqlite::query::iterator sqlite::query::end()
128
return sqlite::query::iterator( *this, false );
133
sqlite::query &sqlite::query::operator <<
134
< sqlite::detail::null_t >(
135
const sqlite::detail::null_t & )
137
int code = bind_null( _bind_index );
138
if( code != SQLITE_OK ) throw sqlite_error( _database, code );
145
sqlite::query &sqlite::query::operator <<
146
< sqlite::detail::set_index_t >(
147
const sqlite::detail::set_index_t &t )
149
_bind_index = t._index;