Oracle ODB Runtime Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
traits.hxx
Go to the documentation of this file.
1 // file : odb/oracle/traits.hxx
2 // copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC
3 // license : ODB NCUEL; see accompanying LICENSE file
4 
5 #ifndef ODB_ORACLE_TRAITS_HXX
6 #define ODB_ORACLE_TRAITS_HXX
7 
8 #include <odb/pre.hxx>
9 
10 #include <odb/details/config.hxx> // ODB_CXX11
11 
12 #include <string>
13 #include <vector>
14 #include <cstddef> // std::size_t
15 #include <cstring> // std::memcpy, std::memset, std::strlen
16 
17 #ifdef ODB_CXX11
18 # include <array>
19 #endif
20 
21 #include <odb/traits.hxx>
22 #include <odb/wrapper-traits.hxx>
23 
24 #include <odb/oracle/version.hxx>
26 
27 #include <odb/details/buffer.hxx>
28 #include <odb/details/wrapper-p.hxx>
29 
30 #include <odb/oracle/details/export.hxx>
31 #include <odb/oracle/details/number.hxx>
32 
33 namespace odb
34 {
35  namespace oracle
36  {
38  {
41 
43 
46 
47  // Both large fixed-point and large floating point NUMBER and FLOAT
48  // values are mapped to this id.
49  //
51 
56 
59 
61 
65  };
66 
67  //
68  // int_traits
69  //
70 
71  // Only mark fundamental unsigned integers as unsigned. In particular,
72  // treat enums as signed since in most cases and on most platforms the
73  // underlying integer type will be signed. On Windows with VC9 and up
74  // and with GCC, the __intN types are simply aliases for the respective
75  // standard integers so the below code will cover them as well. Also
76  // note that the ODB compiler performs a similar test, so if you change
77  // anything below you will probably also need to make a similar change
78  // there.
79  //
80  template <typename T>
81  struct int_traits {static const bool unsign = false;};
82 
83  template <>
84  struct int_traits<bool> {static const bool unsign = true;};
85  template <>
86  struct int_traits<unsigned char> {static const bool unsign = true;};
87  template <>
88  struct int_traits<unsigned short> {static const bool unsign = true;};
89  template <>
90  struct int_traits<unsigned int> {static const bool unsign = true;};
91  template <>
92  struct int_traits<unsigned long> {static const bool unsign = true;};
93  template <>
94  struct int_traits<unsigned long long>
95  {
96  static const bool unsign = true;
97  };
98 
99  //
100  // image_traits
101  //
102 
103  template <typename T, database_type_id>
104  struct image_traits;
105 
106  // int32
107  //
108  template <bool unsign>
110 
111  template <>
112  struct int32_image_traits<false>
113  {
114  static const bind::buffer_type buffer_type = bind::integer;
115  typedef int image_type;
116  };
117 
118  template <>
119  struct int32_image_traits<true>
120  {
121  static const bind::buffer_type buffer_type = bind::uinteger;
122  typedef unsigned int image_type;
123  };
124 
125  template <typename T>
126  struct image_traits<T, id_int32>: int32_image_traits<int_traits<T>::unsign>
127  {
128  };
129 
130  // int64
131  //
132  template <bool unsign>
134 
135  template <>
136  struct int64_image_traits<false>
137  {
138  static const bind::buffer_type buffer_type = bind::integer;
139  typedef long long image_type;
140  };
141 
142  template <>
143  struct int64_image_traits<true>
144  {
145  static const bind::buffer_type buffer_type = bind::uinteger;
146  typedef unsigned long long image_type;
147  };
148 
149  template <typename T>
150  struct image_traits<T, id_int64>: int64_image_traits<int_traits<T>::unsign>
151  {
152  };
153 
154  // big_int
155  //
156  template <typename T>
158  {
159  // Image is a buffer containing native OCI NUMBER representation.
160  //
161  typedef char* image_type;
162  };
163 
164  template <typename T>
165  struct image_traits<T, id_float> {typedef float image_type;};
166 
167  template <typename T>
168  struct image_traits<T, id_double> {typedef double image_type;};
169 
170  template <typename T>
172  {
173  // Image is a buffer containing the native OCI NUMBER representation.
174  //
175  typedef char* image_type;
176  };
177 
178  template <typename T>
180  {
181  // Image is a buffer containing the native OCI DATE representation. This
182  // buffer has a fixed length of 7 bytes.
183  //
184  typedef char* image_type;
185  };
186 
187  template <typename T>
189  {
191  };
192 
193  template <typename T>
195  {
197  };
198 
199  template <typename T>
201  {
203  };
204 
205  template <typename T>
206  struct image_traits<T, id_string> {typedef char* image_type;};
207 
208  template <typename T>
209  struct image_traits<T, id_nstring> {typedef char* image_type;};
210 
211  template <typename T>
212  struct image_traits<T, id_raw> {typedef char* image_type;};
213 
214  template <typename T>
216 
217  template <typename T>
219 
220  template <typename T>
222 
223  //
224  // value_traits
225  //
226 
227  template <typename W, database_type_id, bool null_handler>
229 
230  template <typename T, database_type_id>
232 
233  template <typename T, database_type_id, bool w = details::wrapper_p<T>::r>
235 
236  template <typename T, database_type_id ID>
237  struct select_traits<T, ID, false>
238  {
240  };
241 
242  template <typename W, database_type_id ID>
243  struct select_traits<W, ID, true>
244  {
245  typedef
248  };
249 
250  template <typename T, database_type_id ID>
251  class value_traits: public select_traits<T, ID>::type
252  {
253  };
254 
255  // The wrapped_value_traits specializations should be able to handle
256  // any value type which means we have to have every possible signature
257  // of the set_value() and set_image() functions.
258  //
259  template <typename W, database_type_id ID>
260  struct wrapped_value_traits<W, ID, false>
261  {
263  typedef typename wtraits::unrestricted_wrapped_type wrapped_type;
264 
265  typedef W value_type;
268 
270 
271  static void
272  set_value (W& v, const image_type& i, bool is_null)
273  {
274  vtraits::set_value (wtraits::set_ref (v), i, is_null);
275  }
276 
277  static void
278  set_image (image_type& i, bool& is_null, const W& v)
279  {
280  vtraits::set_image (i, is_null, wtraits::get_ref (v));
281  }
282 
283  // big_int, big_float, string, nstring, raw.
284  //
285  static void
286  set_value (W& v, const char* i, std::size_t n, bool is_null)
287  {
288  vtraits::set_value (wtraits::set_ref (v), i, n, is_null);
289  }
290 
291  // string, nstring, raw.
292  //
293  static void
294  set_image (char* i,
295  std::size_t c,
296  std::size_t& n,
297  bool& is_null,
298  const W& v)
299  {
300  vtraits::set_image (i, c, n, is_null, wtraits::get_ref (v));
301  }
302 
303  // big_int, big_float.
304  //
305  static void
306  set_image (char* i, std::size_t& n, bool& is_null, const W& v)
307  {
308  vtraits::set_image (i, n, is_null, wtraits::get_ref (v));
309  }
310 
311  // blob, clob, nclob.
312  //
313  static void
314  set_value (W& v, result_callback_type& cb, void*& context, bool is_null)
315  {
316  vtraits::set_value (wtraits::set_ref (v), cb, context, is_null);
317  }
318 
319  static void
321  const void*& context,
322  bool& is_null,
323  const W& v)
324  {
325  vtraits::set_image (cb, context, is_null, wtraits::get_ref (v));
326  }
327  };
328 
329  template <typename W, database_type_id ID>
330  struct wrapped_value_traits<W, ID, true>
331  {
333  typedef typename wtraits::unrestricted_wrapped_type wrapped_type;
334 
335  typedef W value_type;
338 
340 
341  static void
342  set_value (W& v, const image_type& i, bool is_null)
343  {
344  if (is_null)
345  wtraits::set_null (v);
346  else
347  vtraits::set_value (wtraits::set_ref (v), i, is_null);
348  }
349 
350  static void
351  set_image (image_type& i, bool& is_null, const W& v)
352  {
353  is_null = wtraits::get_null (v);
354 
355  if (!is_null)
356  vtraits::set_image (i, is_null, wtraits::get_ref (v));
357  }
358 
359  // big_int, big_float, string, nstring, raw.
360  //
361  static void
362  set_value (W& v, const char* i, std::size_t n, bool is_null)
363  {
364  if (is_null)
365  wtraits::set_null (v);
366  else
367  vtraits::set_value (wtraits::set_ref (v), i, n, is_null);
368  }
369 
370  // string, nstring, raw.
371  //
372  static void
373  set_image (char* i,
374  std::size_t c,
375  std::size_t& n,
376  bool& is_null,
377  const W& v)
378  {
379  is_null = wtraits::get_null (v);
380 
381  if (!is_null)
382  vtraits::set_image (i, c, n, is_null, wtraits::get_ref (v));
383  }
384 
385  // big_int, big_float
386  //
387  static void
388  set_image (char* i, std::size_t& n, bool& is_null, const W& v)
389  {
390  is_null = wtraits::get_null (v);
391 
392  if (!is_null)
393  vtraits::set_image (i, n, is_null, wtraits::get_ref (v));
394  }
395 
396  // blob, clob, nclob.
397  //
398  static void
399  set_value (W& v, result_callback_type& cb, void*& context, bool is_null)
400  {
401  if (is_null)
402  wtraits::set_null (v);
403  else
404  vtraits::set_value (wtraits::set_ref (v), cb, context, is_null);
405  }
406 
407  static void
409  const void*& context,
410  bool& is_null,
411  const W& v)
412  {
413  is_null = wtraits::get_null (v);
414 
415  if (!is_null)
416  vtraits::set_image (cb, context, is_null, wtraits::get_ref (v));
417  }
418  };
419 
420  template <typename T, database_type_id ID>
421  struct default_value_traits
422  {
423  typedef T value_type;
424  typedef T query_type;
426 
427  static void
428  set_value (T& v, const image_type& i, bool is_null)
429  {
430  if (!is_null)
431  v = T (i);
432  else
433  v = T ();
434  }
435 
436  static void
437  set_image (image_type& i, bool& is_null, T v)
438  {
439  is_null = false;
440  i = image_type (v);
441  }
442  };
443 
444  // id_big_int partial specialization.
445  //
446  template <typename T, bool unsign>
448 
449  template <typename T>
450  struct big_int_value_traits<T, false>
451  {
452  static void
453  set_value (T& v, const char* b, std::size_t n, bool is_null)
454  {
455  if (!is_null)
456  v = static_cast<T> (details::number_to_int64 (b, n));
457  else
458  v = 0;
459  }
460 
461  static void
462  set_image (char* b, std::size_t& n, bool& is_null, T v)
463  {
464  is_null = false;
465  details::int64_to_number (b, n, static_cast<long long> (v));
466  }
467  };
468 
469  template <typename T>
470  struct big_int_value_traits<T, true>
471  {
472  static void
473  set_value (T& v, const char* b, std::size_t n, bool is_null)
474  {
475  if (!is_null)
476  v = static_cast<T> (details::number_to_uint64 (b, n));
477  else
478  v = 0;
479  }
480 
481  static void
482  set_image (char* b, std::size_t& n, bool& is_null, T v)
483  {
484  is_null = false;
485  details::uint64_to_number (b, n, static_cast<unsigned long long> (v));
486  }
487  };
488 
489  template <typename T>
491  big_int_value_traits<T, int_traits<T>::unsign>
492  {
493  typedef T value_type;
494  typedef T query_type;
496  };
497 
498  // std::string specialization.
499  //
500  class LIBODB_ORACLE_EXPORT string_value_traits
501  {
502  public:
503  typedef std::string value_type;
504  typedef std::string query_type;
505  typedef char* image_type;
506 
507  static void
508  set_value (std::string& v,
509  const char* b,
510  std::size_t n,
511  bool is_null)
512  {
513  if (!is_null)
514  v.assign (b, n);
515  else
516  v.erase ();
517  }
518 
519  static void
520  set_image (char* b,
521  std::size_t c,
522  std::size_t& n,
523  bool& is_null,
524  const std::string& v)
525  {
526  is_null = false;
527  n = v.size ();
528 
529  if (n > c)
530  n = c;
531 
532  if (n != 0)
533  std::memcpy (b, v.c_str (), n);
534  }
535  };
536 
537  template <>
538  struct LIBODB_ORACLE_EXPORT default_value_traits<std::string, id_string>:
540  {
541  };
542 
543  template <>
544  struct LIBODB_ORACLE_EXPORT default_value_traits<std::string, id_nstring>:
546  {
547  };
548 
549  // char*/const char* specialization.
550  //
551  // Specialization for const char* which only supports initialization
552  // of an image from the value but not the other way around. This way
553  // we can pass such values to the queries.
554  //
555  class LIBODB_ORACLE_EXPORT c_string_value_traits
556  {
557  public:
558  typedef const char* value_type;
559  typedef char* image_type;
560 
561  static void
562  set_image (char* b,
563  std::size_t c,
564  std::size_t& n,
565  bool& is_null,
566  const char* v)
567  {
568  is_null = false;
569  n = std::strlen (v);
570 
571  if (n > c)
572  n = c;
573 
574  if (n != 0)
575  std::memcpy (b, v, n);
576  }
577  };
578 
579  template <>
580  struct LIBODB_ORACLE_EXPORT default_value_traits<char*, id_string>:
582 
583  template <>
584  struct LIBODB_ORACLE_EXPORT default_value_traits<char*, id_nstring>:
586 
587  template <>
588  struct LIBODB_ORACLE_EXPORT default_value_traits<const char*, id_string>:
590 
591  template <>
592  struct LIBODB_ORACLE_EXPORT default_value_traits<const char*, id_nstring>:
594 
595  // char[N] specializations.
596  //
597  struct LIBODB_ORACLE_EXPORT c_array_value_traits_base
598  {
599  static void
600  set_value (char* const& v,
601  const char* b,
602  std::size_t n,
603  bool is_null,
604  std::size_t N);
605 
606  static void
607  set_image (char* b,
608  std::size_t c,
609  std::size_t& n,
610  bool& is_null,
611  const char* v,
612  std::size_t N);
613  };
614 
615  template <std::size_t N>
617  {
618  typedef char* value_type;
619  typedef char query_type[N];
620  typedef details::buffer image_type;
621 
622  static void
623  set_value (char* const& v,
624  const char* b,
625  std::size_t n,
626  bool is_null)
627  {
628  c_array_value_traits_base::set_value (v, b, n, is_null, N);
629  }
630 
631  static void
632  set_image (char* b,
633  std::size_t c,
634  std::size_t& n,
635  bool& is_null,
636  const char* v)
637  {
638  c_array_value_traits_base::set_image (b, c, n, is_null, v, N);
639  }
640  };
641 
642  template <std::size_t N>
643  struct default_value_traits<char[N], id_string>:
644  c_array_value_traits<N> {};
645 
646  template <std::size_t N>
648  c_array_value_traits<N> {};
649 
650  // std::array<char, N> (string) specialization.
651  //
652 #ifdef ODB_CXX11
653  template <std::size_t N>
654  struct std_array_value_traits
655  {
656  typedef std::array<char, N> value_type;
657  typedef std::array<char, N> query_type;
658  typedef details::buffer image_type;
659 
660  static void
661  set_value (value_type& v,
662  const char* b,
663  std::size_t n,
664  bool is_null)
665  {
666  c_array_value_traits_base::set_value (v.data (), b, n, is_null, N);
667  }
668 
669  static void
670  set_image (char* b,
671  std::size_t c,
672  std::size_t& n,
673  bool& is_null,
674  const value_type& v)
675  {
676  c_array_value_traits_base::set_image (b, c, n, is_null, v.data (), N);
677  }
678  };
679 
680  template <std::size_t N>
681  struct default_value_traits<std::array<char, N>, id_string>:
682  std_array_value_traits<N> {};
683 
684  template <std::size_t N>
685  struct default_value_traits<std::array<char, N>, id_nstring>:
686  std_array_value_traits<N> {};
687 #endif
688 
689  // char specialization.
690  //
691  struct LIBODB_ORACLE_EXPORT char_value_traits
692  {
693  typedef char value_type;
694  typedef char query_type;
695  typedef details::buffer image_type;
696 
697  static void
698  set_value (char& v,
699  const char* b,
700  std::size_t n,
701  bool is_null)
702  {
703  c_array_value_traits_base::set_value (&v, b, n, is_null, 1);
704  }
705 
706  static void
707  set_image (char* b,
708  std::size_t c,
709  std::size_t& n,
710  bool& is_null,
711  char v)
712  {
713  c_array_value_traits_base::set_image (b, c, n, is_null, &v, 1);
714  }
715  };
716 
717  template <>
718  struct LIBODB_ORACLE_EXPORT default_value_traits<char, id_string>:
720 
721  template <>
722  struct LIBODB_ORACLE_EXPORT default_value_traits<char, id_nstring>:
724 
725  // std::vector<char> (buffer) specialization for RAW.
726  //
727  template <>
728  struct LIBODB_ORACLE_EXPORT default_value_traits<std::vector<char>, id_raw>
729  {
730  public:
731  typedef std::vector<char> value_type;
732  typedef std::vector<char> query_type;
733  typedef char* image_type;
734 
735  static void
736  set_value (value_type& v, const char* b, std::size_t n, bool is_null)
737  {
738  if (!is_null)
739  v.assign (b, b + n);
740  else
741  v.clear ();
742  }
743 
744  static void
745  set_image (char* b,
746  std::size_t c,
747  std::size_t& n,
748  bool& is_null,
749  const value_type& v)
750  {
751  is_null = false;
752  n = v.size ();
753 
754  if (n > c)
755  n = c;
756 
757  // std::vector::data() may not be available in older compilers.
758  //
759  if (n != 0)
760  std::memcpy (b, &v.front (), n);
761  }
762  };
763 
764  // std::vector<unsigned char> (buffer) specialization for RAW.
765  //
766  template <>
767  struct LIBODB_ORACLE_EXPORT
768  default_value_traits<std::vector<unsigned char>, id_raw>
769  {
770  typedef std::vector<unsigned char> value_type;
771  typedef std::vector<unsigned char> query_type;
772  typedef char* image_type;
773 
774  static void
775  set_value (value_type& v, const char* b, std::size_t n, bool is_null)
776  {
777  if (!is_null)
778  {
779  const unsigned char* ub (reinterpret_cast<const unsigned char*> (b));
780  v.assign (ub, ub + n);
781  }
782  else
783  v.clear ();
784  }
785 
786  static void
787  set_image (char* b,
788  std::size_t c,
789  std::size_t& n,
790  bool& is_null,
791  const value_type& v)
792  {
793  is_null = false;
794  n = v.size ();
795 
796  if (n > c)
797  n = c;
798 
799  // std::vector::data() may not be available in older compilers.
800  //
801  if (n != 0)
802  std::memcpy (b, &v.front (), n);
803  }
804  };
805 
806  // char[N] (buffer) specialization for RAW.
807  //
808  template <std::size_t N>
809  struct default_value_traits<char[N], id_raw>
810  {
811  typedef char* value_type;
812  typedef char query_type[N];
813  typedef char* image_type;
814 
815  static void
816  set_value (char* const& v, const char* b, std::size_t n, bool is_null)
817  {
818  if (!is_null)
819  std::memcpy (v, b, (n < N ? n : N));
820  else
821  std::memset (v, 0, N);
822  }
823 
824  static void
825  set_image (char* b,
826  std::size_t c,
827  std::size_t& n,
828  bool& is_null,
829  const char* v)
830  {
831  is_null = false;
832  n = N < c ? N : c;
833  std::memcpy (b, v, n);
834  }
835  };
836 
837  // unsigned char[N] (buffer) specialization for RAW.
838  //
839  template <std::size_t N>
840  struct default_value_traits<unsigned char[N], id_raw>
841  {
842  typedef unsigned char* value_type;
843  typedef unsigned char query_type[N];
844  typedef char* image_type;
845 
846  static void
847  set_value (unsigned char* const& v,
848  const char* b,
849  std::size_t n,
850  bool is_null)
851  {
852  if (!is_null)
853  std::memcpy (v, b, (n < N ? n : N));
854  else
855  std::memset (v, 0, N);
856  }
857 
858  static void
859  set_image (char* b,
860  std::size_t c,
861  std::size_t& n,
862  bool& is_null,
863  const unsigned char* v)
864  {
865  is_null = false;
866  n = N < c ? N : c;
867  std::memcpy (b, v, n);
868  }
869  };
870 
871 #ifdef ODB_CXX11
872  // std::array<char, N> (buffer) specialization for RAW.
873  //
874  template <std::size_t N>
875  struct default_value_traits<std::array<char, N>, id_raw>
876  {
877  public:
878  typedef std::array<char, N> value_type;
879  typedef value_type query_type;
880  typedef char* image_type;
881 
882  static void
883  set_value (value_type& v, const char* b, std::size_t n, bool is_null)
884  {
885  if (!is_null)
886  std::memcpy (v.data (), b, (n < N ? n : N));
887  else
888  std::memset (v.data (), 0, N);
889  }
890 
891  static void
892  set_image (char* b,
893  std::size_t c,
894  std::size_t& n,
895  bool& is_null,
896  const value_type& v)
897  {
898  is_null = false;
899  n = N < c ? N : c;
900  std::memcpy (b, v.data (), n);
901  }
902  };
903 
904  // std::array<unsigned char, N> (buffer) specialization for RAW.
905  //
906  template <std::size_t N>
907  struct default_value_traits<std::array<unsigned char, N>, id_raw>
908  {
909  public:
910  typedef std::array<unsigned char, N> value_type;
911  typedef value_type query_type;
912  typedef char* image_type;
913 
914  static void
915  set_value (value_type& v, const char* b, std::size_t n, bool is_null)
916  {
917  if (!is_null)
918  std::memcpy (v.data (), b, (n < N ? n : N));
919  else
920  std::memset (v.data (), 0, N);
921  }
922 
923  static void
924  set_image (char* b,
925  std::size_t c,
926  std::size_t& n,
927  bool& is_null,
928  const value_type& v)
929  {
930  is_null = false;
931  n = N < c ? N : c;
932  std::memcpy (b, v.data (), n);
933  }
934  };
935 #endif
936 
937  // std::string specialization for LOBs.
938  //
939  class LIBODB_ORACLE_EXPORT string_lob_value_traits
940  {
941  public:
942  typedef std::string value_type;
943  typedef std::string query_type;
945 
946  static void
947  set_value (std::string& v,
949  void*& context,
950  bool is_null)
951  {
952  if (!is_null)
953  {
954  cb = &result_callback;
955  context = &v;
956  }
957  else
958  v.erase ();
959  }
960 
961  static void
963  const void*& context,
964  bool& is_null,
965  const std::string& v)
966  {
967  is_null = false;
968  cb = &param_callback;
969  context = &v;
970  }
971 
972  static bool
973  result_callback (void* context,
974  ub4* position_context,
975  void* buffer,
976  ub4 size,
978 
979  static bool
980  param_callback (const void* context,
981  ub4* position_context,
982  const void** buffer,
983  ub4* size,
985  void* temp_buffer,
986  ub4 capacity);
987  };
988 
989  template <>
990  struct LIBODB_ORACLE_EXPORT default_value_traits<std::string, id_clob>:
992  {
993  };
994 
995  template <>
996  struct LIBODB_ORACLE_EXPORT default_value_traits<std::string, id_nclob>:
998  {
999  };
1000 
1001  // std::vector<char> (buffer) specialization for BLOBs.
1002  //
1003  template <>
1004  struct LIBODB_ORACLE_EXPORT default_value_traits<std::vector<char>,
1005  id_blob>
1006  {
1007  public:
1008  typedef std::vector<char> value_type;
1009  typedef std::vector<char> query_type;
1011 
1012  static void
1015  void*& context,
1016  bool is_null)
1017  {
1018  if (!is_null)
1019  {
1020  cb = &result_callback;
1021  context = &v;
1022  }
1023  else
1024  v.clear ();
1025  }
1026 
1027  static void
1029  const void*& context,
1030  bool& is_null,
1031  const value_type& v)
1032  {
1033  is_null = false;
1034  cb = &param_callback;
1035  context = &v;
1036  }
1037 
1038  static bool
1039  result_callback (void* context,
1040  ub4* position_context,
1041  void* buffer,
1042  ub4 size,
1043  chunk_position);
1044 
1045  static bool
1046  param_callback (const void* context,
1047  ub4* position_context,
1048  const void** buffer,
1049  ub4* size,
1050  chunk_position*,
1051  void* temp_buffer,
1052  ub4 capacity);
1053  };
1054 
1055  // std::vector<unsigned char> (buffer) specialization for BLOBs.
1056  //
1057  template <>
1058  struct LIBODB_ORACLE_EXPORT
1059  default_value_traits<std::vector<unsigned char>, id_blob>
1060  {
1061  public:
1062  typedef std::vector<unsigned char> value_type;
1063  typedef std::vector<unsigned char> query_type;
1065 
1066  static void
1069  void*& context,
1070  bool is_null)
1071  {
1072  if (!is_null)
1073  {
1074  cb = &result_callback;
1075  context = &v;
1076  }
1077  else
1078  v.clear ();
1079  }
1080 
1081  static void
1083  const void*& context,
1084  bool& is_null,
1085  const value_type& v)
1086  {
1087  is_null = false;
1088  cb = &param_callback;
1089  context = &v;
1090  }
1091 
1092  static bool
1093  result_callback (void* context,
1094  ub4* position_context,
1095  void* buffer,
1096  ub4 size,
1097  chunk_position);
1098 
1099  static bool
1100  param_callback (const void* context,
1101  ub4* position_context,
1102  const void** buffer,
1103  ub4* size,
1104  chunk_position*,
1105  void* temp_buffer,
1106  ub4 capacity);
1107  };
1108 
1109  // char[N] (buffer) specialization for BLOBs.
1110  //
1111  template <std::size_t N>
1113  {
1114  public:
1115  typedef char* value_type;
1116  typedef char query_type[N];
1118 
1119  static void
1120  set_value (char* const& v,
1122  void*& context,
1123  bool is_null)
1124  {
1125  if (!is_null)
1126  {
1127  cb = &result_callback;
1128  context = v;
1129  }
1130  else
1131  std::memset (v, 0, N);
1132  }
1133 
1134  static void
1136  const void*& context,
1137  bool& is_null,
1138  const char* v)
1139  {
1140  is_null = false;
1141  cb = &param_callback;
1142  context = v;
1143  }
1144 
1145  static bool
1146  result_callback (void* context,
1147  ub4* position_context,
1148  void* buffer,
1149  ub4 size,
1150  chunk_position);
1151 
1152  static bool
1153  param_callback (const void* context,
1154  ub4* position_context,
1155  const void** buffer,
1156  ub4* size,
1157  chunk_position*,
1158  void* temp_buffer,
1159  ub4 capacity);
1160  };
1161 
1162  // unsigned char[N] (buffer) specialization for BLOBs.
1163  //
1164  template <std::size_t N>
1165  struct default_value_traits<unsigned char[N], id_blob>
1166  {
1167  public:
1168  typedef unsigned char* value_type;
1169  typedef unsigned char query_type[N];
1171 
1172  static void
1173  set_value (unsigned char* const& v,
1175  void*& context,
1176  bool is_null)
1177  {
1178  if (!is_null)
1179  {
1180  cb = &result_callback;
1181  context = v;
1182  }
1183  else
1184  std::memset (v, 0, N);
1185  }
1186 
1187  static void
1189  const void*& context,
1190  bool& is_null,
1191  const unsigned char* v)
1192  {
1193  is_null = false;
1194  cb = &param_callback;
1195  context = v;
1196  }
1197 
1198  static bool
1199  result_callback (void* context,
1200  ub4* position_context,
1201  void* buffer,
1202  ub4 size,
1203  chunk_position);
1204 
1205  static bool
1206  param_callback (const void* context,
1207  ub4* position_context,
1208  const void** buffer,
1209  ub4* size,
1210  chunk_position*,
1211  void* temp_buffer,
1212  ub4 capacity);
1213  };
1214 
1215 #ifdef ODB_CXX11
1216  // std::array<char, N> (buffer) specialization for BLOBS.
1217  //
1218  template <std::size_t N>
1219  struct default_value_traits<std::array<char, N>, id_blob>
1220  {
1221  public:
1222  typedef std::array<char, N> value_type;
1223  typedef value_type query_type;
1224  typedef lob_callback image_type;
1225 
1226  static void
1227  set_value (value_type& v,
1229  void*& context,
1230  bool is_null)
1231  {
1232  if (!is_null)
1233  {
1234  cb = &result_callback;
1235  context = v.data ();
1236  }
1237  else
1238  std::memset (v.data (), 0, N);
1239  }
1240 
1241  static void
1243  const void*& context,
1244  bool& is_null,
1245  const value_type& v)
1246  {
1247  is_null = false;
1248  cb = &param_callback;
1249  context = v.data ();
1250  }
1251 
1252  static bool
1253  result_callback (void* context,
1254  ub4* position_context,
1255  void* buffer,
1256  ub4 size,
1257  chunk_position);
1258 
1259  static bool
1260  param_callback (const void* context,
1261  ub4* position_context,
1262  const void** buffer,
1263  ub4* size,
1264  chunk_position*,
1265  void* temp_buffer,
1266  ub4 capacity);
1267  };
1268 
1269  // std::array<unsigned char, N> (buffer) specialization for BLOBS.
1270  //
1271  template <std::size_t N>
1272  struct default_value_traits<std::array<unsigned char, N>, id_blob>
1273  {
1274  public:
1275  typedef std::array<unsigned char, N> value_type;
1276  typedef value_type query_type;
1277  typedef lob_callback image_type;
1278 
1279  static void
1280  set_value (value_type& v,
1282  void*& context,
1283  bool is_null)
1284  {
1285  if (!is_null)
1286  {
1287  cb = &result_callback;
1288  context = v.data ();
1289  }
1290  else
1291  std::memset (v.data (), 0, N);
1292  }
1293 
1294  static void
1296  const void*& context,
1297  bool& is_null,
1298  const value_type& v)
1299  {
1300  is_null = false;
1301  cb = &param_callback;
1302  context = v.data ();
1303  }
1304 
1305  static bool
1306  result_callback (void* context,
1307  ub4* position_context,
1308  void* buffer,
1309  ub4 size,
1310  chunk_position);
1311 
1312  static bool
1313  param_callback (const void* context,
1314  ub4* position_context,
1315  const void** buffer,
1316  ub4* size,
1317  chunk_position*,
1318  void* temp_buffer,
1319  ub4 capacity);
1320  };
1321 #endif
1322 
1323  //
1324  // type_traits
1325  //
1326 
1327  template <typename T>
1329 
1330  template <typename T>
1332  {
1333  };
1334 
1335  // Integral types.
1336  //
1337  template <>
1338  struct default_type_traits<bool>
1339  {
1340  static const database_type_id db_type_id = id_int32;
1341  };
1342 
1343  template <>
1344  struct default_type_traits<signed char>
1345  {
1346  static const database_type_id db_type_id = id_int32;
1347  };
1348 
1349  template <>
1350  struct default_type_traits<unsigned char>
1351  {
1352  static const database_type_id db_type_id = id_int32;
1353  };
1354 
1355  template <>
1356  struct default_type_traits<short>
1357  {
1358  static const database_type_id db_type_id = id_int32;
1359  };
1360 
1361  template <>
1362  struct default_type_traits<unsigned short>
1363  {
1364  static const database_type_id db_type_id = id_int32;
1365  };
1366 
1367  template <>
1369  {
1370  static const database_type_id db_type_id = id_int32;
1371  };
1372 
1373  template <>
1374  struct default_type_traits<unsigned int>
1375  {
1376  static const database_type_id db_type_id = id_int32;
1377  };
1378 
1379  template <>
1380  struct default_type_traits<long>
1381  {
1382  static const database_type_id db_type_id = id_big_int;
1383  };
1384 
1385  template <>
1386  struct default_type_traits<unsigned long>
1387  {
1388  static const database_type_id db_type_id = id_big_int;
1389  };
1390 
1391  template <>
1392  struct default_type_traits<long long>
1393  {
1394  static const database_type_id db_type_id = id_big_int;
1395  };
1396 
1397  template <>
1398  struct default_type_traits<unsigned long long>
1399  {
1400  static const database_type_id db_type_id = id_big_int;
1401  };
1402 
1403  // Float types.
1404  //
1405  template <>
1406  struct default_type_traits<float>
1407  {
1408  static const database_type_id db_type_id = id_float;
1409  };
1410 
1411  template <>
1412  struct default_type_traits<double>
1413  {
1414  static const database_type_id db_type_id = id_double;
1415  };
1416 
1417  // String types.
1418  //
1419  template <>
1420  struct default_type_traits<std::string>
1421  {
1422  static const database_type_id db_type_id = id_string;
1423  };
1424 
1425  template <>
1426  struct default_type_traits<char*>
1427  {
1428  static const database_type_id db_type_id = id_string;
1429  };
1430 
1431  template <>
1432  struct default_type_traits<const char*>
1433  {
1434  static const database_type_id db_type_id = id_string;
1435  };
1436 
1437  template <std::size_t N>
1438  struct default_type_traits<char[N]>
1439  {
1440  static const database_type_id db_type_id = id_string;
1441  };
1442 
1443 #ifdef ODB_CXX11
1444  template <std::size_t N>
1445  struct default_type_traits<std::array<char, N> >
1446  {
1447  static const database_type_id db_type_id = id_string;
1448  };
1449 #endif
1450 
1451  template <>
1452  struct default_type_traits<char>
1453  {
1454  static const database_type_id db_type_id = id_string;
1455  };
1456 
1457  // Binary types. Assume RAW since LOBs cannot be compared in
1458  // Oracle and this is only used in queries.
1459  //
1460  template <std::size_t N>
1461  struct default_type_traits<unsigned char[N]>
1462  {
1463  static const database_type_id db_type_id = id_raw;
1464  };
1465 
1466  template <>
1467  struct default_type_traits<std::vector<char> >
1468  {
1469  static const database_type_id db_type_id = id_raw;
1470  };
1471 
1472  template <>
1473  struct default_type_traits<std::vector<unsigned char> >
1474  {
1475  static const database_type_id db_type_id = id_raw;
1476  };
1477 
1478 #ifdef ODB_CXX11
1479  template <std::size_t N>
1480  struct default_type_traits<std::array<unsigned char, N> >
1481  {
1482  static const database_type_id db_type_id = id_raw;
1483  };
1484 #endif
1485  }
1486 }
1487 
1488 #include <odb/oracle/traits.txx>
1489 
1490 #include <odb/post.hxx>
1491 
1492 #endif // ODB_ORACLE_TRAITS_HXX
static void set_image(char *b, std::size_t &n, bool &is_null, T v)
Definition: traits.hxx:482
Definition: oracle-types.hxx:92
Definition: traits.hxx:60
Definition: traits.hxx:251
Definition: traits.hxx:109
char * image_type
Definition: traits.hxx:175
static void set_image(param_callback_type &cb, const void *&context, bool &is_null, const value_type &v)
Definition: traits.hxx:1082
static void set_image(char *b, std::size_t c, std::size_t &n, bool &is_null, const value_type &v)
Definition: traits.hxx:745
Definition: oracle-types.hxx:63
char * image_type
Definition: traits.hxx:161
buffer_type
Definition: oracle-types.hxx:90
static void set_image(param_callback_type &cb, const void *&context, bool &is_null, const W &v)
Definition: traits.hxx:320
bool(* result_callback_type)(void *context, ub4 *position_context, void *buffer, ub4 size, chunk_position)
Definition: oracle-types.hxx:53
static void set_image(char *b, std::size_t c, std::size_t &n, bool &is_null, const char *v)
Definition: traits.hxx:825
lob_callback image_type
Definition: traits.hxx:944
chunk_position
Definition: oracle-types.hxx:22
std::string value_type
Definition: traits.hxx:503
Definition: traits.hxx:42
static void set_image(char *i, std::size_t &n, bool &is_null, const W &v)
Definition: traits.hxx:388
std::vector< char > query_type
Definition: traits.hxx:732
T value_type
Definition: traits.hxx:423
wtraits::unrestricted_wrapped_type wrapped_type
Definition: traits.hxx:333
double image_type
Definition: traits.hxx:168
char * value_type
Definition: traits.hxx:1115
wrapper_traits< W > wtraits
Definition: traits.hxx:332
lob_callback image_type
Definition: traits.hxx:221
static const bool unsign
Definition: traits.hxx:81
Definition: oracle-types.hxx:93
database_type_id
Definition: traits.hxx:37
Definition: traits.hxx:555
char * image_type
Definition: traits.hxx:813
Definition: traits.hxx:40
Definition: traits.hxx:939
image_traits< T, ID >::image_type image_type
Definition: traits.hxx:425
image_traits< wrapped_type, ID >::image_type image_type
Definition: traits.hxx:337
lob_callback image_type
Definition: traits.hxx:1170
wrapped_type query_type
Definition: traits.hxx:336
static void set_value(unsigned char *const &v, const char *b, std::size_t n, bool is_null)
Definition: traits.hxx:847
static void set_image(char *b, std::size_t &n, bool &is_null, T v)
Definition: traits.hxx:462
lob_callback image_type
Definition: traits.hxx:1117
static void set_image(char *i, std::size_t c, std::size_t &n, bool &is_null, const W &v)
Definition: traits.hxx:294
char * image_type
Definition: traits.hxx:206
details::buffer image_type
Definition: traits.hxx:620
unsigned int ub4
Definition: oracle-fwd.hxx:20
default_value_traits< T, ID > type
Definition: traits.hxx:239
static void set_value(unsigned char *const &v, result_callback_type &cb, void *&context, bool is_null)
Definition: traits.hxx:1173
static void set_value(W &v, const char *i, std::size_t n, bool is_null)
Definition: traits.hxx:362
static void set_image(char *b, std::size_t c, std::size_t &n, bool &is_null, const char *v, std::size_t N)
unsigned char * value_type
Definition: traits.hxx:842
char * image_type
Definition: traits.hxx:559
char value_type
Definition: traits.hxx:693
static void set_value(value_type &v, result_callback_type &cb, void *&context, bool is_null)
Definition: traits.hxx:1013
static void set_value(std::string &v, const char *b, std::size_t n, bool is_null)
Definition: traits.hxx:508
unsigned char * value_type
Definition: traits.hxx:1168
static void set_value(char *const &v, result_callback_type &cb, void *&context, bool is_null)
Definition: traits.hxx:1120
std::vector< unsigned char > value_type
Definition: traits.hxx:1062
Definition: traits.hxx:63
char * image_type
Definition: traits.hxx:505
Definition: traits.hxx:54
wrapped_value_traits< W, ID, wrapper_traits< W >::null_handler > type
Definition: traits.hxx:247
static void set_value(char *const &v, const char *b, std::size_t n, bool is_null)
Definition: traits.hxx:816
float image_type
Definition: traits.hxx:165
static void set_image(param_callback_type &cb, const void *&context, bool &is_null, const value_type &v)
Definition: traits.hxx:1028
unsigned int image_type
Definition: traits.hxx:122
static void set_image(image_type &i, bool &is_null, T v)
Definition: traits.hxx:437
Definition: traits.hxx:45
static void set_value(T &v, const image_type &i, bool is_null)
Definition: traits.hxx:428
interval_ym image_type
Definition: traits.hxx:196
lob_callback image_type
Definition: traits.hxx:218
char * image_type
Definition: traits.hxx:209
static void set_image(char *b, std::size_t c, std::size_t &n, bool &is_null, const unsigned char *v)
Definition: traits.hxx:859
Definition: traits.hxx:1331
static void set_image(char *b, std::size_t c, std::size_t &n, bool &is_null, const char *v)
Definition: traits.hxx:632
static void set_image(image_type &i, bool &is_null, const W &v)
Definition: traits.hxx:278
static void set_value(T &v, const char *b, std::size_t n, bool is_null)
Definition: traits.hxx:453
static void set_value(W &v, result_callback_type &cb, void *&context, bool is_null)
Definition: traits.hxx:399
T query_type
Definition: traits.hxx:424
Definition: traits.hxx:53
Definition: traits.hxx:447
Definition: traits.hxx:57
static void set_value(char &v, const char *b, std::size_t n, bool is_null)
Definition: traits.hxx:698
std::vector< unsigned char > query_type
Definition: traits.hxx:1063
Definition: traits.hxx:597
Definition: traits.hxx:228
static void set_image(char *b, std::size_t c, std::size_t &n, bool &is_null, const std::string &v)
Definition: traits.hxx:520
wtraits::unrestricted_wrapped_type wrapped_type
Definition: traits.hxx:263
static void set_image(param_callback_type &cb, const void *&context, bool &is_null, const std::string &v)
Definition: traits.hxx:962
static void set_value(value_type &v, const char *b, std::size_t n, bool is_null)
Definition: traits.hxx:775
unsigned long long image_type
Definition: traits.hxx:146
static void set_value(char *const &v, const char *b, std::size_t n, bool is_null, std::size_t N)
Definition: traits.hxx:39
Definition: traits.hxx:62
char * value_type
Definition: traits.hxx:811
static void set_image(param_callback_type &cb, const void *&context, bool &is_null, const W &v)
Definition: traits.hxx:408
Definition: oracle-types.hxx:174
static void set_value(std::string &v, result_callback_type &cb, void *&context, bool is_null)
Definition: traits.hxx:947
std::vector< char > query_type
Definition: traits.hxx:1009
int image_type
Definition: traits.hxx:115
static void set_value(W &v, const image_type &i, bool is_null)
Definition: traits.hxx:342
static void set_image(image_type &i, bool &is_null, const W &v)
Definition: traits.hxx:351
wrapped_type query_type
Definition: traits.hxx:266
std::vector< unsigned char > value_type
Definition: traits.hxx:770
long long image_type
Definition: traits.hxx:139
static void set_value(char *const &v, const char *b, std::size_t n, bool is_null)
Definition: traits.hxx:623
static void set_value(W &v, const image_type &i, bool is_null)
Definition: traits.hxx:272
static void set_image(char *b, std::size_t c, std::size_t &n, bool &is_null, const char *v)
Definition: traits.hxx:562
static void set_value(W &v, const char *i, std::size_t n, bool is_null)
Definition: traits.hxx:286
Definition: traits.hxx:231
std::vector< unsigned char > query_type
Definition: traits.hxx:771
char * image_type
Definition: traits.hxx:212
Definition: traits.hxx:44
value_traits< wrapped_type, ID > vtraits
Definition: traits.hxx:269
Definition: traits.hxx:1328
Definition: traits.hxx:55
static void set_image(char *i, std::size_t c, std::size_t &n, bool &is_null, const W &v)
Definition: traits.hxx:373
Definition: oracle-types.hxx:253
image_traits< wrapped_type, ID >::image_type image_type
Definition: traits.hxx:267
Definition: traits.hxx:133
std::string query_type
Definition: traits.hxx:943
static void set_value(W &v, result_callback_type &cb, void *&context, bool is_null)
Definition: traits.hxx:314
Definition: traits.hxx:64
char query_type
Definition: traits.hxx:694
char * image_type
Definition: traits.hxx:184
static void set_image(char *b, std::size_t c, std::size_t &n, bool &is_null, const value_type &v)
Definition: traits.hxx:787
Definition: oracle-types.hxx:222
Definition: traits.hxx:50
static void set_image(param_callback_type &cb, const void *&context, bool &is_null, const unsigned char *v)
Definition: traits.hxx:1188
static void set_value(value_type &v, const char *b, std::size_t n, bool is_null)
Definition: traits.hxx:736
static void set_image(char *b, std::size_t c, std::size_t &n, bool &is_null, char v)
Definition: traits.hxx:707
const char * value_type
Definition: traits.hxx:558
std::string query_type
Definition: traits.hxx:504
char query_type[N]
Definition: traits.hxx:619
datetime image_type
Definition: traits.hxx:190
Definition: traits.hxx:616
wrapper_traits< W > wtraits
Definition: traits.hxx:262
value_traits< wrapped_type, ID > vtraits
Definition: traits.hxx:339
interval_ds image_type
Definition: traits.hxx:202
char * value_type
Definition: traits.hxx:618
Definition: traits.hxx:500
Definition: traits.hxx:104
std::string value_type
Definition: traits.hxx:942
image_traits< T, id_big_int >::image_type image_type
Definition: traits.hxx:495
Definition: traits.hxx:52
static void set_value(value_type &v, result_callback_type &cb, void *&context, bool is_null)
Definition: traits.hxx:1067
Definition: traits.hxx:58
bool(* param_callback_type)(const void *context, ub4 *position_context, const void **buffer, ub4 *size, chunk_position *, void *temp_buffer, ub4 capacity)
Definition: oracle-types.hxx:34
Definition: traits.hxx:691
static void set_value(T &v, const char *b, std::size_t n, bool is_null)
Definition: traits.hxx:473
Definition: traits.hxx:81
details::buffer image_type
Definition: traits.hxx:695
std::vector< char > value_type
Definition: traits.hxx:1008
Definition: traits.hxx:234
std::vector< char > value_type
Definition: traits.hxx:731
static void set_image(char *i, std::size_t &n, bool &is_null, const W &v)
Definition: traits.hxx:306
static void set_image(param_callback_type &cb, const void *&context, bool &is_null, const char *v)
Definition: traits.hxx:1135
lob_callback image_type
Definition: traits.hxx:215