You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
2.6 KiB

  1. --- a/src/connection.cpp
  2. +++ b/src/connection.cpp
  3. @@ -18,6 +18,14 @@
  4. #include "cnxninfo.h"
  5. #include "sqlwchar.h"
  6. +#ifdef WORDS_BIGENDIAN
  7. +# define OPTENC_UTF16NE OPTENC_UTF16BE
  8. +# define ENCSTR_UTF16NE "utf-16be"
  9. +#else
  10. +# define OPTENC_UTF16NE OPTENC_UTF16LE
  11. +# define ENCSTR_UTF16NE "utf-16le"
  12. +#endif
  13. +
  14. #if PY_MAJOR_VERSION < 3
  15. static bool IsStringType(PyObject* t) { return (void*)t == (void*)&PyString_Type; }
  16. static bool IsUnicodeType(PyObject* t) { return (void*)t == (void*)&PyUnicode_Type; }
  17. @@ -90,7 +98,7 @@ static bool Connect(PyObject* pConnectSt
  18. // indication that we can handle Unicode. We are going to use the same unicode ending
  19. // as we do for binding parameters.
  20. - SQLWChar wchar(pConnectString, SQL_C_WCHAR, encoding, "utf-16le");
  21. + SQLWChar wchar(pConnectString, SQL_C_WCHAR, encoding, ENCSTR_UTF16NE);
  22. if (!wchar)
  23. return false;
  24. @@ -216,24 +224,24 @@ PyObject* Connection_New(PyObject* pConn
  25. // single-byte text we don't actually know what the encoding is. For example, with SQL
  26. // Server the encoding is based on the database's collation. We ask the driver / DB to
  27. // convert to SQL_C_WCHAR and use the ODBC default of UTF-16LE.
  28. - cnxn->sqlchar_enc.optenc = OPTENC_UTF16LE;
  29. - cnxn->sqlchar_enc.name = _strdup("utf-16le");
  30. + cnxn->sqlchar_enc.optenc = OPTENC_UTF16NE;
  31. + cnxn->sqlchar_enc.name = _strdup(ENCSTR_UTF16NE);
  32. cnxn->sqlchar_enc.ctype = SQL_C_WCHAR;
  33. - cnxn->sqlwchar_enc.optenc = OPTENC_UTF16LE;
  34. - cnxn->sqlwchar_enc.name = _strdup("utf-16le");
  35. + cnxn->sqlwchar_enc.optenc = OPTENC_UTF16NE;
  36. + cnxn->sqlwchar_enc.name = _strdup(ENCSTR_UTF16NE);
  37. cnxn->sqlwchar_enc.ctype = SQL_C_WCHAR;
  38. - cnxn->metadata_enc.optenc = OPTENC_UTF16LE;
  39. - cnxn->metadata_enc.name = _strdup("utf-16le");
  40. + cnxn->metadata_enc.optenc = OPTENC_UTF16NE;
  41. + cnxn->metadata_enc.name = _strdup(ENCSTR_UTF16NE);
  42. cnxn->metadata_enc.ctype = SQL_C_WCHAR;
  43. // Note: I attempted to use UTF-8 here too since it can hold any type, but SQL Server fails
  44. // with a data truncation error if we send something encoded in 2 bytes to a column with 1
  45. // character. I don't know if this is a bug in SQL Server's driver or if I'm missing
  46. // something, so we'll stay with the default ODBC conversions.
  47. - cnxn->unicode_enc.optenc = OPTENC_UTF16LE;
  48. - cnxn->unicode_enc.name = _strdup("utf-16le");
  49. + cnxn->unicode_enc.optenc = OPTENC_UTF16NE;
  50. + cnxn->unicode_enc.name = _strdup(ENCSTR_UTF16NE);
  51. cnxn->unicode_enc.ctype = SQL_C_WCHAR;
  52. #if PY_MAJOR_VERSION < 3