aboutsummaryrefslogtreecommitdiff
path: root/odb/mysql/result.txx
blob: 931ecf93230ae0924f3982fc068727c02d1b2095 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// file      : odb/mysql/result.txx
// author    : Boris Kolpackov <boris@codesynthesis.com>
// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
// license   : GNU GPL v2; see accompanying LICENSE file

namespace odb
{
  namespace mysql
  {
    template <typename T>
    result_impl<T>::
    ~result_impl ()
    {
    }

    template <typename T>
    result_impl<T>::
    result_impl (details::shared_ptr<select_statement> statement,
                 object_statements<T>& statements)
        : statement_ (statement), statements_ (statements)
    {
      next ();
    }

    template <typename T>
    void result_impl<T>::
    current (T& x)
    {
      if (!this->end_)
        traits::init (
          x, statements_.image (), statements_.connection ().database ());
    }

    template <typename T>
    void result_impl<T>::
    next ()
    {
      this->current (pointer_type ());
      select_statement::result r (statement_->fetch ());

      switch (r)
      {
      case select_statement::truncated:
        {
          typename traits::image_type& i (statements_.image ());

          if (traits::grow (i, statements_.image_error ()))
          {
            binding& b (statements_.image_binding ());
            traits::bind (b.bind, i);
            b.version++;
            statement_->refetch ();
          }
          // Fall throught.
        }
      case select_statement::success:
        {
          break;
        }
      case select_statement::no_data:
        {
          this->end_ = true;
          break;
        }
      }
    }

    template <typename T>
    void result_impl<T>::
    cache ()
    {
      statement_->cache ();
    }

    template <typename T>
    std::size_t result_impl<T>::
    size ()
    {
      return statement_->result_size ();
    }
  }
}