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/database.h>
31
const std::string &sql )
33
basic_statement( database, sql ),
36
assert( sqlite3_column_count( _handle ) > 0 );
43
basic_statement( database ),
49
int sqlite::query::prepare(
50
const std::string &sql )
53
int code = basic_statement::prepare( sql );
54
assert( code != SQLITE_OK || sqlite3_column_count( _handle ) > 0 );
59
sqlite::row sqlite::query::step()
61
database::database_mutex_guard lock( _database );
63
int code = basic_statement::step();
64
if( code == SQLITE_DONE ) return row();
65
if( code == SQLITE_ROW ) return row( _handle, _next_row++ );
67
throw sqlite_error( _database, code );
71
unsigned int sqlite::query::column_count()
73
return sqlite3_column_count( _handle );
77
const std::string sqlite::query::column_name(
81
static_cast< unsigned int >( sqlite3_column_count( _handle ) ) );
82
return sqlite3_column_name( _handle, index );
86
sqlite::query::iterator::iterator(
99
sqlite::row sqlite::query::iterator::dereference() const
101
return sqlite::row( _query._handle, _query._next_row++ );
105
void sqlite::query::iterator::increment()
107
_valid = _query.step();
111
bool sqlite::query::iterator::equal(
112
sqlite::query::iterator const &other )
115
return _valid == other._valid;
119
sqlite::query::iterator sqlite::query::begin()
121
return sqlite::query::iterator( *this, true );
125
sqlite::query::iterator sqlite::query::end()
127
return sqlite::query::iterator( *this, false );