Skip to content
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

Allow customization of default odbc version #1278

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/pyodbcmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ static char module_doc[] =
"\n"
"paramstyle\n"
" The string constant 'qmark' to indicate parameters are identified using\n"
" question marks.";
" question marks."
"\n"
"odbcversion\n"
" The ODBC version number as a string, such as '3.X' for ODBC 3.X compatibility.\n"
" This is a global (HENV) setting, so it can only be modified before the first\n"
" connection is made. Use 3.8 if you are using unixodbc connection pooling and your\n"
" drivers are all 3.8 compatible. The default is 3.X\n";

PyObject* Error;
PyObject* Warning;
Expand Down Expand Up @@ -296,7 +302,17 @@ static bool AllocateEnv()
return false;
}

if (!SQL_SUCCEEDED(SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, sizeof(int))))
SQLPOINTER defaultVersion = (SQLPOINTER)SQL_OV_ODBC3;
PyObject* odbcversion = PyObject_GetAttrString(pModule, "odbcversion");
if (PyObject_TypeCheck(odbcversion, &PyUnicode_Type)) {
if (PyUnicode_CompareWithASCIIString(odbcversion, "3.8") == 0)
{
defaultVersion = (SQLPOINTER)SQL_OV_ODBC3_80;
}
}
Py_DECREF(odbcversion);

if (!SQL_SUCCEEDED(SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, defaultVersion, sizeof(int))))
{
PyErr_SetString(PyExc_RuntimeError, "Unable to set SQL_ATTR_ODBC_VERSION attribute.");
return false;
Expand Down Expand Up @@ -1169,6 +1185,7 @@ PyMODINIT_FUNC PyInit_pyodbc()
PyModule_AddIntConstant(module, "threadsafety", 1);
PyModule_AddStringConstant(module, "apilevel", "2.0");
PyModule_AddStringConstant(module, "paramstyle", "qmark");
PyModule_AddStringConstant(module, "odbcversion", "3.X");
PyModule_AddObject(module, "pooling", Py_True);
Py_INCREF(Py_True);
PyModule_AddObject(module, "lowercase", Py_False);
Expand Down