-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion to reduce errors caused by reusing IBM_DBStatement variables #843
Comments
Hello @imavo, Thanks |
The advantage of a statement-object is that it allows re-use (for example , in a loop). Are you suggesting that each loop iteration should use ibm_db.free_stmt() ? Why should'nt the ibm_db.free_result() (at the end of processing a result-set) allow the programmer to work in a more pythonic manner by re-using statement-variables, which would be possible with my suggestion. I cannot see a logical reason why ibm_db.free_result() does not already do what I suggest above. Can you give a logical reason for not closing the CLI-handle as suggested? |
Whatever you suggested to change the function, already exists in ibm_db_free_stmt function. |
Is your feature request related to a problem? Please describe.
See the sample code-fragment below that demonstrates the problem (without the workaround). However, any programmer that calls any ibm_db API that takes an input argument of an IBM_DBStatement object can get a variety of errors (depending on which ibm_db API gets invoked, as long as it needs an input IBM_DBStatement object) if the same variable gets re-used for the IBM_DBStatement object.
Describe the solution you'd like
To Reduce the chances of errors resulting from re-using variables for IBM_DBStatement objects
ibm_db.free_result()
shhould conditionally free the cli-statement-handle and after freeing that cli-statement-handle should remove its identity from the IBM_DBStatement object (for example by setting the hstmt to(SQLHSTMT) -1
). In other words, instead of simply closing the cursor ,it frees the cli-statement-handle also.I note that the destructor function already conditionally does the
SQLFreeHandle()
when the hstmt is not -1.This suggestion will benefit those you use
ibm_db.free_result()
, but will not help those who fail to use it when it needs to be used and who also do not use the workaround.The details of the suggestion is to change the code for
ibm_db_free_result
function to read as follows:Describe alternatives you've considered
It is possible to avoid errors by ensuring that the programmer always remembers to assign "None" to any re-used variable that will store an IBM_DBStatement object before reassigning such a variable. This is considered non-pythonic and it is not mentioned in the wiki to be a requirement, and is easily avoided if the ibm_db code was altered as suggested above.
Additional context
This problem was mentioned in a different guise in #830
Sample python script demonstrating the problem (may others are possible).
The text was updated successfully, but these errors were encountered: