aboutsummaryrefslogtreecommitdiff
path: root/odb/oracle/oracle-types.hxx
blob: f12caeb83d72daa74be2381551f687a98fa2b50c (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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
// file      : odb/oracle/oracle-types.hxx
// author    : Constantin Michael <constantin@codesynthesis.com>
// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
// license   : ODB NCUEL; see accompanying LICENSE file

#ifndef ODB_ORACLE_ORACLE_TYPES_HXX
#define ODB_ORACLE_ORACLE_TYPES_HXX

#include <odb/pre.hxx>

#include <odb/oracle/version.hxx>
#include <odb/oracle/oracle-fwd.hxx>
#include <odb/oracle/auto-descriptor.hxx>

namespace odb
{
  namespace oracle
  {
    enum chunk_position
    {
      one_chunk,
      first_chunk,
      next_chunk,
      last_chunk
    };

    // Callback function signature used to specify LOB parameters that are
    // passed to the database. If false is returned from the callback,
    // statement execution is aborted.
    //
    typedef bool (*param_callback_type) (
      const void* context,   // [in] The user context.
      ub4* position_context, // [in] A position context. A callback is free to
                             // use this to track position information. This is
                             // initialized to zero before the callback is
                             // invoked for the first time.
      const void** buffer,   // [out] On return, a pointer to a buffer
                             // containing parameter data.
      ub4* size,             // [out] The parameter data size in bytes.
      chunk_position*,       // [out] The position of the chunk of data in
                             // buffer.
      void* temp_buffer,     // [in] A temporary buffer that may be used if
                             // required. The buffer argument should specify
                             // this buffer on return if it is used.
      ub4 capacity);         // [in] The temporary buffer size in bytes.

    // Callback function signature used to specify LOB values returned from
    // the database. If false is returned, database_exception is thrown.
    //
    typedef bool (*result_callback_type) (
      void* context,         // [in] The user context.
      ub4* position_context, // [in] A position context. A callback is free to
                             // use this to track position information. This is
                             // initialized to zero before the callback is
                             // invoked for the first time.
      void* buffer,          // [in] A buffer containing the result data.
      ub4 size,              // [in] The result data size in bytes.
      chunk_position);       // [in] The position of this chunk.

    union lob_callback
    {
      param_callback_type param;
      result_callback_type result;
    };

    union lob_context
    {
      const void* param;
      void* result;
    };

    struct bind
    {
      // This enumeration identifies the possible buffer types that can be
      // bound to a bind instance. In most cases, these map directly to
      // SQLT_XXX codes, identifying an external OCI type. nstring and nclob
      // however have no equivalent OCI typecode. These additional identifiers
      // allow for a consistent interface across all types. Note that these
      // values are mapped to their corresponding external OCI typecodes (if
      // any) using their integer values, and should therefore not be
      // rearranged or explicitly assigned without also adjusting the
      // sqlt_lookup array in odb/oracle/statement.cxx.
      //
      enum buffer_type
      {
        integer,       // Buffer is an integer type of size specified by size.
        uinteger,      // Buffer is an unsigned integer of size specified by
                       // size.
        binary_float,  // Buffer is a float.
        binary_double, // Buffer is a double.
        number,        // Buffer is a variable length char array.
        date,          // Buffer is a 7-byte char array.
        timestamp,     // Buffer is a datetime.
        interval_ym,   // Buffer is an interval_ym.
        interval_ds,   // Buffer is an interval_ds.
        string,        // Buffer is a variable length char array.
        nstring,       // Buffer is a variable length char array.
        raw,           // Buffer is a variable length char array.
        blob,          // Bind is a callback.
        clob,          // Bind is a callback.
        nclob,         // Bind is a callback.
        last           // Used as an end of list marker.
      };

      buffer_type type; // The type stored by buffer.
      void* buffer;     // Data buffer pointer. When result callbacks are in
                        // use, this is interpreted as a lob_auto_descriptor*.
      ub2* size;        // The number of bytes in buffer. When parameter
                        // callbacks are in use, this is interpreted as a ub4*
                        // indicating the current position. For LOB result
                        // bindings, this is interpreted as the OCIDefine
                        // handle associated with the LOB result parameter.
      ub4 capacity;     // The maximum number of bytes that can be stored in
                        // buffer.
      sb2* indicator;   // Pointer to an OCI indicator variable.

      lob_callback* callback;

      // This pointer is provided to the user through the context argument
      // in both parameter and result callback functions.
      //
      lob_context* context;
    };

    // An instance of this structure specifies the function to invoke and
    // the context to pass just prior to the image associated with a query
    // being modified.
    //
    struct change_callback
    {
      change_callback (): callback (0), context (0) {};

      void (*callback) (void*);
      void* context;
    };

    //
    // These specialized auto_descriptor classes allows for transparent
    // transferal of descriptors between auto_descriptor instances. This
    // simplifies the implementation of a private copy of the shared image
    // associated with queries. The specializations for OCIDateTime and
    // OCIInterval also wrap OCI handles that are required for manipulation
    // of the descriptor data.
    //

    class LIBODB_ORACLE_EXPORT lob_auto_descriptor:
      public auto_descriptor<OCILobLocator>
    {
      typedef auto_descriptor <OCILobLocator> base;

    public:
      lob_auto_descriptor (OCILobLocator* l = 0)
        : base (l)
      {
      }

      lob_auto_descriptor (lob_auto_descriptor& x)
        : base (x.d_)
      {
        x.d_ = 0;
      }

      lob_auto_descriptor&
      operator= (lob_auto_descriptor& x)
      {
        OCILobLocator* l (x.d_);
        x.d_ = 0;
        reset (l);

        return *this;
      }
    };

    class LIBODB_ORACLE_EXPORT datetime_auto_descriptor:
      public auto_descriptor<OCIDateTime, dt_timestamp>
    {
      typedef auto_descriptor<OCIDateTime, dt_timestamp> base;

    public:
      datetime_auto_descriptor (OCIDateTime* d = 0):
        base (d),
        environment (0),
        error (0)
      {
      }

      datetime_auto_descriptor (datetime_auto_descriptor& x):
        base (x.d_),
        environment (x.environment),
        error (x.error)
      {
        x.d_ = 0;
      }

      datetime_auto_descriptor&
      operator= (datetime_auto_descriptor& x)
      {
        OCIDateTime* l (x.d_);
        x.d_ = 0;
        reset (l);

        environment = x.environment;
        error = x.error;

        return *this;
      }

      OCIEnv* environment;
      OCIError* error;
    };

    class LIBODB_ORACLE_EXPORT interval_ym_auto_descriptor:
      public auto_descriptor<OCIInterval, dt_interval_ym>
    {
      typedef auto_descriptor<OCIInterval, dt_interval_ym> base;

    public:
      interval_ym_auto_descriptor (OCIInterval* d = 0):
        base (d),
        environment (0),
        error (0)
      {
      }

      interval_ym_auto_descriptor (interval_ym_auto_descriptor& x):
        base (x.d_),
        environment (x.environment),
        error (x.error)
      {
        x.d_ = 0;
      }

      interval_ym_auto_descriptor&
      operator= (interval_ym_auto_descriptor& x)
      {
        OCIInterval* l (x.d_);
        x.d_ = 0;
        reset (l);

        environment = x.environment;
        error = x.error;

        return *this;
      }

      OCIEnv* environment;
      OCIError* error;
    };

    class LIBODB_ORACLE_EXPORT interval_ds_auto_descriptor:
      public auto_descriptor<OCIInterval, dt_interval_ds>
    {
      typedef auto_descriptor<OCIInterval, dt_interval_ds> base;

    public:
      interval_ds_auto_descriptor (OCIInterval* d = 0):
        base (d),
        environment (0),
        error (0)
      {
      }

      interval_ds_auto_descriptor (interval_ds_auto_descriptor& x):
        base (x.d_),
        environment (x.environment),
        error (x.error)
      {
        x.d_ = 0;
      }

      interval_ds_auto_descriptor&
      operator= (interval_ds_auto_descriptor& x)
      {
        OCIInterval* l (x.d_);
        x.d_ = 0;
        reset (l);

        environment = x.environment;
        error = x.error;

        return *this;
      }

      OCIEnv* environment;
      OCIError* error;
    };

    //
    // The OCIDateTime and OCIInterval APIs require that an environment and
    // error handle be passed any function that manipulates an OCIDateTime or
    // OCIInterval descriptor. It is however impossible to obtain these handles
    // the first time any temporal data image is initialized. The following
    // structures allow ODB generated code to interact with the OCI temporal
    // descriptor types indirectly via C++ primitives. The wrapped OCI
    // descriptor is then set using these primitives at a time when the all the
    // required data is available. A symmetric get interface is provided for
    // consistency.
    //

    struct LIBODB_ORACLE_EXPORT datetime
    {
      struct fields_type
      {
        sb2 year;
        ub1 month;
        ub1 day;
        ub1 hour;
        ub1 minute;
        ub1 second;
        ub4 nanosecond;
      };

      mutable fields_type fields;
      datetime_auto_descriptor descriptor;

      void
      get () const;

      void
      set ();

    };

    struct LIBODB_ORACLE_EXPORT interval_ym
    {
      struct fields_type
      {
        sb4 year;
        sb4 month;
      };

      mutable fields_type fields;
      interval_ym_auto_descriptor descriptor;

      void
      get () const;

      void
      set ();
    };

    struct LIBODB_ORACLE_EXPORT interval_ds
    {
      struct fields_type
      {
        sb4 day;
        sb4 hour;
        sb4 minute;
        sb4 second;
        sb4 nanosecond;
      };

      mutable fields_type fields;
      interval_ds_auto_descriptor descriptor;

      void
      get () const;

      void
      set ();
    };
  }
}

#include <odb/post.hxx>

#endif // ODB_ORACLE_ORACLE_TYPES_HXX