OCILIB (C and C++ Driver for Oracle)  4.7.3
Open source and cross platform Oracle Driver delivering efficient access to Oracle databases.
Long.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/types.hpp"
24 
25 namespace ocilib
26 {
27 
28 template<class T, int U>
30 {
31 }
32 
33 template<class T, int U>
34 Long<T, U>::Long(const Statement &statement)
35 {
36  Acquire(core::Check(OCI_LongCreate(statement, U)), reinterpret_cast<HandleFreeFunc>(OCI_LongFree), nullptr, statement.GetHandle());
37 }
38 
39 template<class T, int U>
40 Long<T, U>::Long(OCI_Long *pLong, core::Handle* parent)
41 {
42  Acquire(pLong, nullptr, nullptr, parent);
43 }
44 
45 template<class T, int U>
46 unsigned int Long<T, U>::Write(const T& content)
47 {
48  if (content.empty())
49  {
50  return 0;
51  }
52 
53  return core::Check(OCI_LongWrite(*this, static_cast<AnyPointer>(const_cast<typename T::value_type*>(&content[0])), static_cast<unsigned int>(content.size())));
54 }
55 
56 template<class T, int U>
57 unsigned int Long<T, U>::GetLength() const
58 {
59  return core::Check(OCI_LongGetSize(*this));
60 }
61 
62 template<>
64 {
65  return core::MakeString(static_cast<const otext *>(core::Check(OCI_LongGetBuffer(*this))));
66 }
67 
68 template<>
70 {
71  return core::MakeRaw(core::Check(OCI_LongGetBuffer(*this)), GetLength());
72 }
73 
74 }
Internal usage. Interface for handling ownership and relationship of a C API handle.
Definition: core.hpp:312
OCILIB ++ Namespace.
OCI_SYM_PUBLIC unsigned int OCI_API OCI_LongGetSize(OCI_Long *lg)
Return the buffer size of a long object in bytes (OCI_BLONG) or character (OCI_CLONG) ...
Raw MakeRaw(AnyPointer result, unsigned int size)
Internal usage. Constructs a C++ Raw object from the given OCILIB raw buffer.
Definition: Utils.hpp:70
Object used for executing SQL or PL/SQL statement and returning the produced results.
Definition: types.hpp:5536
static T Check(T result)
Internal usage. Checks if the last OCILIB function call has raised an error. If so, it raises a C++ exception using the retrieved error handle.
Definition: Utils.hpp:53
OCI_SYM_PUBLIC OCI_Long *OCI_API OCI_LongCreate(OCI_Statement *stmt, unsigned int type)
Create a local temporary Long instance.
Long()
Create an empty null Long instance.
Definition: Long.hpp:29
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
T GetContent() const
Return the string read from a fetch sequence.
unsigned int GetLength() const
Return the buffer length.
Definition: Long.hpp:57
OCI_SYM_PUBLIC void *OCI_API OCI_LongGetBuffer(OCI_Long *lg)
Return the internal buffer of an OCI_Long object read from a fetch sequence.
unsigned int Write(const T &content)
Write the given string into the long Object.
Definition: Long.hpp:46
OCI_SYM_PUBLIC boolean OCI_API OCI_LongFree(OCI_Long *lg)
Free a local temporary long.
std::vector< unsigned char > Raw
C++ counterpart of SQL RAW data type.
Definition: config.hpp:138
struct OCI_Long OCI_Long
Oracle Long data type.
Definition: types.h:248
OCI_SYM_PUBLIC unsigned int OCI_API OCI_LongWrite(OCI_Long *lg, void *buffer, unsigned int len)
Write a buffer into a Long.
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