Skip to content

Commit c2ce6ce

Browse files
committed
Migrate changes from master to master-2.1
1 parent 94f2135 commit c2ce6ce

16 files changed

+280
-115
lines changed

examples/dates.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf-8 -*-
33

44
# MySQL Connector/Python - MySQL driver written in Python.
5-
# Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
5+
# Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved.
66

77
# MySQL Connector/Python is licensed under the terms of the GPLv2
88
# <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -82,6 +82,7 @@ def main(config):
8282
except (mysql.connector.errors.Error, TypeError) as exc:
8383
output.append("Failed inserting {0}\nError: {1}\n".format(
8484
data, exc))
85+
cursor.execute(stmt_drop)
8586
raise
8687

8788
# Read the names again and print them

examples/microseconds.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf-8 -*-
33

44
# MySQL Connector/Python - MySQL driver written in Python.
5-
# Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
5+
# Copyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved.
66

77
# MySQL Connector/Python is licensed under the terms of the GPLv2
88
# <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -95,7 +95,8 @@ def main(config):
9595
except:
9696
# Ignoring the fact that it was not there
9797
pass
98-
98+
99+
cursor.execute("DROP TABLE IF EXISTS relay_laps")
99100
cursor.close()
100101
cnx.close()
101102

lib/cpy_distutils.py

Lines changed: 96 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,22 @@
3535
import os
3636
import shlex
3737
import struct
38-
from subprocess import Popen, PIPE, STDOUT
38+
from subprocess import Popen, PIPE, STDOUT, check_call
3939
import sys
4040
import platform
41+
import shutil
42+
4143

4244
ARCH_64BIT = sys.maxsize > 2**32 # Works with Python 2.6 and greater
4345
py_arch = '64-bit' if ARCH_64BIT else '32-bit'
4446

4547
CEXT_OPTIONS = [
4648
('with-mysql-capi=', None,
4749
"Location of MySQL C API installation or path to mysql_config"),
50+
('extra-compile-args=', None,
51+
"Extra compile args"),
52+
('extra-link-args=', None,
53+
"Extra link args")
4854
]
4955

