Permalink
Browse files

Do not set parameter set size unnecessarily.

If parameter array binding is not enabled, never set parameter set size. When enabled, only set parameter set size when making a change.
  • Loading branch information...
gbegen committed May 11, 2012
1 parent 956201e commit 23430c155fcccba7b294cbe227ece175f7008e88
Showing with 19 additions and 12 deletions.
  1. +1 −0 src/cursor.cpp
  2. +1 −0 src/cursor.h
  3. +17 −12 src/params.cpp
View
@@ -2174,6 +2174,7 @@ Cursor_New(Connection* cnxn)
cur->paramcount = 0;
cur->paramtypes = 0;
cur->paramInfos = 0;
+ cur->paramSetSize = 1;
cur->colinfos = 0;
cur->arraysize = 1;
cur->rowcount = -1;
View
@@ -94,6 +94,7 @@ struct Cursor
// Even if the same SQL statement is executed twice, the parameter bindings are redone from scratch since we try to
// bind into the Python objects directly.
ParamInfo* paramInfos;
+ Py_ssize_t paramSetSize;
//
// Result Information
View
@@ -855,21 +855,26 @@ static bool Prepare(Cursor* cur, PyObject* pSql, Py_ssize_t cParamSetSize)
Py_INCREF(cur->pPreparedSQL);
}
- Py_BEGIN_ALLOW_THREADS
+ if (cur->cnxn->useParameterArrayBinding && cParamSetSize != cur->paramSetSize)
+ {
+ Py_BEGIN_ALLOW_THREADS
ret = SQLSetStmtAttr(cur->hstmt, SQL_ATTR_PARAMSET_SIZE, (SQLPOINTER)cParamSetSize, SQL_IS_INTEGER);
- Py_END_ALLOW_THREADS
+ Py_END_ALLOW_THREADS
- if (cur->cnxn->hdbc == SQL_NULL_HANDLE)
- {
- // The connection was closed by another thread in the ALLOW_THREADS block above.
- RaiseErrorV(0, ProgrammingError, "The cursor's connection was closed.");
- return false;
- }
+ if (cur->cnxn->hdbc == SQL_NULL_HANDLE)
+ {
+ // The connection was closed by another thread in the ALLOW_THREADS block above.
+ RaiseErrorV(0, ProgrammingError, "The cursor's connection was closed.");
+ return false;
+ }
- if (!SQL_SUCCEEDED(ret))
- {
- RaiseErrorV(0, ArrayBindingNotSupportedError, "Binding parameters to arrays is not supported.");
- return false;
+ if (!SQL_SUCCEEDED(ret))
+ {
+ RaiseErrorV(0, ArrayBindingNotSupportedError, "Binding parameters to arrays is not supported.");
+ return false;
+ }
+
+ cur->paramSetSize = cParamSetSize;
}
return true;

0 comments on commit 23430c1

Please sign in to comment.