Repository navigation
Conversation
When the CLI rejected a statement attribute, set_option() recorded the
error but still returned True, so Python raised SystemError ("returned
a result with an exception set"). prepare() given such an option failed
the same way, and exec_immediate() crashed. All three now raise the
driver's error as an Exception, as other ibm_db calls do. prepare() and
exec_immediate() release the statement they allocated; exec_immediate()
now does so for any options error.
When the CLI rejected a connection attribute, the diagnostic was read
from the connection handle as if it were a statement handle, so nothing
was recorded and set_option() returned True. It now returns False, as
documented, and conn_errormsg(conn) holds the driver's message.
connect() with such an option still succeeds, as before.
Add a regression test.
Signed-off-by: Robert Cope <robert@copesystems.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the CLI driver rejects an attribute value:
set_option(stmt, ..., 0), or options passed toprepare()/exec_immediate()) now raise the driver's error as anException, the same class and message other ibm_db calls raise. Before, the result was aSystemError("returned a result with an exception set"), andexec_immediate()segfaulted. The statement allocated by a rejectedprepare()is released.exec_immediate()now releases its statement on any options error, including the existing validation errors, where it used to leak it.set_option(conn, ..., 1)) now returnFalse, as documented, and the driver's message is available fromconn_errormsg(conn). It is read from the connection handle, so read it right after the call. If the same dict sets further attributes after the rejected one, they are still applied, as before, and a later successful call on the handle can replace the message. The process-wideconn_errormsg()is left alone, so a successfulconnect()given a rejected option doesn't leave a stale message there. The diagnostic used to be requested through the statement-handle field withSQL_HANDLE_STMT, so nothing was recorded andTruewas returned.connect()with such an option still succeeds, as before.Otherwise nothing changes. The existing messages for invalid
ATTR_CASEandSQL_ATTR_ROW_ARRAY_SIZEvalues are kept, and the zLOAD attribute branch is untouched.Closes #1086
Added
ibm_db_tests/test_6796_SetOptionDriverError.py. It runs against Db2 LUW servers and skips elsewhere, because I could only verify the driver's behaviour there.Testing (Linux x86_64, Python 3.13, clidriver v11.5.9, Db2 LUW 11.5.8):
exec_immediate()case). With this change it passes.Note: this touches the same lines as #1085 (reference leaks in option parsing), so whichever merges second needs a rebase. The conflict is in the two string-value branches of
_python_ibm_db_assign_options(). Keep both sides, with #<PR 1>'sPy_DECREF(data);before this PR'sif (rc == SQL_ERROR) return ...;. #<PR 1>'sPy_XDECREF(keys)lines in_python_ibm_db_parse_options()merge cleanly. I ran both new tests on the combined code resolved that way, and test 6796 checks that a rejected string option is released the same way as an accepted one, so a resolution that drops the decref on the new return shows up as a leak.