Skip to content

Commit b400acd

Browse files
authored
set charset before connect (#382)
1 parent 5a40d57 commit b400acd

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

MySQLdb/_mysql.c

+9-4
Original file line numberDiff line numberDiff line change
@@ -397,21 +397,22 @@ _mysql_ConnectionObject_Initialize(
397397
"read_default_file", "read_default_group",
398398
"client_flag", "ssl",
399399
"local_infile",
400-
"read_timeout", "write_timeout",
400+
"read_timeout", "write_timeout", "charset",
401401
NULL } ;
402402
int connect_timeout = 0;
403403
int read_timeout = 0;
404404
int write_timeout = 0;
405405
int compress = -1, named_pipe = -1, local_infile = -1;
406406
char *init_command=NULL,
407407
*read_default_file=NULL,
408-
*read_default_group=NULL;
408+
*read_default_group=NULL,
409+
*charset=NULL;
409410

410411
self->converter = NULL;
411412
self->open = 0;
412413

413414
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
414-
"|ssssisOiiisssiOiii:connect",
415+
"|ssssisOiiisssiOiiis:connect",
415416
kwlist,
416417
&host, &user, &passwd, &db,
417418
&port, &unix_socket, &conv,
@@ -422,7 +423,8 @@ _mysql_ConnectionObject_Initialize(
422423
&client_flag, &ssl,
423424
&local_infile,
424425
&read_timeout,
425-
&write_timeout
426+
&write_timeout,
427+
&charset
426428
))
427429
return -1;
428430

@@ -486,6 +488,9 @@ _mysql_ConnectionObject_Initialize(
486488
if (ssl) {
487489
mysql_ssl_set(&(self->connection), key, cert, ca, capath, cipher);
488490
}
491+
if (charset) {
492+
mysql_options(&(self->connection), MYSQL_SET_CHARSET_NAME, charset);
493+
}
489494

490495
conn = mysql_real_connect(&(self->connection), host, user, passwd, db,
491496
port, unix_socket, client_flag);

MySQLdb/connections.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class object, used to create cursors (keyword only)
140140
kwargs2['conv'] = conv2
141141

142142
cursorclass = kwargs2.pop('cursorclass', self.default_cursor)
143-
charset = kwargs2.pop('charset', '')
143+
charset = kwargs2.get('charset', '')
144144

145145
if charset or not PY2:
146146
use_unicode = True

0 commit comments

Comments
 (0)