| Issue 264: | [patch] cursor.execute leaks parameters when exception is raised | |
| 2 people starred this issue and may be notified of changes. | Back to list |
cursor.execute leaks its parameters in most cases where an exception is raised.
This is very noticeable when updating a lot of data using the pattern:
try:
cursor.execute('INSERT INTO table ...', params)
except pyodbc.IntegrityError:
# row already exists; update it
cursor.execute('UPDATE table ...', params)
This problem exists in 2.1.8, 3.0.5 and today's git head.
Comments in the code (cursor.cpp) suggest that this problem was considered, but deliberately left there for fear of inaccurate error reporting:
if (!SQL_SUCCEEDED(ret) && ret != SQL_NEED_DATA && ret != SQL_NO_DATA)
{
// We could try dropping through the while and if below, but if there is an error, we need to raise it before
// FreeParameterData calls more ODBC functions.
return RaiseErrorFromHandle("SQLExecDirectW", cur->cnxn->hdbc, cur->hstmt);
}
Attached is a proposed patch to resolve.
May 23, 2012
Project Member
#1
mkleehammer
Status:
Complete
May 23, 2012
Thanks! I do still like my patch better :-) see my review comments on your commit (revision 244e84a3e281): https://code.google.com/p/pyodbc/source/detail?r=244e84a3e281f5f3387089ee49868a6fb9ed1ff2 |