Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit edeab30

Browse filesBrowse files
authored
Use cp1252 for latin1 charset (PyMySQL#398)
1 parent 6c67620 commit edeab30
Copy full SHA for edeab30

File tree

Expand file treeCollapse file tree

2 files changed

+12
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+12
-4
lines changed

‎MySQLdb/_mysql.c

Copy file name to clipboardExpand all lines: MySQLdb/_mysql.c
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ _get_encoding(MYSQL *mysql)
217217
if (strncmp(utf8, cs.csname, 4) == 0) { // utf8, utf8mb3, utf8mb4
218218
return utf8;
219219
}
220+
else if (strncmp("latin1", cs.csname, 6) == 0) {
221+
return "cp1252";
222+
}
220223
else if (strncmp("koi8r", cs.csname, 5) == 0) {
221224
return "koi8_r";
222225
}

‎MySQLdb/connections.py

Copy file name to clipboardExpand all lines: MySQLdb/connections.py
+9-4Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
NotSupportedError, ProgrammingError,
1616
)
1717

18+
# Mapping from MySQL charset name to Python codec name
19+
_charset_to_encoding = {
20+
"utf8mb4": "utf8",
21+
"utf8mb3": "utf8",
22+
"latin1": "cp1252",
23+
"koi8r": "koi8_r",
24+
"koi8u": "koi8_u",
25+
}
1826

1927
re_numeric_part = re.compile(r"^(\d+)")
2028

@@ -289,10 +297,7 @@ def set_character_set(self, charset):
289297
set can only be changed in MySQL-4.1 and newer. If you try
290298
to change the character set from the current value in an
291299
older version, NotSupportedError will be raised."""
292-
if charset in ("utf8mb4", "utf8mb3"):
293-
py_charset = "utf8"
294-
else:
295-
py_charset = charset
300+
py_charset = _charset_to_encoding.get(charset, charset)
296301
if self.character_set_name() != charset:
297302
try:
298303
super(Connection, self).set_character_set(charset)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.