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>
30
const std::string &sql )
32
basic_statement( database, sql ),
35
assert( sqlite3_column_count( _handle ) > 0 );
42
basic_statement( database ),
48
int sqlite::query::prepare(
49
const std::string &sql )
52
int error_code = basic_statement::prepare( sql );
53
assert( error_code != SQLITE_OK || sqlite3_column_count( _handle ) > 0 );
58
sqlite::row sqlite::query::step()
60
// sqlite3_mutex_enter( sqlite3_db_mutex( _database ) );
62
int error_code = basic_statement::step();
63
if( error_code == SQLITE_ROW ) {
64
// sqlite3_mutex_leave( sqlite3_db_mutex( _database ) );
65
return row( _handle, _next_row++ );
67
if( error_code == SQLITE_DONE ) {
68
// sqlite3_mutex_leave( sqlite3_db_mutex( _database ) );
71
throw sqlite_error( error_code );
74
// sqlite3_mutex_leave( sqlite3_db_mutex( _database ) );
80
unsigned int sqlite::query::column_count()
82
return sqlite3_column_count( _handle );
86
const std::string sqlite::query::column_name(
90
static_cast< unsigned int >( sqlite3_column_count( _handle ) ) );
91
return sqlite3_column_name( _handle, index );
95
sqlite::query::iterator::iterator(
108
sqlite::row sqlite::query::iterator::dereference() const
110
return sqlite::row( _query._handle, _query._next_row++ );
114
void sqlite::query::iterator::increment()
116
_valid = _query.step();
120
bool sqlite::query::iterator::equal(
121
sqlite::query::iterator const &other )
124
return _valid == other._valid;
128
sqlite::query::iterator sqlite::query::begin()
130
return sqlite::query::iterator( *this, true );
134
sqlite::query::iterator sqlite::query::end()
136
return sqlite::query::iterator( *this, false );