Simplify Oracle error reporting

Instead of calling throw_oracle_soci_error(), add oracle_soci_error ctor
taking the parameters that were passed to this function and just throw
the object created using this ctor.

This is more explicit and simpler.

No real changes.
This commit is contained in:
Vadim Zeitlin
2026-02-06 02:25:44 +01:00
parent 862cac05b2
commit c59f23412a
10 changed files with 63 additions and 54 deletions

View File

@@ -26,6 +26,8 @@ namespace soci
class SOCI_ORACLE_DECL oracle_soci_error : public soci_error
{
public:
oracle_soci_error(sword res, OCIError *errhp);
oracle_soci_error(std::string const & msg, int errNum = 0);
error_category get_error_category() const override;

View File

@@ -56,7 +56,7 @@ std::size_t oracle_blob_backend::get_len()
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session_.errhp_);
throw oracle_soci_error(res, session_.errhp_);
}
return static_cast<std::size_t>(len);
@@ -81,7 +81,7 @@ std::size_t oracle_blob_backend::read_from_start(void *buf, std::size_t toRead,
static_cast<oraub8>(offset + 1), buf, amt, OCI_ONE_PIECE, nullptr, nullptr, 0, SQLCS_IMPLICIT);
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session_.errhp_);
throw oracle_soci_error(res, session_.errhp_);
}
return static_cast<std::size_t>(amt);
@@ -104,7 +104,7 @@ std::size_t oracle_blob_backend::write_from_start(const void *buf, std::size_t t
const_cast<void*>(buf), amt, OCI_ONE_PIECE, nullptr, nullptr, 0, 0);
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session_.errhp_);
throw oracle_soci_error(res, session_.errhp_);
}
return static_cast<std::size_t>(amt);
@@ -120,7 +120,7 @@ std::size_t oracle_blob_backend::append(const void *buf, std::size_t toWrite)
&amt, nullptr, const_cast<void*>(buf), amt, OCI_ONE_PIECE, nullptr, nullptr, 0, 0);
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session_.errhp_);
throw oracle_soci_error(res, session_.errhp_);
}
return static_cast<std::size_t>(amt);
@@ -132,7 +132,7 @@ void oracle_blob_backend::trim(std::size_t newLen)
static_cast<oraub8>(newLen));
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session_.errhp_);
throw oracle_soci_error(res, session_.errhp_);
}
}
@@ -155,7 +155,7 @@ void oracle_blob_backend::set_lob_locator(const oracle_blob_backend::locator_t l
sword res = OCILobLocatorAssign(session_.svchp_, session_.errhp_, locator, &lobp_);
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session_.errhp_);
throw oracle_soci_error(res, session_.errhp_);
}
}
@@ -168,7 +168,7 @@ void oracle_blob_backend::set_lob_locator(const oracle_blob_backend::locator_t l
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session_.errhp_);
throw oracle_soci_error(res, session_.errhp_);
}
if (!already_open)
@@ -177,7 +177,7 @@ void oracle_blob_backend::set_lob_locator(const oracle_blob_backend::locator_t l
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session_.errhp_);
throw oracle_soci_error(res, session_.errhp_);
}
}
}
@@ -195,7 +195,7 @@ void oracle_blob_backend::reset()
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session_.errhp_);
throw oracle_soci_error(res, session_.errhp_);
}
if (is_temporary)
@@ -209,7 +209,7 @@ void oracle_blob_backend::reset()
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session_.errhp_);
throw oracle_soci_error(res, session_.errhp_);
}
initialized_ = false;
@@ -225,14 +225,14 @@ void oracle_blob_backend::ensure_initialized()
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session_.errhp_);
throw oracle_soci_error(res, session_.errhp_);
}
res = OCILobOpen(session_.svchp_, session_.errhp_, lobp_, OCI_LOB_READWRITE);
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session_.errhp_);
throw oracle_soci_error(res, session_.errhp_);
}
initialized_ = true;

View File

@@ -72,9 +72,13 @@ soci_error::error_category oracle_soci_error::get_error_category() const
return unknown;
}
void soci::details::oracle::get_error_details(sword res, OCIError *errhp,
std::string &msg, int &errNum)
namespace
{
std::string do_get_error_details(sword res, OCIError *errhp, int& errNum)
{
std::string msg;
text errbuf[512];
sb4 errcode;
errNum = 0;
@@ -97,13 +101,19 @@ void soci::details::oracle::get_error_details(sword res, OCIError *errhp,
default:
msg = "soci error: Unknown error code";
}
return msg;
}
void soci::details::oracle::throw_oracle_soci_error(sword res, OCIError *errhp)
} // anonymous namespace
void soci::details::oracle::get_error_details(sword res, OCIError *errhp,
std::string &msg, int &errNum)
{
msg = do_get_error_details(res, errhp, errNum);
}
oracle_soci_error::oracle_soci_error(sword res, OCIError *errhp)
: soci_error(do_get_error_details(res, errhp, err_num_))
{
std::string msg;
int errNum;
get_error_details(res, errhp, msg, errNum);
throw oracle_soci_error(msg, errNum);
}

