OCILIB (C and C++ Driver for Oracle)  4.7.3
Open source and cross platform Oracle Driver delivering efficient access to Oracle databases.
BindTypeAdaptor.hpp
1 /*
2  * OCILIB - C Driver for Oracle (C Wrapper for Oracle OCI)
3  *
4  * Website: http://www.ocilib.net
5  *
6  * Copyright (c) 2007-2021 Vincent ROGIER <vince.rogier@ocilib.net>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #pragma once
22 
23 #include "ocilibcpp/support.hpp"
24 
25 namespace ocilib
26 {
27  namespace support
28  {
29  template<class T>
30  void BindTypeAdaptor<T>::SetInData()
31  {
32  if (GetMode() & OCI_BDM_IN)
33  {
34  *_data = static_cast<NativeType>(_object);
35  }
36  }
37 
38  template<class T>
39  void BindTypeAdaptor<T>::SetOutData()
40  {
41  if (GetMode() & OCI_BDM_OUT)
42  {
43  _object = static_cast<T&>(*_data);
44  }
45  }
46 
47  template<class T>
48  BindTypeAdaptor<T>::BindTypeAdaptor(const ocilib::Statement& statement, const ostring& name, unsigned int mode, ObjectType& object) :
49  BindObject(statement, name, mode),
50  _object(object),
51  _data(core::OnAllocate(new NativeType))
52  {
53 
54  }
55 
56  template<class T>
57  BindTypeAdaptor<T>::~BindTypeAdaptor() noexcept
58  {
59  delete core::OnDeallocate(_data);
60  }
61 
62  template<class T>
63  BindTypeAdaptor<T>::operator NativeType* () const
64  {
65  return _data;
66  }
67 
68  template<>
69  inline void BindTypeAdaptor<bool>::SetInData()
70  {
71  if (GetMode() & OCI_BDM_IN)
72  {
73  *_data = (_object == true);
74  }
75  }
76 
77  template<>
78  inline void BindTypeAdaptor<bool>::SetOutData()
79  {
80  if (GetMode() & OCI_BDM_OUT)
81  {
82  _object = (*_data == TRUE);
83  }
84  }
85  }
86 }
OCILIB ++ Namespace.
Object used for executing SQL or PL/SQL statement and returning the produced results.
Definition: types.hpp:5536
std::basic_string< otext, std::char_traits< otext >, std::allocator< otext > > ostring
string class wrapping the OCILIB otext * type and OTEXT() macros ( see Character sets ) ...
Definition: config.hpp:120