Skip to content

Commit e57c474

Browse files
author
Jun Yamasaki
committed
Raises an error if the ssl_mode setting is not supported
1 parent 08680b1 commit e57c474

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

MySQLdb/_mysql.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ _mysql_ConnectionObject_Initialize(
486486
(MYSQL_VERSION_ID >= 50711 && MYSQL_VERSION_ID <= 50799) || \
487487
(MYSQL_VERSION_ID >= 80000)) && \
488488
!defined(MARIADB_BASE_VERSION) && !defined(MARIADB_VERSION_ID)
489+
#define HAVE_ENUM_MYSQL_OPT_SSL_MODE
489490
if (ssl_mode) {
490491
mysql_options(&(self->connection), MYSQL_OPT_SSL_MODE, &ssl_mode);
491492
}
@@ -1526,6 +1527,20 @@ _mysql_get_client_info(
15261527
return PyUnicode_FromString(mysql_get_client_info());
15271528
}
15281529

1530+
static char _mysql_get_have_enum_mysql_opt_ssl_mode__doc__[] =
1531+
"Returns whether enum MYSQL_OPT_SSL_MODE is defined.";
1532+
static PyObject *
1533+
_mysql_get_have_enum_mysql_opt_ssl_mode(
1534+
PyObject *self,
1535+
PyObject *noargs)
1536+
{
1537+
#ifdef HAVE_ENUM_MYSQL_OPT_SSL_MODE
1538+
Py_RETURN_TRUE;
1539+
#else
1540+
Py_RETURN_FALSE;
1541+
#endif
1542+
}
1543+
15291544
static char _mysql_ConnectionObject_get_host_info__doc__[] =
15301545
"Returns a string that represents the MySQL client library\n\
15311546
version. Non-standard.\n\
@@ -2577,6 +2592,12 @@ _mysql_methods[] = {
25772592
METH_NOARGS,
25782593
_mysql_get_client_info__doc__
25792594
},
2595+
{
2596+
"get_have_enum_mysql_opt_ssl_mode",
2597+
(PyCFunction)_mysql_get_have_enum_mysql_opt_ssl_mode,
2598+
METH_NOARGS,
2599+
_mysql_get_have_enum_mysql_opt_ssl_mode__doc__
2600+
},
25802601
{NULL, NULL} /* sentinel */
25812602
};
25822603

MySQLdb/connections.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ class object, used to create cursors (keyword only)
170170
kwargs2['client_flag'] = client_flag
171171

172172
if 'ssl_mode' in kwargs:
173+
if not _mysql.get_have_enum_mysql_opt_ssl_mode():
174+
raise NotSupportedError('Does not support ssl_mode specification: %s' % _mysql.get_client_info())
173175
if hasattr(SSL_MODE, kwargs['ssl_mode']):
174176
kwargs2['ssl_mode'] = getattr(SSL_MODE, kwargs['ssl_mode'])
175177
else:

0 commit comments

Comments
 (0)