5056
CEXT_STATIC_OPTIONS = [
@@ -125,7 +131,11 @@ def unix_lib_is64bit(lib_file):
125131
lib_file = mysqlclient_libs[-1]
126132

127133
log.debug("# Using file command to test lib_file {0}".format(lib_file))
128-
prc = Popen(['file', '-L', lib_file], stdin=PIPE, stderr=STDOUT,
134+
if platform.uname() == 'SunOS':
135+
cmd_list = ['file', '-L', lib_file]
136+
else:
137+
cmd_list = ['file', '-L', lib_file]
138+
prc = Popen(cmd_list, stdin=PIPE, stderr=STDOUT,
129139
stdout=PIPE)
130140
stdout = prc.communicate()[0]
131141
stdout = stdout.split(':')[1]
@@ -152,6 +162,9 @@ def parse_mysql_config_info(options, stdout):
152162
libs = shlex.split(info['libs'])
153163
info['lib_dir'] = libs[0].replace('-L', '')
154164
info['libs'] = [ lib.replace('-l', '') for lib in libs[1:] ]
165+
if platform.uname()[0] == 'SunOS':
166+
info['lib_dir'] = info['lib_dir'].replace('-R', '')
167+
info['libs'] = [lib.replace('-R', '') for lib in info['libs']]
155168
log.debug("# info['libs']: ")
156169
for lib in info['libs']:
157170
log.debug("# {0}".format(lib))
@@ -185,7 +198,17 @@ def get_mysql_config_info(mysql_config):
185198
# Try to figure out the architecture
186199
info['arch'] = None
187200
if os.name == 'posix':
188-
pathname = os.path.join(info['lib_dir'], 'lib' + info['libs'][0]) + '*'
201+
if platform.uname()[0] == 'SunOS':
202+
print("info['lib_dir']: {0}".format(info['lib_dir']))
203+
print("info['libs'][0]: {0}".format(info['libs'][0]))
204+
pathname = os.path.abspath(os.path.join(info['lib_dir'],
205+
'lib',
206+
info['libs'][0])) + '/*'
207+
else:
208+
pathname = os.path.join(info['lib_dir'],
209+
'lib' + info['libs'][0]) + '*'
210+
print("# Looking mysqlclient_lib at path: {0}".format(pathname))
211+
log.debug("# searching mysqlclient_lib at: %s", pathname)
189212
libs = glob(pathname)
190213
mysqlclient_libs = []
191214
for filepath in libs:
@@ -205,7 +228,12 @@ def get_mysql_config_info(mysql_config):
205228
log.debug("#+ {0}".format(mysqlclient_lib))
206229
log.debug("# tested mysqlclient_lib[-1]: "
207230
"{0}".format(mysqlclient_libs[-1]))
208-
proc = Popen(['file', '-L', mysqlclient_libs[-1]], stdout=PIPE,
231+
if platform.uname()[0] == 'SunOS':
232+
print("mysqlclient_lib: {0}".format(mysqlclient_libs[-1]))
233+
cmd_list = ['file', mysqlclient_libs[-1]]
234+
else:
235+
cmd_list = ['file', '-L', mysqlclient_libs[-1]]
236+
proc = Popen(cmd_list, stdout=PIPE,
209237
universal_newlines=True)
210238
stdout, _ = proc.communicate()
211239
stdout = stdout.split(':')[1]
@@ -258,6 +286,8 @@ class BuildExtDynamic(build_ext):
258286

259287
def initialize_options(self):
260288
build_ext.initialize_options(self)
289+
self.extra_compile_args = None
290+
self.extra_link_args = None
261291
self.with_mysql_capi = None
262292

263293
def _finalize_connector_c(self, connc_loc):
@@ -367,10 +397,7 @@ def _finalize_connector_c(self, connc_loc):
367397

368398
# We try to offer a nice message when the architecture of Python
369399
# is not the same as MySQL Connector/C binaries.
370-
py_arch = '64-bit' if ARCH_64BIT else '32-bit'
371-
log.debug("# Python architecture: {0}".format(py_arch))
372-
log.debug("# Python ARCH_64BIT: {0}".format(ARCH_64BIT))
373-
log.debug("# self.arch: {0}".format(self.arch))
400+
print("# self.arch: {0}".format(self.arch))
374401
if ARCH_64BIT != connc_64bit:
375402
log.error("Python is {0}, but does not "
376403
"match MySQL C API {1} architecture, "
@@ -381,11 +408,17 @@ def _finalize_connector_c(self, connc_loc):
381408
sys.exit(1)
382409

383410
def finalize_options(self):
384-
self.set_undefined_options('install',
385-
('with_mysql_capi', 'with_mysql_capi'))
411+
self.set_undefined_options(
412+
'install',
413+
('extra_compile_args', 'extra_compile_args'),
414+
('extra_link_args', 'extra_link_args'),
415+
('with_mysql_capi', 'with_mysql_capi'))
386416

387417
build_ext.finalize_options(self)
388418

419+
print("# Python architecture: {0}".format(py_arch))
420+
print("# Python ARCH_64BIT: {0}".format(ARCH_64BIT))
421+
389422
if self.with_mysql_capi:
390423
self._finalize_connector_c(self.with_mysql_capi)
391424

@@ -430,6 +463,13 @@ def fix_compiler(self):
430463
# Add system headers to Extensions extra_compile_args
431464
sysheaders = [ '-isystem' + dir for dir in cc.include_dirs]
432465
for ext in self.extensions:
466+
# Add extra compile args
467+
if self.extra_compile_args:
468+
ext.extra_compile_args.extend(self.extra_compile_args.split())
469+
# Add extra link args
470+
if self.extra_link_args:
471+
ext.extra_link_args.extend(self.extra_link_args.split())
472+
# Add system headers
433473
for sysheader in sysheaders:
434474
if sysheader not in ext.extra_compile_args:
435475
ext.extra_compile_args.append(sysheader)
@@ -440,10 +480,16 @@ def fix_compiler(self):
440480

441481
def run(self):
442482
"""Run the command"""
443-
if not self.with_mysql_capi:
444-
return
445-
446483
if os.name == 'nt':
484+
for ext in self.extensions:
485+
# Use the multithread, static version of the run-time library
486+
ext.extra_compile_args.append("/MT")
487+
# Add extra compile args
488+
if self.extra_compile_args:
489+
ext.extra_compile_args.extend(self.extra_compile_args.split())
490+
# Add extra link args
491+
if self.extra_link_args:
492+
ext.extra_link_args.extend(self.extra_link_args.split())
447493
build_ext.run(self)
448494
else:
449495
self.real_build_extensions = self.build_extensions
@@ -460,11 +506,27 @@ class BuildExtStatic(BuildExtDynamic):
460506
user_options = build_ext.user_options + CEXT_OPTIONS
461507

462508
def finalize_options(self):
509+
install_obj = self.distribution.get_command_obj('install')
510+
install_obj.with_mysql_capi = self.with_mysql_capi
511+
install_obj.extra_compile_args = self.extra_compile_args
512+
install_obj.extra_link_args = self.extra_link_args
513+
install_obj.static = True
514+
515+
options_pairs = []
516+
if not self.extra_compile_args:
517+
options_pairs.append(('extra_compile_args', 'extra_compile_args'))
518+
if not self.extra_link_args:
519+
options_pairs.append(('extra_link_args', 'extra_link_args'))
463520
if not self.with_mysql_capi:
464-
self.set_undefined_options('install',
465-
('with_mysql_capi', 'with_mysql_capi'))
521+
options_pairs.append(('with_mysql_capi', 'with_mysql_capi'))
522+
if options_pairs:
523+
self.set_undefined_options('install', *options_pairs)
466524

467525
build_ext.finalize_options(self)
526+
527+
print("# Python architecture: {0}".format(py_arch))
528+
print("# Python ARCH_64BIT: {0}".format(ARCH_64BIT))
529+
468530
self.connc_lib = os.path.join(self.build_temp, 'connc', 'lib')
469531
self.connc_include = os.path.join(self.build_temp, 'connc', 'include')
470532

@@ -500,7 +562,8 @@ def fix_compiler(self):
500562
if os.name == 'posix':
501563
include_dirs.append(self.connc_include)
502564
library_dirs.append(self.connc_lib)
503-
libraries.append("mysqlclient")
565+
if self.with_mysql_capi:
566+
libraries.append("mysqlclient")
504567

505568
# As we statically link and the "libmysqlclient.a" library
506569
# carry no information what it depends on, we need to
@@ -512,6 +575,12 @@ def fix_compiler(self):
512575
ext.include_dirs.extend(include_dirs)
513576
ext.library_dirs.extend(library_dirs)
514577
ext.libraries.extend(libraries)
578+
# Add extra compile args
579+
if self.extra_compile_args:
580+
ext.extra_compile_args.extend(self.extra_compile_args.split())
581+
# Add extra link args
582+
if self.extra_link_args:
583+
ext.extra_link_args.extend(self.extra_link_args.split())
515584

516585

517586
class InstallLib(install_lib):
@@ -560,23 +629,27 @@ class Install(install):
560629

561630
def initialize_options(self):
562631
install.initialize_options(self)
632+
self.extra_compile_args = None
633+
self.extra_link_args = None
563634
self.with_mysql_capi = None
564635
self.byte_code_only = None
565636
self.static = None
566637

567638
def finalize_options(self):
568639
if self.static:
569-
log.info("Linking CExtension statically with MySQL libraries")
640+
log.info("Linking C Extension statically with libraries")
570641
self.distribution.cmdclass['build_ext'] = BuildExtStatic
571642

572643
if self.byte_code_only is None:
573644
self.byte_code_only = False
574645

646+
build_ext_obj = self.distribution.get_command_obj('build_ext')
647+
build_ext_obj.with_mysql_capi = self.with_mysql_capi
648+
build_ext_obj.extra_compile_args = self.extra_compile_args
649+
build_ext_obj.extra_link_args = self.extra_link_args
650+
build_ext_obj.static = self.static
651+
575652
if self.with_mysql_capi:
576-
build_ext = self.distribution.get_command_obj('build_ext')
577-
build_ext.with_mysql_capi = self.with_mysql_capi
578-
build = self.distribution.get_command_obj('build_ext')
579-
build.with_mysql_capi = self.with_mysql_capi
580653
self.need_ext = True
581654

582655
if not self.need_ext:
@@ -586,7 +659,7 @@ def finalize_options(self):
586659

587660
def run(self):
588661
if not self.need_ext:
589-
log.info("Not Installing C Extension")
662+
log.info("Not Installing MySQL C Extension")
590663
else:
591-
log.info("Installing C Extension")
664+
log.info("Installing MySQL C Extension")
592665
install.run(self)

setupinfo.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
package_dir = {'': 'lib'}
6060
name = 'mysql-connector-python'
6161
version = '{0}.{1}.{2}'.format(*VERSION[0:3])
62-
6362
extensions = [
6463
Extension("_mysql_connector",
6564
sources=[
@@ -69,8 +68,7 @@
6968
"src/mysql_connector.c",
7069
"src/force_cpp_linkage.cc",
7170
],
72-
include_dirs=['src/include'],
73-
)
71+
include_dirs=['src/include']),
7472
]
7573

7674
packages = [

src/exceptions.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
# MySQL Connector/Python - MySQL driver written in Python.
3-
# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
3+
# Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
44
55
# MySQL Connector/Python is licensed under the terms of the GPLv2
66
# <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -25,6 +25,9 @@
2525

2626
#include <Python.h>
2727

28+
#ifdef MS_WINDOWS
29+
#include <windows.h>
30+
#endif
2831
#include <mysql.h>
2932

3033
#include "catch23.h"

src/mysql_capi.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
#include <Python.h>
3131
#include <datetime.h>
3232

33+
#ifdef MS_WINDOWS
34+
#include <windows.h>
35+
#endif
3336
#include <mysql.h>
3437

3538
#include "catch23.h"
@@ -1039,8 +1042,13 @@ MySQL_connect(MySQL *self, PyObject *args, PyObject *kwds)
10391042
#if MYSQL_VERSION_ID >= 50711
10401043
unsigned int ssl_mode;
10411044
#endif
1042-
my_bool abool;
1043-
my_bool ssl_enabled= 0;
1045+
#if MYSQL_VERSION_ID >= 80001
1046+
bool abool;
1047+
bool ssl_enabled= 0;
1048+
#else
1049+
my_bool abool;
1050+
my_bool ssl_enabled= 0;
1051+
#endif
10441052
MYSQL *res;
10451053

10461054
static char *kwlist[]=
@@ -1214,6 +1222,7 @@ MySQL_connect(MySQL *self, PyObject *args, PyObject *kwds)
12141222
res= mysql_real_connect(&self->session, host, user, password, database,
12151223
port, unix_socket, client_flags);
12161224
#else
1225+
{
12171226
char* c_password;
12181227
if (PyUnicode_Check(password))
12191228
{
@@ -1227,6 +1236,7 @@ MySQL_connect(MySQL *self, PyObject *args, PyObject *kwds)
12271236
}
12281237
res= mysql_real_connect(&self->session, host, user, c_password, database,
12291238
port, unix_socket, client_flags);
1239+
}
12301240
#endif
12311241

12321242
Py_END_ALLOW_THREADS

src/mysql_capi_conversion.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
# MySQL Connector/Python - MySQL driver written in Python.
3-
# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
3+
# Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
44
55
# MySQL Connector/Python is licensed under the terms of the GPLv2
66
# <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -29,6 +29,9 @@
2929
#include <Python.h>
3030
#include <datetime.h>
3131

32+
#ifdef MS_WINDOWS
33+
#include <windows.h>
34+
#endif
3235
#include <mysql.h>
3336

3437
#include "catch23.h"
@@ -760,4 +763,4 @@ mytopy_string(const char *data, const unsigned long length,
760763
return PyBytes_FromStringAndSize(data, length);
761764
#endif
762765
}
763-
}
766+
}

0 commit comments

Comments
 (0)