OCILIB (C and C++ Driver for Oracle)  4.7.5
Open source and cross platform Oracle Driver delivering efficient access to Oracle databases.
Loading...
Searching...
No Matches
support.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-2023 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/core.hpp"
24
25// ReSharper disable CppClangTidyModernizeUseNodiscard
26// ReSharper disable CppClangTidyHicppUseEqualsDefault
27// ReSharper disable CppClangTidyHicppSpecialMemberFunctions
28// ReSharper disable CppClangTidyCppcoreguidelinesSpecialMemberFunctions
29// ReSharper disable CppClangTidyModernizePassByValue
30
31namespace ocilib
32{
39 namespace support
40 {
45 template<class T> struct BindResolver {};
46
52 {
53 public:
54
55 BindObject(const ocilib::Statement& statement, const ostring& name, unsigned int mode);
56
57 virtual ~BindObject() noexcept;
58
59 ostring GetName() const;
60
61 ocilib::Statement GetStatement() const;
62
63 unsigned int GetMode() const;
64
65 virtual void SetInData() = 0;
66 virtual void SetOutData() = 0;
67
68 protected:
69
70 const ocilib::Statement& _statement;
71 ostring _name;
72 unsigned int _mode;
73 };
74
79 class BindArray : public BindObject
80 {
81 public:
82
83 BindArray(const ocilib::Statement& statement, const ostring& name, unsigned int mode);
84 virtual ~BindArray() noexcept;
85
86 template<class T>
87 void SetVector(std::vector<T>& vector, bool isPlSqlTable, unsigned int elemSize);
88
89 template<class T>
90 typename BindResolver<T>::OutputType* GetData() const;
91
92 void SetInData() override;
93 void SetOutData() override;
94
95 unsigned int GetSize() const;
96 unsigned int GetSizeForBindCall() const;
97
98 private:
99
100 class AbstractBindArrayObject
101 {
102 public:
103 virtual ~AbstractBindArrayObject() {};
104 virtual void SetInData() = 0;
105 virtual void SetOutData() = 0;
106 virtual ostring GetName() const = 0;
107 virtual bool IsHandleObject() const = 0;
108 virtual unsigned int GetSize() const = 0;
109 virtual unsigned int GetSizeForBindCall() const = 0;
110 };
111
112 template<class T>
113 class BindArrayObject : public AbstractBindArrayObject
114 {
115 public:
116
117 typedef T ObjectType;
118 typedef std::vector<ObjectType> ObjectVector;
119 typedef typename BindResolver<ObjectType>::OutputType NativeType;
120
121 BindArrayObject(const ocilib::Statement& statement, const ostring& name, ObjectVector& vector, bool isPlSqlTable, unsigned int mode, unsigned int elemSize);
122 virtual ~BindArrayObject() noexcept;
123 void SetInData() override;
124 void SetOutData() override;
125 ostring GetName()const override;
126 bool IsHandleObject() const override;
127 unsigned int GetSize() const override;
128 unsigned int GetSizeForBindCall() const override;
129
130 operator ObjectVector& () const;
131 operator NativeType* () const;
132
133 private:
134
135 void AllocData();
136 void FreeData() const;
137
138 const ocilib::Statement& _statement;
139 ostring _name;
140 ObjectVector& _vector;
141 NativeType* _data;
142 bool _isPlSqlTable;
143 unsigned int _mode;
144 unsigned int _elemCount;
145 unsigned int _elemSize;
146 };
147
148 AbstractBindArrayObject* _object;
149 };
150
155 template<class T>
157 {
158 friend class ocilib::Statement;
159
160 public:
161
162 typedef T ObjectType;
163 typedef typename BindResolver<ObjectType>::OutputType NativeType;
164
165 operator NativeType* () const;
166
167 void SetInData() override;
168 void SetOutData() override;
169
170 BindObjectAdaptor(const ocilib::Statement& statement, const ostring& name, unsigned int mode, ObjectType& object, unsigned int size);
171 virtual ~BindObjectAdaptor() noexcept;
172
173 private:
174
175 ObjectType& _object;
176 NativeType* _data;
177 unsigned int _size;
178 };
179
184 template<class T>
186 {
187 friend class ocilib::Statement;
188
189 public:
190
191 typedef T ObjectType;
192 typedef typename BindResolver<ObjectType>::OutputType NativeType;
193
194 operator NativeType* () const;
195
196 void SetInData() override;
197 void SetOutData() override;
198
199 BindTypeAdaptor(const Statement& statement, const ostring& name, unsigned int mode, ObjectType& object);
200 virtual ~BindTypeAdaptor() noexcept;
201
202 private:
203
204 ObjectType& _object;
205 NativeType* _data;
206 };
207
213 {
214 public:
215
216 BindsHolder(const ocilib::Statement& statement);
217 ~BindsHolder() noexcept;
218
219 void Clear();
220
221 void AddBindObject(BindObject* bindObject);
222
223 void SetOutData();
224 void SetInData();
225
226 private:
227
228 std::vector<BindObject*> _bindObjects;
229 const ocilib::Statement& _statement;
230 };
231 }
232}
Object used for executing SQL or PL/SQL statement and returning the produced results.
Definition: types.hpp:5556
Internal usage. Class implementing bind translations between C++ vectors and C API arrays.
Definition: support.hpp:80
Internal usage. Class implementing bind adapters between C++ class and C API types.
Definition: support.hpp:157
Internal usage. Base class for implementing bind translations for C++ objects and their counter parts...
Definition: support.hpp:52
Internal usage. Class implementing bind adapters between C++ types and C API types when C++ types do ...
Definition: support.hpp:186
Internal usage. Class owning bind objects allowing to set/get C data prior/after a statement executio...
Definition: support.hpp:213
OCILIB ++ Namespace.
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
Internal usage. Allow resolving a native type used by C API from a C++ type in binding operations.
Definition: support.hpp:45