OCILIB (C and C++ Driver for Oracle)  4.7.3
Open source and cross platform Oracle Driver delivering efficient access to Oracle databases.
File.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 // ReSharper disable CppClangTidyHicppUseEqualsDefault
26 // ReSharper disable CppClangTidyModernizeUseEqualsDefault
27 
28 namespace ocilib
29 {
30 
31 inline File::File()
32 {
33 }
34 
35 inline File::File(const Connection &connection)
36 {
37  Acquire(core::Check(OCI_FileCreate(connection, OCI_BFILE)), reinterpret_cast<HandleFreeFunc>(OCI_FileFree), nullptr, connection.GetHandle());
38 }
39 
40 inline File::File(const Connection &connection, const ostring& directory, const ostring& name)
41 {
42  Acquire(core::Check(OCI_FileCreate(connection, OCI_BFILE)), reinterpret_cast<HandleFreeFunc>(OCI_FileFree), nullptr, connection.GetHandle());
43 
44  SetInfos(directory, name);
45 }
46 
47 inline File::File(OCI_File *pFile, core::Handle *parent)
48 {
49  Acquire(pFile, nullptr, nullptr, parent);
50 }
51 
52 inline Raw File::Read(unsigned int size)
53 {
54  core::ManagedBuffer<unsigned char> buffer(static_cast<size_t>(size + 1));
55 
56  size = core::Check(OCI_FileRead(*this, static_cast<AnyPointer>(buffer), size));
57 
58  return core::MakeRaw(buffer, size);
59 }
60 
61 inline bool File::Seek(SeekMode seekMode, big_uint offset)
62 {
63  return (core::Check(OCI_FileSeek(*this, offset, seekMode)) == TRUE);
64 }
65 
66 inline File File::Clone() const
67 {
68  File result(GetConnection());
69 
70  core::Check(OCI_FileAssign(result, *this));
71 
72  return result;
73 }
74 
75 inline bool File::Equals(const File &other) const
76 {
77  return (core::Check(OCI_FileIsEqual(*this, other)) == TRUE);
78 }
79 
80 inline big_uint File::GetOffset() const
81 {
82  return core::Check(OCI_FileGetOffset(*this));
83 }
84 
85 inline big_uint File::GetLength() const
86 {
87  return core::Check(OCI_FileGetSize(*this));
88 }
89 
91 {
92  return Connection(core::Check(OCI_FileGetConnection(*this)), nullptr);
93 }
94 
95 inline bool File::Exists() const
96 {
97  return (core::Check(OCI_FileExists(*this)) == TRUE);
98 }
99 
100 inline void File::SetInfos(const ostring& directory, const ostring& name)
101 {
102  core::Check(OCI_FileSetName(*this, directory.c_str(), name.c_str()));
103 }
104 
105 inline ostring File::GetName() const
106 {
108 }
109 
111 {
113 }
114 
115 inline void File::Open()
116 {
117  core::Check(OCI_FileOpen(*this));
118 }
119 
120 inline bool File::IsOpened() const
121 {
122  return (core::Check(OCI_FileIsOpen(*this)) == TRUE);
123 }
124 
125 inline void File::Close()
126 {
127  core::Check(OCI_FileClose(*this));
128 }
129 
130 inline bool File::operator == (const File& other) const
131 {
132  return Equals(other);
133 }
134 
135 inline bool File::operator != (const File& other) const
136 {
137  return (!(*this == other));
138 }
139 
140 }
Internal usage. Interface for handling ownership and relationship of a C API handle.
Definition: core.hpp:312
File()
Create an empty null File instance.
Definition: File.hpp:31
big_uint GetLength() const
Returns the number of bytes contained in the file.
Definition: File.hpp:85
OCI_SYM_PUBLIC boolean OCI_API OCI_FileSetName(OCI_File *file, const otext *dir, const otext *name)
Set the directory and file name of FILE handle.
OCILIB ++ Namespace.
OCI_SYM_PUBLIC boolean OCI_API OCI_FileAssign(OCI_File *file, OCI_File *file_src)
Assign a file to another one.
OCI_SYM_PUBLIC boolean OCI_API OCI_FileIsEqual(OCI_File *file, OCI_File *file2)
Compare two file handle for equality.
OCI_SYM_PUBLIC OCI_Connection *OCI_API OCI_FileGetConnection(OCI_File *file)
Retrieve connection handle from the file handle.
Raw MakeRaw(AnyPointer result, unsigned int size)
Internal usage. Constructs a C++ Raw object from the given OCILIB raw buffer.
Definition: Utils.hpp:70
void Open()
Open a file for reading on the server.
Definition: File.hpp:115
A connection or session with a specific database.
Definition: types.hpp:1563
big_uint GetOffset() const
Returns the current R/W offset within the file.
Definition: File.hpp:80
OCI_SYM_PUBLIC unsigned int OCI_API OCI_FileRead(OCI_File *file, void *buffer, unsigned int len)
Read a portion of a file into the given buffer.
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 boolean OCI_API OCI_FileOpen(OCI_File *file)
Open a file for reading.
OCI_SYM_PUBLIC boolean OCI_API OCI_FileFree(OCI_File *file)
Free a local File object.
OCI_SYM_PUBLIC boolean OCI_API OCI_FileClose(OCI_File *file)
Close a file.
OCI_SYM_PUBLIC big_uint OCI_API OCI_FileGetOffset(OCI_File *file)
Return the current position in the file.
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
OCI_SYM_PUBLIC boolean OCI_API OCI_FileExists(OCI_File *file)
Check if the given file exists on server.
Template Enumeration template class providing some type safety to some extends for manipulating enume...
Definition: core.hpp:117
Object identifying the SQL data type BFILE.
Definition: types.hpp:4319
Internal usage. Provide a buffer class with RAII capabilities.
Definition: core.hpp:196
File Clone() const
Clone the current instance to a new one performing deep copy.
Definition: File.hpp:66
Connection GetConnection() const
Return the file parent connection.
Definition: File.hpp:90
void SetInfos(const ostring &directory, const ostring &name)
Set the directory and file name of our file object.
Definition: File.hpp:100
Raw Read(unsigned int size)
Read a portion of a file.
Definition: File.hpp:52
struct OCI_File OCI_File
Oracle External Large objects:
Definition: types.h:211
bool operator!=(const File &other) const
Indicates if the current file value is not equal the given file value.
Definition: File.hpp:135
std::vector< unsigned char > Raw
C++ counterpart of SQL RAW data type.
Definition: config.hpp:138
OCI_SYM_PUBLIC const otext *OCI_API OCI_FileGetName(OCI_File *file)
Return the name of the given file.
ostring GetName() const
Return the file name.
Definition: File.hpp:105
OCI_SYM_PUBLIC const otext *OCI_API OCI_FileGetDirectory(OCI_File *file)
Return the directory of the given file.
bool Seek(SeekMode seekMode, big_uint offset)
Move the current position within the file for read/write operations.
Definition: File.hpp:61
OCI_SYM_PUBLIC boolean OCI_API OCI_FileSeek(OCI_File *file, big_uint offset, unsigned int mode)
Perform a seek operation on the OCI_File content buffer.
OCI_SYM_PUBLIC OCI_File *OCI_API OCI_FileCreate(OCI_Connection *con, unsigned int type)
Create a file object instance.
OCI_SYM_PUBLIC big_uint OCI_API OCI_FileGetSize(OCI_File *file)
Return the size in bytes of a file.
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
OCI_SYM_PUBLIC boolean OCI_API OCI_FileIsOpen(OCI_File *file)
Check if the specified file is opened within the file handle.
bool IsOpened() const
Check if the specified file is currently opened on the server by our object.
Definition: File.hpp:120
void Close()
Close the file on the server.
Definition: File.hpp:125
bool operator==(const File &other) const
Indicates if the current file value is equal the given file value.
Definition: File.hpp:130
ostring GetDirectory() const
Return the file directory.
Definition: File.hpp:110
bool Exists() const
Check if the given file exists on server.
Definition: File.hpp:95