OCILIB (C and C++ Driver for Oracle)  4.7.6
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-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 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  AcquireAllocated
37  (
38  core::Check(OCI_LongCreate(statement, U)),
39  statement.GetHandle()
40  );
41 }
42 
43 template<class T, int U>
44 Long<T, U>::Long(OCI_Long *pLong, core::Handle* parent)
45 {
46  AcquireTransient(pLong, parent);
47 }
48 
49 template<class T, int U>
50 unsigned int Long<T, U>::Write(const T& content)
51 {
52  if (content.empty())
53  {
54  return 0;
55  }
56 
57  return core::Check(OCI_LongWrite(*this, static_cast<AnyPointer>(const_cast<typename T::value_type*>(&content[0])), static_cast<unsigned int>(content.size())));
58 }
59 
60 template<class T, int U>
61 unsigned int Long<T, U>::GetLength() const
62 {
63  return core::Check(OCI_LongGetSize(*this));
64 }
65 
66 template<>
68 {
69  return core::MakeString(static_cast<const otext *>(core::Check(OCI_LongGetBuffer(*this))));
70 }
71 
72 template<>
74 {
75  return core::MakeRaw(core::Check(OCI_LongGetBuffer(*this)), GetLength());
76 }
77 
78 }
Long()
Create an empty null Long instance.
Definition: Long.hpp:29
unsigned int Write(const T &content)
Write the given string into the long Object.
Definition: Long.hpp:50
unsigned int GetLength() const
Return the buffer length.
Definition: Long.hpp:61
T GetContent() const
Return the string read from a fetch sequence.
Object used for executing SQL or PL/SQL statement and returning the produced results.
Definition: types.hpp:5559
Internal usage. Interface for handling ownership and relationship of a C API handle.
Definition: core.hpp:325
struct OCI_Long OCI_Long
Oracle Long data type.
Definition: types.h:260
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)
OCI_SYM_PUBLIC OCI_Long *OCI_API OCI_LongCreate(OCI_Statement *stmt, unsigned int type)
Create a local temporary Long instance.
OCI_SYM_PUBLIC unsigned int OCI_API OCI_LongWrite(OCI_Long *lg, void *buffer, unsigned int len)
Write a buffer into a Long.
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.
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
Raw MakeRaw(AnyPointer result, unsigned int size)
Internal usage. Constructs a C++ Raw object from the given OCILIB raw buffer.
Definition: Utils.hpp:70
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
std::vector< unsigned char > Raw
C++ counterpart of SQL RAW data type.
Definition: config.hpp:138
void * AnyPointer
Alias for the generic void pointer.
Definition: config.hpp:129