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

fix #9 #10

Closed
wants to merge 2 commits into from
Closed
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
20 changes: 8 additions & 12 deletions src/getdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,12 @@ 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];
SQLCHAR buffer[100];
SQLLEN cbFetched = 0; // Note: will not include the NULL terminator.

SQLRETURN ret;
Py_BEGIN_ALLOW_THREADS
ret = SQLGetData(cur->hstmt, (SQLUSMALLINT)(iCol+1), SQL_C_WCHAR, buffer, sizeof(buffer), &cbFetched);
ret = SQLGetData(cur->hstmt, (SQLSMALLINT)(iCol+1), SQL_C_CHAR, buffer, sizeof(buffer), &cbFetched);
Py_END_ALLOW_THREADS
if (!SQL_SUCCEEDED(ret))
return RaiseErrorFromHandle("SQLGetData", cur->cnxn->hdbc, cur->hstmt);
Expand All @@ -478,9 +478,9 @@ static PyObject* GetDataDecimal(Cursor* cur, Py_ssize_t iCol)

// Remove non-digits and convert the databases decimal to a '.' (required by decimal ctor).
//
// We are assuming that the decimal point and digits fit within the size of SQLWCHAR.
// We are assuming that the decimal point and digits fit within the size of SQLCHAR.

int cch = (int)(cbFetched / sizeof(SQLWCHAR));
int cch = (int)(cbFetched / sizeof(SQLCHAR));

for (int i = (cch - 1); i >= 0; i--)
{
Expand All @@ -491,18 +491,14 @@ static PyObject* GetDataDecimal(Cursor* cur, Py_ssize_t iCol)
}
else if ((buffer[i] < '0' || buffer[i] > '9') && buffer[i] != '-')
{
memmove(&buffer[i], &buffer[i] + 1, (cch - i) * sizeof(SQLWCHAR));
memmove(&buffer[i], &buffer[i] + 1, (cch - i) * sizeof(SQLCHAR));
cch--;
}
}

I(buffer[cch] == 0);

Object str(PyUnicode_FromSQLWCHAR(buffer, cch));
if (!str)
return 0;

return PyObject_CallFunction(decimal_type, "O", str.Get());
return PyObject_CallFunction(decimal_type, "s", buffer);
}


Expand Down Expand Up @@ -560,7 +556,7 @@ static PyObject* GetDataLongLong(Cursor* cur, Py_ssize_t iCol)
ColumnInfo* pinfo = &cur->colinfos[iCol];

SQLSMALLINT nCType = pinfo->is_unsigned ? SQL_C_UBIGINT : SQL_C_SBIGINT;
SQLBIGINT value;
PY_LONG_LONG value;
SQLLEN cbFetched;
SQLRETURN ret;

Expand All @@ -575,7 +571,7 @@ static PyObject* GetDataLongLong(Cursor* cur, Py_ssize_t iCol)
Py_RETURN_NONE;

if (pinfo->is_unsigned)
return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)(SQLUBIGINT)value);
return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)value);

return PyLong_FromLongLong((PY_LONG_LONG)value);
}
Expand Down