Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzmbrzl committed Oct 26, 2023
1 parent 2c95e8a commit fe80aa7
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/backends/oracle/blob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <cctype>

#include <iostream>
#include <bitset>

#ifdef _MSC_VER
#pragma warning(disable:4355)
Expand All @@ -24,6 +25,20 @@ using namespace soci;
using namespace soci::details;
using namespace soci::details::oracle;

std::bitset<sizeof(OCILobLocator)> toBitset(const OCILobLocator &locator) {
std::bitset<sizeof(OCILobLocator)> 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<void *>(locator) << ", value: " << toBitset(*locator);
}

oracle_blob_backend::oracle_blob_backend(oracle_session_backend &session)
: session_(session), lobp_(NULL), initialized_(false)
{
Expand All @@ -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()
Expand Down Expand Up @@ -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 {
Expand All @@ -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_);
}

Expand All @@ -222,13 +243,34 @@ 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)
{
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;
}
}

0 comments on commit fe80aa7

Please sign in to comment.