aboutsummaryrefslogtreecommitdiff
path: root/odb/mssql/traits.txx
blob: 634097eb3f81be04fb10658a8ddb299c3f167bce (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// file      : odb/mssql/traits.txx
// copyright : Copyright (c) 2005-2012 Code Synthesis Tools CC
// license   : ODB NCUEL; see accompanying LICENSE file

#include <cassert>

namespace odb
{
  namespace mssql
  {
    //
    // wrapped_value_traits<W, ID, true>
    //

    template <typename W, database_type_id ID>
    void wrapped_value_traits<W, ID, true>::
    result_callback (void* context,
                     std::size_t* position,
                     void** buffer,
                     std::size_t* size,
                     chunk_type chunk,
                     std::size_t size_left,
                     void* tmp_buffer,
                     std::size_t tmp_capacity)
    {
      W& v (*static_cast<W*> (context));

      if (chunk == chunk_null)
        wtraits::set_null (v);
      else
      {
        long_callback& c (*static_cast<long_callback*> (*buffer));

        // Redirect all further calls.
        //
        vtraits::set_value (wtraits::set_ref (v),
                            c.callback.result,
                            c.context.result);

        // Forward this call.
        //
        c.callback.result (
          c.context.result,
          position,
          buffer,
          size,
          chunk,
          size_left,
          tmp_buffer,
          tmp_capacity);
      }
    }

    //
    // c_array_long_binary_value_traits
    //

    template <typename C, std::size_t N>
    void c_array_long_binary_value_traits<C, N>::
    param_callback (const void* context,
                    std::size_t*,
                    const void** buffer,
                    std::size_t* size,
                    chunk_type* chunk,
                    void*,
                    std::size_t)
    {
      *buffer = context;
      *size = N;
      *chunk = chunk_one;
    }

    template <typename C, std::size_t N>
    void c_array_long_binary_value_traits<C, N>::
    result_callback (void* context,
                     std::size_t*,
                     void** buffer,
                     std::size_t* size,
                     chunk_type chunk,
                     std::size_t size_left,
                     void* tmp_buf,
                     std::size_t tmp_capacity)
    {
      // The code is similar to the vector<char> specialization.
      //
      switch (chunk)
      {
      case chunk_null:
      case chunk_one:
        {
          std::memset (context, 0, N);
          break;
        }
      case chunk_first:
        {
          assert (size_left != 0);

          *buffer = context;
          *size = size_left < N ? size_left : N;
          break;
        }
      case chunk_next:
        {
          // We can get here if total size is greater than N. There is
          // no way to stop until we read all the data, so dump the
          // remainder into the temporary buffer.
          //
          *buffer = tmp_buf;
          *size = tmp_capacity;
          break;
        }
      case chunk_last:
        {
          break;
        }
      }
    }

#ifdef ODB_CXX11
    //
    // array_long_binary_value_traits
    //

    template <typename C, std::size_t N>
    void array_long_binary_value_traits<C, N>::
    param_callback (const void* context,
                    std::size_t*,
                    const void** buffer,
                    std::size_t* size,
                    chunk_type* chunk,
                    void*,
                    std::size_t)
    {
      *buffer = context;
      *size = N;
      *chunk = chunk_one;
    }

    template <typename C, std::size_t N>
    void array_long_binary_value_traits<C, N>::
    result_callback (void* context,
                     std::size_t*,
                     void** buffer,
                     std::size_t* size,
                     chunk_type chunk,
                     std::size_t size_left,
                     void* tmp_buf,
                     std::size_t tmp_capacity)
    {
      // The code is similar to the vector<char> specialization.
      //
      switch (chunk)
      {
      case chunk_null:
      case chunk_one:
        {
          std::memset (context, 0, N);
          break;
        }
      case chunk_first:
        {
          assert (size_left != 0);

          *buffer = context;
          *size = size_left < N ? size_left : N;
          break;
        }
      case chunk_next:
        {
          // We can get here if total size is greater than N. There is
          // no way to stop until we read all the data, so dump the
          // remainder into the temporary buffer.
          //
          *buffer = tmp_buf;
          *size = tmp_capacity;
          break;
        }
      case chunk_last:
        {
          break;
        }
      }
    }
#endif
  }
}