View File

@@ -19,8 +19,6 @@ namespace details
namespace oracle
{
void throw_oracle_soci_error(sword res, OCIError *errhp);
void get_error_details(sword res, OCIError *errhp,
std::string &msg, int &errNum);

View File

@@ -387,7 +387,7 @@ void oracle_session_backend::commit()
sword res = OCITransCommit(svchp_, errhp_, OCI_DEFAULT);
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, errhp_);
throw oracle_soci_error(res, errhp_);
}
}
@@ -396,7 +396,7 @@ void oracle_session_backend::rollback()
sword res = OCITransRollback(svchp_, errhp_, OCI_DEFAULT);
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, errhp_);
throw oracle_soci_error(res, errhp_);
}
}

View File

@@ -181,7 +181,7 @@ void oracle_standard_into_type_backend::define_by_pos(
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, statement_.session_.errhp_);
throw oracle_soci_error(res, statement_.session_.errhp_);
}
}
@@ -217,7 +217,7 @@ void oracle::read_from_lob(oracle_session_backend& session,
sword res = OCILobGetChunkSize(session.svchp_, session.errhp_, lobp, &len);
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session.errhp_);
throw oracle_soci_error(res, session.errhp_);
}
value.clear();
@@ -251,7 +251,7 @@ void oracle::read_from_lob(oracle_session_backend& session,
break;
default:
throw_oracle_soci_error(res, session.errhp_);
throw oracle_soci_error(res, session.errhp_);
}
value.resize(prevSize + lenChunk);

View File

@@ -223,7 +223,7 @@ void oracle_standard_use_type_backend::bind_by_pos(
&indOCIHolder_, nullptr, nullptr, 0, nullptr, OCI_DEFAULT);
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, statement_.session_.errhp_);
throw oracle_soci_error(res, statement_.session_.errhp_);
}
statement_.boundByPos_ = true;
@@ -254,7 +254,7 @@ void oracle_standard_use_type_backend::bind_by_name(
&indOCIHolder_, nullptr, nullptr, 0, nullptr, OCI_DEFAULT);
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, statement_.session_.errhp_);
throw oracle_soci_error(res, statement_.session_.errhp_);
}
statement_.boundByName_ = true;
@@ -280,7 +280,7 @@ void oracle::write_to_lob(
toWrite, OCI_ONE_PIECE, nullptr, nullptr, 0, SQLCS_IMPLICIT);
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session.errhp_);
throw oracle_soci_error(res, session.errhp_);
}
}
@@ -289,7 +289,7 @@ void oracle::write_to_lob(
res = OCILobGetLength(session.svchp_, session.errhp_, lobp, &len);
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session.errhp_);
throw oracle_soci_error(res, session.errhp_);
}
if (toWrite < len)
@@ -297,7 +297,7 @@ void oracle::write_to_lob(
res = OCILobTrim(session.svchp_, session.errhp_, lobp, toWrite);
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session.errhp_);
throw oracle_soci_error(res, session.errhp_);
}
}
}
@@ -309,7 +309,7 @@ OCILobLocator * oracle::create_temp_lob(oracle_session_backend& session)
reinterpret_cast<dvoid**>(&lobp), OCI_DTYPE_LOB, 0, nullptr);
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session.errhp_);
throw oracle_soci_error(res, session.errhp_);
}
res = OCILobCreateTemporary(session.svchp_,
@@ -318,7 +318,7 @@ OCILobLocator * oracle::create_temp_lob(oracle_session_backend& session)
OCI_TEMP_CLOB, OCI_ATTR_NOCACHE, OCI_DURATION_SESSION);
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session.errhp_);
throw oracle_soci_error(res, session.errhp_);
}
return lobp;

View File

