File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed
Filter options
Expand file tree Collapse file tree 2 files changed +12
-4
lines changed
Original file line number Diff line number Diff line change @@ -217,6 +217,9 @@ _get_encoding(MYSQL *mysql)
217
217
if (strncmp (utf8 , cs .csname , 4 ) == 0 ) { // utf8, utf8mb3, utf8mb4
218
218
return utf8 ;
219
219
}
220
+ else if (strncmp ("latin1" , cs .csname , 6 ) == 0 ) {
221
+ return "cp1252" ;
222
+ }
220
223
else if (strncmp ("koi8r" , cs .csname , 5 ) == 0 ) {
221
224
return "koi8_r" ;
222
225
}
Original file line number Diff line number Diff line change 15
15
NotSupportedError , ProgrammingError ,
16
16
)
17
17
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
+ }
18
26
19
27
re_numeric_part = re .compile (r"^(\d+)" )
20
28
@@ -289,10 +297,7 @@ def set_character_set(self, charset):
289
297
set can only be changed in MySQL-4.1 and newer. If you try
290
298
to change the character set from the current value in an
291
299
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 )
296
301
if self .character_set_name () != charset :
297
302
try :
298
303
super (Connection , self ).set_character_set (charset )
You can’t perform that action at this time.
0 commit comments