Skip to content
This repository

fix #9 #10

Closed
wants to merge 2 commits into from

4 participants

yihuang Gunnlaugur Thor Briem hejsan Michael Kleehammer
yihuang

No description provided.

yihuang

I don't have many experiences with c and 64bit platform, but these changes do fix my problems.
details of my environment is listed in issue #9.

Gunnlaugur Thor Briem
gthb commented

FWIW: Switching to the head of @yihuang's branch got me past the same/a similar issue; I am using FreeTDS on an amd64-platform linux, and was stuck on this:

  File "/opt/pyenv/LIVE/lib/python2.5/site-packages/sqlalchemy/engine/base.py", line 3125, in _fetchone_impl
    return self.cursor.fetchone()
sqlalchemy.exc.DBAPIError: (Error) ('HY003', '[HY003] [FreeTDS][SQL Server]Program type out of range (0) (SQLGetData)') None None
hejsan

This fixed things for me as well.
I am also on a 64 bit ubuntu.
Please merge :)

Michael Kleehammer

Use SQLCHAR when retrieving decimals. Fixes #9.

Thanks to yihuang for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 8 additions and 12 deletions. Show diff stats Hide diff stats

  1. +8 12 src/getdata.cpp
20 src/getdata.cpp
@@ -463,12 +463,12 @@ static PyObject* GetDataDecimal(Cursor* cur, Py_ssize_t iCol)
463 463
464 464 // TODO: Is Unicode a good idea for Python 2.7? We need to know which drivers support Unicode.
465 465
466   - SQLWCHAR buffer[100];
  466 + SQLCHAR buffer[100];
467 467 SQLLEN cbFetched = 0; // Note: will not include the NULL terminator.
468 468
469 469 SQLRETURN ret;
470 470 Py_BEGIN_ALLOW_THREADS
471   - ret = SQLGetData(cur->hstmt, (SQLUSMALLINT)(iCol+1), SQL_C_WCHAR, buffer, sizeof(buffer), &cbFetched);
  471 + ret = SQLGetData(cur->hstmt, (SQLSMALLINT)(iCol+1), SQL_C_CHAR, buffer, sizeof(buffer), &cbFetched);
472 472 Py_END_ALLOW_THREADS
473 473 if (!SQL_SUCCEEDED(ret))
474 474 return RaiseErrorFromHandle("SQLGetData", cur->cnxn->hdbc, cur->hstmt);
@@ -478,9 +478,9 @@ static PyObject* GetDataDecimal(Cursor* cur, Py_ssize_t iCol)
478 478
479 479 // Remove non-digits and convert the databases decimal to a '.' (required by decimal ctor).
480 480 //
481   - // We are assuming that the decimal point and digits fit within the size of SQLWCHAR.
  481 + // We are assuming that the decimal point and digits fit within the size of SQLCHAR.
482 482
483   - int cch = (int)(cbFetched / sizeof(SQLWCHAR));
  483 + int cch = (int)(cbFetched / sizeof(SQLCHAR));
484 484
485 485 for (int i = (cch - 1); i >= 0; i--)
486 486 {
@@ -491,18 +491,14 @@ static PyObject* GetDataDecimal(Cursor* cur, Py_ssize_t iCol)
491 491 }
492 492 else if ((buffer[i] < '0' || buffer[i] > '9') && buffer[i] != '-')
493 493 {
494   - memmove(&buffer[i], &buffer[i] + 1, (cch - i) * sizeof(SQLWCHAR));
  494 + memmove(&buffer[i], &buffer[i] + 1, (cch - i) * sizeof(SQLCHAR));
495 495 cch--;
496 496 }
497 497 }
498 498
499 499 I(buffer[cch] == 0);
500 500
501   - Object str(PyUnicode_FromSQLWCHAR(buffer, cch));
502   - if (!str)
503   - return 0;
504   -
505   - return PyObject_CallFunction(decimal_type, "O", str.Get());
  501 + return PyObject_CallFunction(decimal_type, "s", buffer);
506 502 }
507 503
508 504
@@ -560,7 +556,7 @@ static PyObject* GetDataLongLong(Cursor* cur, Py_ssize_t iCol)
560 556 ColumnInfo* pinfo = &cur->colinfos[iCol];
561 557
562 558 SQLSMALLINT nCType = pinfo->is_unsigned ? SQL_C_UBIGINT : SQL_C_SBIGINT;
563   - SQLBIGINT value;
  559 + PY_LONG_LONG value;
564 560 SQLLEN cbFetched;
565 561 SQLRETURN ret;
566 562
@@ -575,7 +571,7 @@ static PyObject* GetDataLongLong(Cursor* cur, Py_ssize_t iCol)
575 571 Py_RETURN_NONE;
576 572
577 573 if (pinfo->is_unsigned)
578   - return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)(SQLUBIGINT)value);
  574 + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)value);
579 575
580 576 return PyLong_FromLongLong((PY_LONG_LONG)value);
581 577 }

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.