Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add SQL_WCHART_CONVERT to 64-bit Unix with 32-bit Unicode

Thanks to Marc-Antoine Parent.
  • Loading branch information...
commit ddcaaed1b8f23eba7afd3c2f986754e878572140 1 parent c80051c
@mkleehammer authored
Showing with 48 additions and 44 deletions.
  1. +32 −31 setup.py
  2. +6 −6 tests3/mysqltests.py
  3. +10 −7 tests3/pgtests.py
View
63 setup.py
@@ -115,9 +115,12 @@ def main():
def get_compiler_settings(version_str):
- settings = { 'libraries': [],
- 'include_dirs': [],
- 'define_macros' : [ ('PYODBC_VERSION', version_str) ] }
+ settings = {
+ 'extra_compile_args' : [],
+ 'libraries': [],
+ 'include_dirs': [],
+ 'define_macros' : [ ('PYODBC_VERSION', version_str) ]
+ }
# This isn't the best or right way to do this, but I don't see how someone is supposed to sanely subclass the build
# command.
@@ -128,22 +131,28 @@ def get_compiler_settings(version_str):
except ValueError:
pass
+ from array import array
+ UNICODE_WIDTH = array('u').itemsize
+ settings['define_macros'].append(('PYODBC_UNICODE_WIDTH', str(UNICODE_WIDTH)))
+
if os.name == 'nt':
- settings['extra_compile_args'] = ['/Wall',
- '/wd4668',
- '/wd4820',
- '/wd4711', # function selected for automatic inline expansion
- '/wd4100', # unreferenced formal parameter
- '/wd4127', # "conditional expression is constant" testing compilation constants
- '/wd4191', # casts to PYCFunction which doesn't have the keywords parameter
- ]
- settings['libraries'].append('odbc32')
- settings['libraries'].append('advapi32')
+ settings['extra_compile_args'].extend([
+ '/Wall',
+ '/wd4668',
+ '/wd4820',
+ '/wd4711', # function selected for automatic inline expansion
+ '/wd4100', # unreferenced formal parameter
+ '/wd4127', # "conditional expression is constant" testing compilation constants
+ '/wd4191', # casts to PYCFunction which doesn't have the keywords parameter
+ ])
if '--debug' in sys.argv:
sys.argv.remove('--debug')
settings['extra_compile_args'].extend('/Od /Ge /GS /GZ /RTC1 /Wp64 /Yd'.split())
+ settings['libraries'].append('odbc32')
+ settings['libraries'].append('advapi32')
+
elif os.environ.get("OS", '').lower().startswith('windows'):
# Windows Cygwin (posix on windows)
# OS name not windows, but still on Windows
@@ -153,24 +162,11 @@ def get_compiler_settings(version_str):
# OS/X now ships with iODBC.
settings['libraries'].append('iodbc')
- # Until I figure out how Apple expects people to find the system include files (xcode-
- # select, xcodebuild?) you'll need to create a setup.cfg file with the following:
- #
- # [build_settings]
- # include_dirs: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include
-
- path = join(dirname(abspath(__file__)), 'setup.cfg')
- print(path, exists(path))
- if exists(path):
- config = ConfigParser()
- config.read(path)
-
- if config.has_option('build_settings', 'include_dirs'):
- value = config.get('build_settings', 'include_dirs').split(os.pathsep)
- settings['include_dirs'] = value
-
# 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', '-Wno-deprecated-declarations']
+ settings['extra_compile_args'].extend([
+ '-Wno-write-strings',
+ '-Wno-deprecated-declarations'
+ ])
# Apple has decided they won't maintain the iODBC system in OS/X and has added deprecation warnings in 10.8.
# For now target 10.7 to eliminate the warnings.
@@ -180,7 +176,12 @@ def get_compiler_settings(version_str):
# Other posix-like: Linux, Solaris, etc.
# 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']
+ settings['extra_compile_args'].append('-Wno-write-strings')
+
+ if UNICODE_WIDTH == 4:
+ # This makes UnixODBC use UCS-4 instead of UCS-2, which works better with sizeof(wchar_t)==4.
+ # Thanks to Marc-Antoine Parent
+ settings['define_macros'].append(('SQL_WCHART_CONVERT', '1'))
# What is the proper way to detect iODBC, MyODBC, unixODBC, etc.?
settings['libraries'].append('odbc')
View
12 tests3/mysqltests.py
@@ -21,7 +21,7 @@
from os.path import join, getsize, dirname, abspath, basename
from testutils import *
-_TESTSTR = '0123456789-abcdefghijklmnopqrstuvwxyz-'
+_TESTSTR = b'0123456789-abcdefghijklmnopqrstuvwxyz-'
def _generate_test_string(length):
"""
@@ -36,7 +36,7 @@ def _generate_test_string(length):
if length <= len(_TESTSTR):
return _TESTSTR[:length]
- c = (length + len(_TESTSTR)-1) / len(_TESTSTR)
+ c = int((length + len(_TESTSTR)-1) / len(_TESTSTR))
v = _TESTSTR * c
return v[:length]
@@ -46,7 +46,7 @@ class MySqlTestCase(unittest.TestCase):
LARGE_FENCEPOST_SIZES = [ 4095, 4096, 4097, 10 * 1024, 20 * 1024 ]
ANSI_FENCEPOSTS = [ _generate_test_string(size) for size in SMALL_FENCEPOST_SIZES ]
- UNICODE_FENCEPOSTS = [ unicode(s) for s in ANSI_FENCEPOSTS ]
+ UNICODE_FENCEPOSTS = [ s.decode('utf8') for s in ANSI_FENCEPOSTS ]
BLOB_FENCEPOSTS = ANSI_FENCEPOSTS + [ _generate_test_string(size) for size in LARGE_FENCEPOST_SIZES ]
def __init__(self, method_name, connection_string):
@@ -132,7 +132,7 @@ def _test_strtype(self, sqltype, value, colsize=None):
try:
self.cursor.execute(sql)
except:
- print '>>>>', sql
+ print('>>>>', sql)
self.cursor.execute("insert into t1 values(?)", value)
v = self.cursor.execute("select * from t1").fetchone()[0]
@@ -416,7 +416,7 @@ def test_bigint(self):
#
# Top 4 bytes are returned as 0x00 00 00 00. If the input is high enough, they are returned as 0xFF FF FF FF.
input = 0x123456789
- print 'writing %x' % input
+ print('writing %x' % input)
self.cursor.execute("create table t1(d bigint)")
self.cursor.execute("insert into t1 values (?)", input)
result = self.cursor.execute("select d from t1").fetchone()[0]
@@ -651,7 +651,7 @@ def test_autocommit(self):
def main():
from optparse import OptionParser
parser = OptionParser(usage=usage)
- parser.add_option("-v", "--verbose", action="count", help="Increment test verbosity (can be used multiple times)")
+ parser.add_option("-v", "--verbose", default=0, action="count", help="Increment test verbosity (can be used multiple times)")
parser.add_option("-d", "--debug", action="store_true", default=False, help="Print debugging items")
parser.add_option("-t", "--test", help="Run only the named test")
View
17 tests3/pgtests.py
@@ -3,6 +3,8 @@
# Unit tests for PostgreSQL on Linux (Fedora)
# This is a stripped down copy of the SQL Server tests.
+from __future__ import print_function
+
import sys, os, re
import unittest
from decimal import Decimal
@@ -23,7 +25,7 @@ def _generate_test_string(length):
if length <= len(_TESTSTR):
return _TESTSTR[:length]
- c = (length + len(_TESTSTR)-1) / len(_TESTSTR)
+ c = int((length + len(_TESTSTR)-1) / len(_TESTSTR))
v = _TESTSTR * c
return v[:length]
@@ -370,7 +372,7 @@ def test_row_repr(self):
def main():
from optparse import OptionParser
parser = OptionParser(usage="usage: %prog [options] connection_string")
- parser.add_option("-v", "--verbose", action="count", help="Increment test verbosity (can be used multiple times)")
+ parser.add_option("-v", "--verbose", default=0, action="count", help="Increment test verbosity (can be used multiple times)")
parser.add_option("-d", "--debug", action="store_true", default=False, help="Print debugging items")
parser.add_option("-t", "--test", help="Run only the named test")
parser.add_option('-a', '--ansi', help='ANSI only', default=False, action='store_true')
@@ -391,11 +393,12 @@ def main():
if options.verbose:
cnxn = pyodbc.connect(connection_string, ansi=options.ansi)
- print 'library:', os.path.abspath(pyodbc.__file__)
- print 'odbc: %s' % cnxn.getinfo(pyodbc.SQL_ODBC_VER)
- print 'driver: %s %s' % (cnxn.getinfo(pyodbc.SQL_DRIVER_NAME), cnxn.getinfo(pyodbc.SQL_DRIVER_VER))
- print 'driver supports ODBC version %s' % cnxn.getinfo(pyodbc.SQL_DRIVER_ODBC_VER)
- print 'unicode:', pyodbc.UNICODE_SIZE, 'sqlwchar:', pyodbc.SQLWCHAR_SIZE
+ print_library_info(cnxn)
+ # print 'library:', os.path.abspath(pyodbc.__file__)
+ # print 'odbc: %s' % cnxn.getinfo(pyodbc.SQL_ODBC_VER)
+ # print 'driver: %s %s' % (cnxn.getinfo(pyodbc.SQL_DRIVER_NAME), cnxn.getinfo(pyodbc.SQL_DRIVER_VER))
+ # print 'driver supports ODBC version %s' % cnxn.getinfo(pyodbc.SQL_DRIVER_ODBC_VER)
+ # print 'unicode:', pyodbc.UNICODE_SIZE, 'sqlwchar:', pyodbc.SQLWCHAR_SIZE
cnxn.close()
if options.test:

0 comments on commit ddcaaed

Please sign in to comment.
Something went wrong with that request. Please try again.