From 2316c103e53709f78b5559b78578412441efed8d Mon Sep 17 00:00:00 2001 From: Iqbal Hassan Date: Tue, 9 Jan 2024 15:35:14 +0800 Subject: [PATCH] Avoid Oracle errors for OCI_DESCRIBE_ONLY for non-SELECTs 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 #1119. --- src/backends/oracle/statement.cpp | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/backends/oracle/statement.cpp b/src/backends/oracle/statement.cpp index ec4702f24..c7198b3ba 100644 --- a/src/backends/oracle/statement.cpp +++ b/src/backends/oracle/statement.cpp @@ -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(stmtp_), + static_cast(OCI_HTYPE_STMT), static_cast(&statementType), + 0, static_cast(OCI_ATTR_STMT_TYPE), session_.errhp_); if (res != OCI_SUCCESS) { throw_oracle_soci_error(res, session_.errhp_); } - int cols; - res = OCIAttrGet(static_cast(stmtp_), - static_cast(OCI_HTYPE_STMT), static_cast(&cols), - 0, static_cast(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(stmtp_), + static_cast(OCI_HTYPE_STMT), static_cast(&cols), + 0, static_cast(OCI_ATTR_PARAM_COUNT), session_.errhp_); + + if (res != OCI_SUCCESS) + { + throw_oracle_soci_error(res, session_.errhp_); + } } return cols;