OCILIB (C and C++ Driver for Oracle)  4.7.6
Open source and cross platform Oracle Driver delivering efficient access to Oracle databases.
Reference.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/types.hpp"
24 
25 // ReSharper disable CppClangTidyHicppUseEqualsDefault
26 // ReSharper disable CppClangTidyModernizeUseEqualsDefault
27 
28 namespace ocilib
29 {
30 
32 {
33 }
34 
35 inline Reference::Reference(const TypeInfo &typeInfo)
36 {
37  Connection connection = typeInfo.GetConnection();
38  AcquireAllocated
39  (
40  core::Check(OCI_RefCreate(connection, typeInfo)),
41  connection.GetHandle()
42  );
43 }
44 
45 inline Reference::Reference(OCI_Ref *pRef, core::Handle *parent)
46 {
47  AcquireTransient(pRef, parent);
48 }
49 
51 {
52  OCI_TypeInfo* typeInfo = core::Check(OCI_RefGetTypeInfo(*this));
53 
54  Connection connection
55  (
57  Environment::GetEnvironmentHandle()
58  );
59 
60  return TypeInfo(typeInfo, connection.GetHandle());
61 }
62 
64 {
65  return Object(core::Check(OCI_RefGetObject(*this)), GetHandle());
66 }
67 
69 {
70  Reference result(GetTypeInfo());
71 
72  core::Check(OCI_RefAssign(result, *this));
73 
74  return result;
75 }
76 
77 inline bool Reference::IsReferenceNull() const
78 {
79  return (core::Check(OCI_RefIsNull(*this)) == TRUE);
80 }
81 
83 {
85 }
86 
88 {
89  if (!IsNull())
90  {
91  const unsigned int size = core::Check(OCI_RefGetHexSize(*this));
92 
93  core::ManagedBuffer<otext> buffer(static_cast<size_t>(size + 1));
94 
95  core::Check(OCI_RefToText(*this, size, buffer));
96 
97  return core::MakeString(static_cast<const otext *>(buffer), static_cast<int>(size));
98  }
99 
100  return OCI_STRING_NULL;
101 }
102 
103 }
A connection or session with a specific database.
Definition: types.hpp:1580
Object identifying the SQL data type OBJECT.
Definition: types.hpp:4668
Object identifying the SQL data type REF.
Definition: types.hpp:4848
Reference Clone() const
Clone the current instance to a new one performing deep copy.
Definition: Reference.hpp:68
Reference()
Create an empty null Reference instance.
Definition: Reference.hpp:31
TypeInfo GetTypeInfo() const
Return the TypeInfo object describing the referenced object.
Definition: Reference.hpp:50
ostring ToString() const override
return a string representation of the current reference
Definition: Reference.hpp:87
void SetReferenceNull()
Nullify the given Ref handle.
Definition: Reference.hpp:82
bool IsReferenceNull() const
Check if the reference points to an object or not.
Definition: Reference.hpp:77
Object GetObject() const
Returns the object pointed by the reference.
Definition: Reference.hpp:63
Provides type information on Oracle Database objects.
Definition: types.hpp:4531
Connection GetConnection() const
Return the connection associated with a statement.
Definition: TypeInfo.hpp:52
Internal usage. Interface for handling ownership and relationship of a C API handle.
Definition: core.hpp:325
Internal usage. Provide a buffer class with RAII capabilities.
Definition: core.hpp:197
struct OCI_Ref OCI_Ref
Oracle REF type representation.
Definition: types.h:356
struct OCI_TypeInfo OCI_TypeInfo
Type info metadata handle.
Definition: types.h:366
OCI_SYM_PUBLIC OCI_Connection *OCI_API OCI_TypeInfoGetConnection(OCI_TypeInfo *typinf)
Retrieve connection handle from the type info handle.
OCI_SYM_PUBLIC boolean OCI_API OCI_RefIsNull(OCI_Ref *ref)
Check if the Ref points to an object or not.
OCI_SYM_PUBLIC OCI_Object *OCI_API OCI_RefGetObject(OCI_Ref *ref)
Returns the object pointed by the Ref handle.
OCI_SYM_PUBLIC OCI_Ref *OCI_API OCI_RefCreate(OCI_Connection *con, OCI_TypeInfo *typinf)
Create a local Ref instance.
OCI_SYM_PUBLIC OCI_TypeInfo *OCI_API OCI_RefGetTypeInfo(OCI_Ref *ref)
Return the type info object associated to the Ref.
OCI_SYM_PUBLIC boolean OCI_API OCI_RefAssign(OCI_Ref *ref, OCI_Ref *ref_src)
Assign a Ref to another one.
OCI_SYM_PUBLIC unsigned int OCI_API OCI_RefGetHexSize(OCI_Ref *ref)
Returns the size of the hex representation of the given Ref handle.
OCI_SYM_PUBLIC boolean OCI_API OCI_RefSetNull(OCI_Ref *ref)
Nullify the given Ref handle.
OCI_SYM_PUBLIC boolean OCI_API OCI_RefToText(OCI_Ref *ref, unsigned int size, otext *str)
Converts a Ref handle value to a hexadecimal string.
static T Check(T result)
Internal usage. Checks if the last OCILIB function call has raised an error. If so,...
Definition: Utils.hpp:53
ostring MakeString(const otext *result, int size=-1)
Internal usage. Constructs a C++ string object from the given OCILIB string pointer.
Definition: Utils.hpp:65
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