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

Add SQL_WCHART_CONVERT for UnixODBC. #20

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ def get_compiler_settings(version_str):
# Python functions take a lot of 'char *' that really should be const. gcc complains about this *a lot*
settings['extra_compile_args'] = ['-Wno-write-strings']

# This makes UnixODBC use UCS-4 instead of UCS-2, which works better with sizeof(wchar_t)==4
settings['extra_compile_args'].append('-DSQL_WCHART_CONVERT=1')

# What is the proper way to detect iODBC, MyODBC, unixODBC, etc.?
settings['libraries'].append('odbc')

Expand Down
16 changes: 16 additions & 0 deletions src/test_unicode_size.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <stdio.h>
#include <sql.h>
#include <sqlext.h>
#include <Python.h>

int main() {
#ifdef HAVE_WCHAR_H
if (sizeof(SQLWCHAR) != sizeof(wchar_t)) {
printf("-DSQL_WCHART_CONVERT=1");
}
#else
if (sizeof(SQLWCHAR) != sizeof(Py_UNICODE)) {
printf("-DSQL_WCHART_CONVERT=1");
}
#endif
}
10 changes: 10 additions & 0 deletions tests3/testunicode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pyodbc
cnxn = pyodbc.connect("DSN=VOS")
cursor = cnxn.cursor()
ustr=u"a\u8c22\u00e9"
cursor.execute("CREATE TABLE unicode_test (name NVARCHAR)")
cursor.execute("INSERT into unicode_test values (?)", ustr)
cursor.execute("SELECT name from unicode_test")
result = cursor.fetchone()[0]
cursor.execute("DROP TABLE unicode_test")
assert result == ustr