Skip to content

Commit

Permalink
Avoid Oracle errors for OCI_DESCRIBE_ONLY for non-SELECTs
Browse files Browse the repository at this point in the history
Don't do anything in prepare_for_describe() if the statement is not a
SELECT, as it is not necessary and results in "ORA-24333: zero iteration
count" error, since there's nothing to describe.

This commit is best viewed ignoring whitespace-only changes.

Closes SOCI#1119.
  • Loading branch information
iqbal-hasprime authored and vadz committed Nov 17, 2024
1 parent 7fb2e51 commit 2316c10
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/backends/oracle/statement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,21 +163,33 @@ std::string oracle_statement_backend::rewrite_for_procedure_call(

int oracle_statement_backend::prepare_for_describe()
{
sword res = OCIStmtExecute(session_.svchp_, stmtp_, session_.errhp_,
1, 0, 0, 0, OCI_DESCRIBE_ONLY);
ub2 statementType = OCI_STMT_UNKNOWN;
sword res = OCIAttrGet(static_cast<dvoid*>(stmtp_),
static_cast<ub4>(OCI_HTYPE_STMT), static_cast<dvoid*>(&statementType),
0, static_cast<ub4>(OCI_ATTR_STMT_TYPE), session_.errhp_);
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session_.errhp_);
}

int cols;
res = OCIAttrGet(static_cast<dvoid*>(stmtp_),
static_cast<ub4>(OCI_HTYPE_STMT), static_cast<dvoid*>(&cols),
0, static_cast<ub4>(OCI_ATTR_PARAM_COUNT), session_.errhp_);

if (res != OCI_SUCCESS)
int cols = 0;
if (statementType == OCI_STMT_SELECT)
{
throw_oracle_soci_error(res, session_.errhp_);
res = OCIStmtExecute(session_.svchp_, stmtp_, session_.errhp_,
1, 0, 0, 0, OCI_DESCRIBE_ONLY);
if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session_.errhp_);
}

res = OCIAttrGet(static_cast<dvoid*>(stmtp_),
static_cast<ub4>(OCI_HTYPE_STMT), static_cast<dvoid*>(&cols),
0, static_cast<ub4>(OCI_ATTR_PARAM_COUNT), session_.errhp_);

if (res != OCI_SUCCESS)
{
throw_oracle_soci_error(res, session_.errhp_);
}
}

return cols;
Expand Down

0 comments on commit 2316c10

Please sign in to comment.