Skip to content

Commit 1fa7ae6

Browse files
committed
WL#15982: Remove use of mysql_shutdown
This worklog removes the usage of mysql_shutdown() C API function and COM_SHUTDOWN. The COM_SHUTDOWN is replaced by SQL command SHUTDOWN. The current API for connection.cmd_shutdown() keeps unchanged. Change-Id: Ie002c8b325b28fa5b3b353370e9473e841761fa3
1 parent 87d0e6c commit 1fa7ae6

File tree

7 files changed

+30
-42
lines changed

7 files changed

+30
-42
lines changed

CHANGES.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ Copyright (c) 2009, 2023, Oracle and/or its affiliates.
88
Full release notes:
99
http://dev.mysql.com/doc/relnotes/connector-python/en/
1010

11+
v8.3.0
12+
======
13+
14+
- WL#15982: Remove use of mysql_shutdown
15+
1116
v8.2.0
1217
======
1318

lib/mysql/connector/abstracts.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,10 +1506,12 @@ def cmd_quit(self) -> Any:
15061506
"""Close the current connection with the server"""
15071507
raise NotImplementedError
15081508

1509-
def cmd_shutdown(
1510-
self, shutdown_type: Optional[int] = None
1511-
) -> Optional[Mapping[str, Any]]:
1512-
"""Shut down the MySQL Server"""
1509+
def cmd_shutdown(self, shutdown_type: Optional[int] = None) -> None:
1510+
"""Shut down the MySQL Server
1511+
1512+
This method sends the SHUTDOWN command to the MySQL server.
1513+
The `shutdown_type` is not used, and it's kept for backward compatibility.
1514+
"""
15131515
raise NotImplementedError
15141516

15151517
def cmd_statistics(self) -> Optional[Mapping[str, Any]]:

lib/mysql/connector/connection.py

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,7 @@
5757
from . import version
5858
from .abstracts import MySQLConnectionAbstract
5959
from .authentication import MySQLAuthenticator, get_auth_plugin
60-
from .constants import (
61-
ClientFlag,
62-
FieldType,
63-
ServerCmd,
64-
ServerFlag,
65-
ShutdownType,
66-
flag_is_set,
67-
)
60+
from .constants import ClientFlag, FieldType, ServerCmd, ServerFlag, flag_is_set
6861
from .conversion import MySQLConverter
6962
from .cursor import (
7063
CursorBase,
@@ -929,24 +922,13 @@ def cmd_quit(self) -> bytes:
929922
self._socket.send(packet, 0, 0)
930923
return bytes(packet)
931924

932-
def cmd_shutdown(self, shutdown_type: Optional[int] = None) -> EofPacketType:
925+
def cmd_shutdown(self, shutdown_type: Optional[int] = None) -> None:
933926
"""Shut down the MySQL Server
934927
935-
This method sends the SHUTDOWN command to the MySQL server and is only
936-
possible if the current user has SUPER privileges. The result is a
937-
dictionary containing the OK packet information.
938-
939-
Note: Most applications and scripts do not the SUPER privilege.
940-
941-
Returns a dict()
928+
This method sends the SHUTDOWN command to the MySQL server.
929+
The `shutdown_type` is not used, and it's kept for backward compatibility.
942930
"""
943-
if shutdown_type:
944-
if not ShutdownType.get_info(shutdown_type):
945-
raise InterfaceError("Invalid shutdown type")
946-
atype = shutdown_type
947-
else:
948-
atype = ShutdownType.SHUTDOWN_DEFAULT
949-
return self._handle_eof(self._send_cmd(ServerCmd.SHUTDOWN, int4store(atype)))
931+
self.cmd_query("SHUTDOWN")
950932

951933
def cmd_statistics(self) -> StatsPacketType:
952934
"""Send the statistics command to the MySQL Server

lib/mysql/connector/connection_cext.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,11 @@ def cmd_quit(self) -> None:
897897
self.close()
898898

899899
def cmd_shutdown(self, shutdown_type: Optional[int] = None) -> None:
900-
"""Shut down the MySQL Server"""
900+
"""Shut down the MySQL Server
901+
902+
This method sends the SHUTDOWN command to the MySQL server.
903+
The `shutdown_type` is not used, and it's kept for backward compatibility.
904+
"""
901905
if not self._cmysql:
902906
raise OperationalError("MySQL Connection not available")
903907

src/mysql_capi.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2954,6 +2954,8 @@ MySQL_shutdown(MySQL *self, PyObject *args)
29542954
{
29552955
unsigned int level = 0;
29562956
int res;
2957+
char *stmt = "SHUTDOWN";
2958+
Py_ssize_t stmt_length;
29572959

29582960
CHECK_SESSION(self);
29592961

@@ -2962,7 +2964,8 @@ MySQL_shutdown(MySQL *self, PyObject *args)
29622964
}
29632965

29642966
Py_BEGIN_ALLOW_THREADS
2965-
res = mysql_shutdown(&self->session, level);
2967+
stmt_length = strlen(stmt);
2968+
res = mysql_real_query(&self->session, stmt, stmt_length);
29662969
Py_END_ALLOW_THREADS
29672970

29682971
if (res) {

tests/test_abstracts.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2014, 2022, Oracle and/or its affiliates.
1+
# Copyright (c) 2014, 2023, Oracle and/or its affiliates.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0, as
@@ -255,12 +255,8 @@ def test_cmd_quit(self):
255255
"Test not available for external MySQL servers",
256256
)
257257
@unittest.skipIf(
258-
tests.MYSQL_VERSION >= (8, 0, 1),
259-
"As of MySQL 8.0.1, CMD_SHUTDOWN is not recognized.",
260-
)
261-
@unittest.skipIf(
262-
tests.MYSQL_VERSION <= (5, 7, 1),
263-
"BugOra17422299 not tested with MySQL version 5.6",
258+
tests.MYSQL_VERSION < (8, 0, 1),
259+
"The SQL command SHUTDOWN is only available as of MySQL 8.0.1",
264260
)
265261
@foreach_cnx()
266262
def test_cmd_shutdown(self):

tests/test_bugs.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,12 +1947,8 @@ def test_load_csv(self):
19471947
"Test not available for external MySQL servers",
19481948
)
19491949
@unittest.skipIf(
1950-
tests.MYSQL_VERSION >= (8, 0, 1),
1951-
"BugOra17422299 not tested with MySQL version >= 8.0.1",
1952-
)
1953-
@unittest.skipIf(
1954-
tests.MYSQL_VERSION <= (5, 7, 1),
1955-
"BugOra17422299 not tested with MySQL version 5.6",
1950+
tests.MYSQL_VERSION < (8, 0, 1),
1951+
"The SQL command SHUTDOWN is only available as of MySQL 8.0.1",
19561952
)
19571953
class BugOra17422299(tests.MySQLConnectorTests):
19581954
"""BUG#17422299: cmd_shutdown fails with malformed connection packet"""

0 commit comments

Comments
 (0)