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

Use cdecimal to speedup #26

Merged
merged 2 commits into from
Aug 19, 2014
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions src/getdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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).
Expand Down
9 changes: 6 additions & 3 deletions src/pyodbcmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down