My favorites
▼
|
Sign in
pyodbc
Python ODBC library
Project Home
Downloads
Wiki
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
264
attachment: pyodbc-memleak.patch
(4.0 KB)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
diff --git a/src/cursor.cpp b/src/cursor.cpp
index 3f491b2..00148cd 100644
--- a/src/cursor.cpp
+++ b/src/cursor.cpp
@@ -700,13 +700,6 @@ static PyObject* execute(Cursor* cur, PyObject* pSql, PyObject* params, bool ski
return RaiseErrorV(0, ProgrammingError, "The cursor's connection was closed.");
}
- 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);
- }
-
while (ret == SQL_NEED_DATA)
{
// We have bound a PyObject* using SQL_LEN_DATA_AT_EXEC, so ODBC is asking us for the data now. We gave the
@@ -719,7 +712,7 @@ static PyObject* execute(Cursor* cur, PyObject* pSql, PyObject* params, bool ski
Py_END_ALLOW_THREADS
if (ret != SQL_NEED_DATA && ret != SQL_NO_DATA && !SQL_SUCCEEDED(ret))
- return RaiseErrorFromHandle("SQLParamData", cur->cnxn->hdbc, cur->hstmt);
+ break;
TRACE("SQLParamData() --> %d\n", ret);
@@ -740,7 +733,7 @@ static PyObject* execute(Cursor* cur, PyObject* pSql, PyObject* params, bool ski
ret = SQLPutData(cur->hstmt, (SQLPOINTER)wchar[offset], (SQLLEN)(remaining * sizeof(SQLWCHAR)));
Py_END_ALLOW_THREADS
if (!SQL_SUCCEEDED(ret))
- return RaiseErrorFromHandle("SQLPutData", cur->cnxn->hdbc, cur->hstmt);
+ break;
offset += remaining;
}
}
@@ -757,7 +750,7 @@ static PyObject* execute(Cursor* cur, PyObject* pSql, PyObject* params, bool ski
ret = SQLPutData(cur->hstmt, (SQLPOINTER)&p[offset], remaining);
Py_END_ALLOW_THREADS
if (!SQL_SUCCEEDED(ret))
- return RaiseErrorFromHandle("SQLPutData", cur->cnxn->hdbc, cur->hstmt);
+ break;
offset += remaining;
}
}
@@ -775,7 +768,7 @@ static PyObject* execute(Cursor* cur, PyObject* pSql, PyObject* params, bool ski
ret = SQLPutData(cur->hstmt, (SQLPOINTER)&p[offset], remaining);
Py_END_ALLOW_THREADS
if (!SQL_SUCCEEDED(ret))
- return RaiseErrorFromHandle("SQLPutData", cur->cnxn->hdbc, cur->hstmt);
+ break;
offset += remaining;
}
}
@@ -795,12 +788,28 @@ static PyObject* execute(Cursor* cur, PyObject* pSql, PyObject* params, bool ski
ret = SQLPutData(cur->hstmt, pb, cb);
Py_END_ALLOW_THREADS
if (!SQL_SUCCEEDED(ret))
- return RaiseErrorFromHandle("SQLPutData", cur->cnxn->hdbc, cur->hstmt);
+ break;
}
}
#endif
- ret = SQL_NEED_DATA;
+ if (SQL_SUCCEEDED(ret))
+ ret = SQL_NEED_DATA;
+ }
+ }
+
+ if (!SQL_SUCCEEDED(ret) && ret != SQL_NO_DATA)
+ {
+ // Take care to extract error information before FreeParamData calls
+ // more ODBC functions.
+ PyObject *pError = GetErrorFromHandle(szLastFunction, cur->cnxn->hdbc,
+ cur->hstmt);
+ FreeParameterData(cur);
+ if (pError)
+ {
+ RaiseErrorFromException(pError);
+ Py_DECREF(pError);
}
+ return 0;
}
FreeParameterData(cur);
@@ -813,9 +822,6 @@ static PyObject* execute(Cursor* cur, PyObject* pSql, PyObject* params, bool ski
return (PyObject*)cur;
}
- if (!SQL_SUCCEEDED(ret))
- return RaiseErrorFromHandle(szLastFunction, cur->cnxn->hdbc, cur->hstmt);
-
SQLLEN cRows = -1;
Py_BEGIN_ALLOW_THREADS
ret = SQLRowCount(cur->hstmt, &cRows);
Powered by
Google Project Hosting