From fe80aa790dc33f292f6953ac51574f9b830b815d Mon Sep 17 00:00:00 2001 From: Robert Adam Date: Thu, 26 Oct 2023 18:44:00 +0200 Subject: [PATCH] test --- src/backends/oracle/blob.cpp | 44 +++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/backends/oracle/blob.cpp b/src/backends/oracle/blob.cpp index 877062965..996f170b9 100644 --- a/src/backends/oracle/blob.cpp +++ b/src/backends/oracle/blob.cpp @@ -15,6 +15,7 @@ #include #include +#include #ifdef _MSC_VER #pragma warning(disable:4355) @@ -24,6 +25,20 @@ using namespace soci; using namespace soci::details; using namespace soci::details::oracle; +std::bitset toBitset(const OCILobLocator &locator) { + std::bitset bitset; + + static_assert(sizeof(bitset) == sizeof(OCILobLocator), "Fail"); + + std::memcpy(&bitset, &locator, sizeof(OCILobLocator)); + + return bitset; +} + +void printLocator(locator_t locator) { + std::cout << "Locator location: " << static_cast(locator) << ", value: " << toBitset(*locator); +} + oracle_blob_backend::oracle_blob_backend(oracle_session_backend &session) : session_(session), lobp_(NULL), initialized_(false) { @@ -34,6 +49,8 @@ oracle_blob_backend::oracle_blob_backend(oracle_session_backend &session) throw soci_error("Cannot allocate the LOB locator"); } std::cout << "Created Oracle Blob obj\n"; + printLocator(lobp_); + std::cout << std::endl; } oracle_blob_backend::~oracle_blob_backend() @@ -191,6 +208,10 @@ void oracle_blob_backend::reset() throw_oracle_soci_error(res, session_.errhp_); } + std::cout << "Is temporary when resetting: " << std::boolalpha << (is_temporary == TRUE) << std::endl; + printLocator(lobp_); + std::cout << std::endl; + if (is_temporary) { res = OCILobFreeTemporary(session_.svchp_, session_.errhp_, lobp_); } else { @@ -199,7 +220,7 @@ void oracle_blob_backend::reset() if (res != OCI_SUCCESS) { - std::cout << "Can't free/close LOB (is temporary: " << std::boolalpha << is_temporary << ") res: " << res << "\n"; + std::cout << "Can't free/close LOB (is temporary: " << is_temporary << ") res: " << res << "\n"; throw_oracle_soci_error(res, session_.errhp_); } @@ -222,6 +243,16 @@ void oracle_blob_backend::ensure_initialized() throw_oracle_soci_error(res, session_.errhp_); } + boolean is_temporary = FALSE; + res = OCILobIsTemporary(session_.envhp_, session_.errhp_, lobp_, &is_temporary); + + if (res != OCI_SUCCESS) + { + throw_oracle_soci_error(res, session_.errhp_); + } + + std::cout << "Is temporary immediately after creation as temporary: " << std::boolalpha << (is_temporary == TRUE) << std::endl; + res = OCILobOpen(session_.svchp_, session_.errhp_, lobp_, OCI_LOB_READWRITE); if (res != OCI_SUCCESS) @@ -229,6 +260,17 @@ void oracle_blob_backend::ensure_initialized() throw_oracle_soci_error(res, session_.errhp_); } + res = OCILobIsTemporary(session_.envhp_, session_.errhp_, lobp_, &is_temporary); + + if (res != OCI_SUCCESS) + { + throw_oracle_soci_error(res, session_.errhp_); + } + + std::cout << "Is temporary immediately after opening: " << std::boolalpha << (is_temporary == TRUE) << std::endl; + printLocator(lobp_); + std::cout << std::endl; + initialized_ = true; } }