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