Skip to content

Commit ad9c98a

Browse files
Remove SET NAMES usage which is no-op in SingleStore
1 parent 4fa6cad commit ad9c98a

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

singlestoredb/mysql/connection.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -980,11 +980,14 @@ def set_charset(self, charset):
980980

981981
def set_character_set(self, charset, collation=None):
982982
"""
983-
Set charaset (and collation) on the server.
983+
Set session charaset (and collation) on the server.
984984
985-
Send "SET NAMES charset [COLLATE collation]" query.
985+
Send "SET [COLLATION|CHARACTER_SET]_SERVER [collation|charset]" query.
986986
Update Connection.encoding based on charset.
987987
988+
If charset/collection are being set to utf8mb4, the corresponding global
989+
setting must be also utf8mb4.
990+
988991
Parameters
989992
----------
990993
charset : str
@@ -997,9 +1000,9 @@ def set_character_set(self, charset, collation=None):
9971000
encoding = charset_by_name(charset).encoding
9981001

9991002
if collation:
1000-
query = f'SET NAMES {charset} COLLATE {collation}'
1003+
query = f'SET COLLATION_SERVER={collation}'
10011004
else:
1002-
query = f'SET NAMES {charset}'
1005+
query = f'SET CHARACTER_SET_SERVER={charset}'
10031006
self._execute_command(COMMAND.COM_QUERY, query)
10041007
self._read_packet()
10051008
self.charset = charset
@@ -1103,19 +1106,6 @@ def connect(self, sock=None):
11031106
self._get_server_information()
11041107
self._request_authentication()
11051108

1106-
# Send "SET NAMES" query on init for:
1107-
# - Ensure charaset (and collation) is set to the server.
1108-
# - collation_id in handshake packet may be ignored.
1109-
# - If collation is not specified, we don't know what is server's
1110-
# default collation for the charset. For example, default collation
1111-
# of utf8mb4 is:
1112-
# - MySQL 5.7, MariaDB 10.x: utf8mb4_general_ci
1113-
# - MySQL 8.0: utf8mb4_0900_ai_ci
1114-
#
1115-
# Reference:
1116-
# - https://github.com/PyMySQL/PyMySQL/issues/1092
1117-
# - https://github.com/wagtail/wagtail/issues/9477
1118-
# - https://zenn.dev/methane/articles/2023-mysql-collation (Japanese)
11191109
self.set_character_set(self.charset, self.collation)
11201110

11211111
if self.sql_mode is not None:

0 commit comments

Comments
 (0)