/* * OCILIB - C Driver for Oracle (C Wrapper for Oracle OCI) * * Website: http://www.ocilib.net * * Copyright (c) 2007-2023 Vincent ROGIER * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include "ocilibcpp/types.hpp" // ReSharper disable CppClangTidyHicppUseEqualsDefault // ReSharper disable CppClangTidyModernizeUseEqualsDefault // ReSharper disable CppClangTidyHicppUseAuto // ReSharper disable CppClangTidyModernizeUseAuto // ReSharper disable CppClangTidyMiscMisplacedConst namespace ocilib { template inline Lob::Lob() { } template Lob::Lob(const Connection &connection) { AcquireAllocated ( core::Check(OCI_LobCreate(connection, U)), connection.GetHandle() ); } template Lob::Lob(OCI_Lob *pLob, core::Handle *parent) { AcquireTransient(pLob, parent); } template<> inline ostring Lob::Read(unsigned int length) { core::ManagedBuffer buffer(static_cast(Environment::GetCharMaxSize() * (length + 1))); unsigned int charCount = length; unsigned int byteCount = 0; if (core::Check(OCI_LobRead2(*this, static_cast(buffer), &charCount, &byteCount))) { length = byteCount / sizeof(otext); } return core::MakeString(static_cast(buffer), static_cast(length)); } template<> inline ostring Lob::Read(unsigned int length) { core::ManagedBuffer buffer(static_cast(Environment::GetCharMaxSize() * (length + 1))); unsigned int charCount = length; unsigned int byteCount = 0; if (core::Check(OCI_LobRead2(*this, static_cast(buffer), &charCount, &byteCount))) { length = byteCount / sizeof(otext); } return core::MakeString(static_cast(buffer), static_cast(length)); } template<> inline Raw Lob::Read(unsigned int length) { core::ManagedBuffer buffer(length + 1); length = core::Check(OCI_LobRead(*this, static_cast(buffer), length)); return core::MakeRaw(buffer, length); } template unsigned int Lob::Write(const T& content) { if (content.empty()) { return 0; } unsigned int res = 0; unsigned int charCount = 0; unsigned int byteCount = static_cast(content.size() * sizeof(typename T::value_type)); const AnyPointer buffer = static_cast(const_cast(&content[0])); if (core::Check(OCI_LobWrite2(*this, buffer, &charCount, &byteCount))) { res = U == LobBinary ? byteCount : charCount; } return res; } template void Lob::Append(const Lob& other) { core::Check(OCI_LobAppendLob(*this, other)); } template unsigned int Lob::Append(const T& content) { if (content.empty()) { return 0; } const AnyPointer data = static_cast(const_cast(&content[0])); return core::Check(OCI_LobAppend(*this, data, static_cast(content.size()))); } template bool Lob::Seek(SeekMode seekMode, big_uint offset) { return (core::Check(OCI_LobSeek(*this, offset, seekMode)) == TRUE); } template Lob Lob::Clone() const { Lob result(GetConnection()); core::Check(OCI_LobAssign(result, *this)); return result; } template bool Lob::Equals(const Lob &other) const { return (core::Check(OCI_LobIsEqual(*this, other)) == TRUE); } template LobType Lob::GetType() const { return LobType(static_cast(core::Check(OCI_LobGetType(*this)))); } template big_uint Lob::GetOffset() const { return core::Check(OCI_LobGetOffset(*this)); } template big_uint Lob::GetLength() const { return core::Check(OCI_LobGetLength(*this)); } template big_uint Lob::GetMaxSize() const { return core::Check(OCI_LobGetMaxSize(*this)); } template big_uint Lob::GetChunkSize() const { return core::Check(OCI_LobGetChunkSize(*this)); } template Connection Lob::GetConnection() const { return Connection ( core::Check(OCI_LobGetConnection(*this)), Environment::GetEnvironmentHandle() ); } template void Lob::Truncate(big_uint length) { core::Check(OCI_LobTruncate(*this, length)); } template big_uint Lob::Erase(big_uint offset, big_uint length) { return core::Check(OCI_LobErase(*this, offset, length)); } template void Lob::Copy(Lob &dest, big_uint offset, big_uint offsetDest, big_uint length) const { core::Check(OCI_LobCopy(dest, *this, offsetDest, offset, length)); } template bool Lob::IsTemporary() const { return (core::Check(OCI_LobIsTemporary(*this)) == TRUE); } template bool Lob::IsRemote() const { return (core::Check(OCI_LobIsRemote(*this)) == TRUE); } template void Lob::Open(OpenMode mode) { core::Check(OCI_LobOpen(*this, mode)); } template void Lob::Flush() { core::Check(OCI_LobFlush(*this)); } template void Lob::Close() { core::Check(OCI_LobClose(*this)); } template void Lob::EnableBuffering(bool value) { core::Check(OCI_LobEnableBuffering(*this, value)); } template Lob& Lob::operator += (const Lob& other) { Append(other); return *this; } template bool Lob::operator == (const Lob& other) const { return Equals(other); } template bool Lob::operator != (const Lob& other) const { return !(*this == other); } }