diff --git a/src/getdata.cpp b/src/getdata.cpp index bd4232ab..dc1c728f 100644 --- a/src/getdata.cpp +++ b/src/getdata.cpp @@ -462,7 +462,8 @@ static PyObject* GetDataDecimal(Cursor* cur, Py_ssize_t iCol) // TODO: Is Unicode a good idea for Python 2.7? We need to know which drivers support Unicode. - SQLWCHAR buffer[100]; + int buffsize = 100; + SQLWCHAR buffer[buffsize]; SQLLEN cbFetched = 0; // Note: will not include the NULL terminator. SQLRETURN ret; @@ -472,7 +473,7 @@ static PyObject* GetDataDecimal(Cursor* cur, Py_ssize_t iCol) if (!SQL_SUCCEEDED(ret)) return RaiseErrorFromHandle("SQLGetData", cur->cnxn->hdbc, cur->hstmt); - if (cbFetched == SQL_NULL_DATA) + if (cbFetched == SQL_NULL_DATA || cbFetched > (buffsize * sizeof(SQLWCHAR))) Py_RETURN_NONE; // Remove non-digits and convert the databases decimal to a '.' (required by decimal ctor). diff --git a/src/pyodbcmodule.cpp b/src/pyodbcmodule.cpp index d61cb24e..6440d59c 100644 --- a/src/pyodbcmodule.cpp +++ b/src/pyodbcmodule.cpp @@ -180,11 +180,14 @@ static bool import_types() if (!Params_init()) return false; - PyObject* decimalmod = PyImport_ImportModule("decimal"); + PyObject* decimalmod = PyImport_ImportModule("cdecimal"); if (!decimalmod) { - PyErr_SetString(PyExc_RuntimeError, "Unable to import decimal"); - return false; + decimalmod = PyImport_ImportModule("decimal"); + if (!decimalmod) { + PyErr_SetString(PyExc_RuntimeError, "Unable to import cdecimal or decimal"); + return false; + } } decimal_type = PyObject_GetAttrString(decimalmod, "Decimal");