summaryrefslogtreecommitdiff
path: root/src/resultset.cpp
blob: 9528a2ac7eb88bbd6de930882c594e7d718177e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// Copyright (c) 2022 Klemens Morgenstern (klemens.morgenstern@gmx.net)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//

#include <boost/sqlite/resultset.hpp>

BOOST_SQLITE_BEGIN_NAMESPACE


bool resultset::read_next(
              system::error_code & ec,
              error_info & ei) // could also return row* instead!
{
    if (done_)
        return false;
    auto cc = sqlite3_step(impl_.get());
    if (cc == SQLITE_DONE)
    {
        done_ = true;
        return false;
    }
    else if (cc != SQLITE_ROW)
    {
        BOOST_SQLITE_ASSIGN_EC(ec, cc);
        ei.set_message(sqlite3_errmsg(sqlite3_db_handle(impl_.get())));
    }
    return !done_;
}

bool resultset::read_next()
{
    system::error_code ec;
    error_info ei;
    auto tmp = read_next(ec, ei);
    if (ec)
        throw_exception(system::system_error(ec, ei.message()));
    return tmp;
}

resultset::iterator resultset::iterator::operator++()
{
  if (sentinel_)
    return *this;

  auto cc = sqlite3_step(row_.stm_);
  if (cc == SQLITE_DONE)
    sentinel_ = true;
  else if (cc != SQLITE_ROW)
  {
    system::error_code ec;
    BOOST_SQLITE_ASSIGN_EC(ec, cc);
    throw_exception(system::system_error(ec, sqlite3_errmsg(sqlite3_db_handle(row_.stm_))));
  }
  return *this;
}

BOOST_SQLITE_END_NAMESPACE