OCILIB (C and C++ Driver for Oracle)  4.7.6
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-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 
31 inline File::File()
32 {
33 }
34 
35 inline File::File(const Connection &connection)
36 {
37  AcquireAllocated
38  (
39  core::Check(OCI_FileCreate(connection, OCI_BFILE)),
40  connection.GetHandle()
41  );
42 }
43 
44 inline File::File(const Connection &connection, const ostring& directory, const ostring& name)
45 {
46  AcquireAllocated
47  (
48  core::Check(OCI_FileCreate(connection, OCI_BFILE)),
49  connection.GetHandle()
50  );
51 
52  SetInfos(directory, name);
53 }
54 
55 inline File::File(OCI_File *pFile, core::Handle *parent)
56 {
57  AcquireTransient(pFile,parent);
58 }
59 
60 inline Raw File::Read(unsigned int size)
61 {
62  core::ManagedBuffer<unsigned char> buffer(static_cast<size_t>(size + 1));
63 
64  size = core::Check(OCI_FileRead(*this, static_cast<AnyPointer>(buffer), size));
65 
66  return core::MakeRaw(buffer, size);
67 }
68 
69 inline bool File::Seek(SeekMode seekMode, big_uint offset)
70 {
71  return (core::Check(OCI_FileSeek(*this, offset, seekMode)) == TRUE);
72 }
73 
74 inline File File::Clone() const
75 {
76  File result(GetConnection());
77 
78  core::Check(OCI_FileAssign(result, *this));
79 
80  return result;
81 }
82 
83 inline bool File::Equals(const File &other) const
84 {
85  return (core::Check(OCI_FileIsEqual(*this, other)) == TRUE);
86 }
87 
88 inline big_uint File::GetOffset() const
89 {
90  return core::Check(OCI_FileGetOffset(*this));
91 }
92 
93 inline big_uint File::GetLength() const
94 {
95  return core::Check(OCI_FileGetSize(*this));
96 }
97 
99 {
100  return Connection
101  (
103  Environment::GetEnvironmentHandle()
104  );
105 }
106 
107 inline bool File::Exists() const
108 {
109  return (core::Check(OCI_FileExists(*this)) == TRUE);
110 }
111 
112 inline void File::SetInfos(const ostring& directory, const ostring& name)
113 {
114  core::Check(OCI_FileSetName(*this, directory.c_str(), name.c_str()));
115 }
116 
117 inline ostring File::GetName() const
118 {
120 }
121 
123 {
125 }
126 
127 inline void File::Open()
128 {
129  core::Check(OCI_FileOpen(*this));
130 }
131 
132 inline bool File::IsOpened() const
133 {
134  return (core::Check(OCI_FileIsOpen(*this)) == TRUE);
135 }
136 
137 inline void File::Close()
138 {
139  core::Check(OCI_FileClose(*this));
140 }
141 
142 inline bool File::operator == (const File& other) const
143 {
144  return Equals(other);
145 }
146 
147 inline bool File::operator != (const File& other) const
148 {
149  return (!(*this == other));
150 }
151 
152 }
A connection or session with a specific database.
Definition: types.hpp:1580
Object identifying the SQL data type BFILE.
Definition: types.hpp:4342
ostring GetDirectory() const
Return the file directory.
Definition: File.hpp:122
bool operator!=(const File &other) const
Indicates if the current file value is not equal the given file value.
Definition: File.hpp:147
void Close()
Close the file on the server.
Definition: File.hpp:137
big_uint GetOffset() const
Returns the current R/W offset within the file.
Definition: File.hpp:88
ostring GetName() const
Return the file name.
Definition: File.hpp:117
big_uint GetLength() const
Returns the number of bytes contained in the file.
Definition: File.hpp:93
Connection GetConnection() const
Return the file parent connection.
Definition: File.hpp:98
void SetInfos(const ostring &directory, const ostring &name)
Set the directory and file name of our file object.
Definition: File.hpp:112
bool Seek(SeekMode seekMode, big_uint offset)
Move the current position within the file for read/write operations.
Definition: File.hpp:69
bool operator==(const File &other) const
Indicates if the current file value is equal the given file value.
Definition: File.hpp:142
File Clone() const
Clone the current instance to a new one performing deep copy.
Definition: File.hpp:74
Raw Read(unsigned int size)
Read a portion of a file.
Definition: File.hpp:60
bool IsOpened() const
Check if the specified file is currently opened on the server by our object.
Definition: File.hpp:132
File()
Create an empty null File instance.
Definition: File.hpp:31
bool Exists() const
Check if the given file exists on server.
Definition: File.hpp:107
void Open()
Open a file for reading on the server.
Definition: File.hpp:127
Template Enumeration template class providing some type safety to some extends for manipulating enume...
Definition: core.hpp:118
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_File OCI_File
Oracle External Large objects:
Definition: types.h:223
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_FileIsOpen(OCI_File *file)
Check if the specified file is opened within the file handle.
OCI_SYM_PUBLIC OCI_Connection *OCI_API OCI_FileGetConnection(OCI_File *file)
Retrieve connection handle from the file handle.
OCI_SYM_PUBLIC boolean OCI_API OCI_FileIsEqual(OCI_File *file, OCI_File *file2)
Compare two file handle for equality.
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 boolean OCI_API OCI_FileExists(OCI_File *file)
Check if the given file exists on server.
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.
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.
OCI_SYM_PUBLIC big_uint OCI_API OCI_FileGetOffset(OCI_File *file)
Return the current position in the file.
OCI_SYM_PUBLIC boolean OCI_API OCI_FileOpen(OCI_File *file)
Open a file for reading.
OCI_SYM_PUBLIC OCI_File *OCI_API OCI_FileCreate(OCI_Connection *con, unsigned int type)
Create a file object instance.
OCI_SYM_PUBLIC const otext *OCI_API OCI_FileGetDirectory(OCI_File *file)
Return the directory of the given file.
OCI_SYM_PUBLIC const otext *OCI_API OCI_FileGetName(OCI_File *file)
Return the name of the given file.
OCI_SYM_PUBLIC boolean OCI_API OCI_FileClose(OCI_File *file)
Close a file.
OCI_SYM_PUBLIC big_uint OCI_API OCI_FileGetSize(OCI_File *file)
Return the size in bytes of a file.
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