@@ -36,7 +36,7 @@ T get_oci_attr(OCIHandle* hp, int attr, OCIError* errhp)
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, errhp);
throw oracle_soci_error(res, errhp);
}
return value;
@@ -91,7 +91,7 @@ void oracle_statement_backend::prepare(std::string const &query,
stmtLen, OCI_V7_SYNTAX, OCI_DEFAULT);
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session_.errhp_);
throw oracle_soci_error(res, session_.errhp_);
}
}
@@ -139,11 +139,11 @@ statement_backend::exec_fetch_result oracle_statement_backend::execute(int numbe
);
if (res2 != OCI_SUCCESS)
{
throw_oracle_soci_error(res2, errhTmp);
throw oracle_soci_error(res2, errhTmp);
}
error_row_ = get_oci_attr<ub4>(errhRow, OCI_ATTR_DML_ROW_OFFSET, errhTmp);
throw_oracle_soci_error(res, errhRow);
throw oracle_soci_error(res, errhRow);
}
//else: No errors, handle as success below.
}
@@ -160,8 +160,7 @@ statement_backend::exec_fetch_result oracle_statement_backend::execute(int numbe
}
else
{
throw_oracle_soci_error(res, session_.errhp_);
return ef_no_data; // unreachable dummy return to please the compiler
throw oracle_soci_error(res, session_.errhp_);
}
}
@@ -186,7 +185,7 @@ statement_backend::exec_fetch_result oracle_statement_backend::fetch(int number)
}
else
{
throw_oracle_soci_error(res, session_.errhp_);
throw oracle_soci_error(res, session_.errhp_);
return ef_no_data; // unreachable dummy return to please the compiler
}
}
@@ -238,7 +237,7 @@ std::string oracle_statement_backend::get_parameter_name(int index) const
if ( res != OCI_SUCCESS )
{
throw_oracle_soci_error(res, session_.errhp_);
throw oracle_soci_error(res, session_.errhp_);
}
return std::string(reinterpret_cast<const char*>(name), len);
@@ -264,7 +263,7 @@ int oracle_statement_backend::prepare_for_describe()
1, 0, nullptr, nullptr, OCI_DESCRIBE_ONLY);
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session_.errhp_);
throw oracle_soci_error(res, session_.errhp_);
}
return get_statement_attr<ub4>(OCI_ATTR_PARAM_COUNT);
@@ -291,7 +290,7 @@ void oracle_statement_backend::describe_column(int colNum,
static_cast<ub4>(colNum));
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session_.errhp_);
throw oracle_soci_error(res, session_.errhp_);
}
// Get the column name
@@ -303,7 +302,7 @@ void oracle_statement_backend::describe_column(int colNum,
reinterpret_cast<OCIError*>(session_.errhp_));
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session_.errhp_);
throw oracle_soci_error(res, session_.errhp_);
}
// Get the column type
@@ -315,7 +314,7 @@ void oracle_statement_backend::describe_column(int colNum,
reinterpret_cast<OCIError*>(session_.errhp_));
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session_.errhp_);
throw oracle_soci_error(res, session_.errhp_);
}
// get the data size
@@ -327,7 +326,7 @@ void oracle_statement_backend::describe_column(int colNum,
reinterpret_cast<OCIError*>(session_.errhp_));
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session_.errhp_);
throw oracle_soci_error(res, session_.errhp_);
}
// get the precision
@@ -339,7 +338,7 @@ void oracle_statement_backend::describe_column(int colNum,
reinterpret_cast<OCIError*>(session_.errhp_));
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session_.errhp_);
throw oracle_soci_error(res, session_.errhp_);
}
// get the scale if necessary, i.e. if not using just NUMBER, for which
@@ -354,7 +353,7 @@ void oracle_statement_backend::describe_column(int colNum,
reinterpret_cast<OCIError*>(session_.errhp_));
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session_.errhp_);
throw oracle_soci_error(res, session_.errhp_);
}
}
else // precision is 0, meaning that this is the default number type
@@ -423,7 +422,7 @@ std::size_t oracle_statement_backend::column_size(int position)
session_.errhp_, 1, 0, nullptr, nullptr, OCI_DESCRIBE_ONLY);
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session_.errhp_);
throw oracle_soci_error(res, session_.errhp_);
}
// Get The Column Handle
@@ -435,7 +434,7 @@ std::size_t oracle_statement_backend::column_size(int position)
static_cast<ub4>(position));
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session_.errhp_);
throw oracle_soci_error(res, session_.errhp_);
}
// Get The Data Size
@@ -447,7 +446,7 @@ std::size_t oracle_statement_backend::column_size(int position)
reinterpret_cast<OCIError*>(session_.errhp_));
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session_.errhp_);
throw oracle_soci_error(res, session_.errhp_);
}
return static_cast<std::size_t>(colSize);

View File

@@ -222,7 +222,7 @@ void oracle_vector_into_type_backend::define_by_pos_bulk(
&indOCIHolderVec_[0], &sizes_[0], &rCodes_[0], OCI_DEFAULT);
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, statement_.session_.errhp_);
throw oracle_soci_error(res, statement_.session_.errhp_);
}
}

View File

@@ -379,7 +379,7 @@ void oracle_vector_use_type_backend::pre_use(indicator const *ind)
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, statement_.session_.errhp_);
throw oracle_soci_error(res, statement_.session_.errhp_);
}
}