@@ -118,6 +118,12 @@ static int _mysql_server_init_done = 0;
118
118
#define HAVE_OPENSSL 1
119
119
#endif
120
120
121
+ /* According to https://dev.mysql.com/doc/refman/5.1/en/mysql-options.html
122
+ The MYSQL_OPT_READ_TIMEOUT apear in the version 5.1.12 */
123
+ #if MYSQL_VERSION_ID > 50112
124
+ #define HAVE_MYSQL_OPT_READ_TIMEOUT 1
125
+ #endif
126
+
121
127
PyObject *
122
128
_mysql_Exception (_mysql_ConnectionObject * c )
123
129
{
@@ -557,8 +563,14 @@ _mysql_ConnectionObject_Initialize(
557
563
"read_default_file" , "read_default_group" ,
558
564
"client_flag" , "ssl" ,
559
565
"local_infile" ,
566
+ #ifdef HAVE_MYSQL_OPT_READ_TIMEOUT
567
+ "read_timeout" ,
568
+ #endif
560
569
NULL } ;
561
570
int connect_timeout = 0 ;
571
+ #ifdef HAVE_MYSQL_OPT_READ_TIMEOUT
572
+ int read_timeout = 0 ;
573
+ #endif
562
574
int compress = -1 , named_pipe = -1 , local_infile = -1 ;
563
575
char * init_command = NULL ,
564
576
* read_default_file = NULL ,
@@ -567,7 +579,13 @@ _mysql_ConnectionObject_Initialize(
567
579
self -> converter = NULL ;
568
580
self -> open = 0 ;
569
581
check_server_init (-1 );
570
- if (!PyArg_ParseTupleAndKeywords (args , kwargs , "|ssssisOiiisssiOi:connect" ,
582
+
583
+ if (!PyArg_ParseTupleAndKeywords (args , kwargs ,
584
+ #ifdef HAVE_MYSQL_OPT_READ_TIMEOUT
585
+ "|ssssisOiiisssiOii:connect" ,
586
+ #else
587
+ "|ssssisOiiisssiOi:connect" ,
588
+ #endif
571
589
kwlist ,
572
590
& host , & user , & passwd , & db ,
573
591
& port , & unix_socket , & conv ,
@@ -576,8 +594,11 @@ _mysql_ConnectionObject_Initialize(
576
594
& init_command , & read_default_file ,
577
595
& read_default_group ,
578
596
& client_flag , & ssl ,
579
- & local_infile /* DO NOT PATCH FOR RECONNECT, IDIOTS
597
+ & local_infile , /* DO NOT PATCH FOR RECONNECT, IDIOTS
580
598
IF YOU DO THIS, I WILL NOT SUPPORT YOUR PACKAGES. */
599
+ #ifdef HAVE_MYSQL_OPT_READ_TIMEOUT
600
+ & read_timeout
601
+ #endif
581
602
))
582
603
return -1 ;
583
604
@@ -613,6 +634,13 @@ _mysql_ConnectionObject_Initialize(
613
634
mysql_options (& (self -> connection ), MYSQL_OPT_CONNECT_TIMEOUT ,
614
635
(char * )& timeout );
615
636
}
637
+ #ifdef HAVE_MYSQL_OPT_READ_TIMEOUT
638
+ if (read_timeout ) {
639
+ unsigned int timeout = read_timeout ;
640
+ mysql_options (& (self -> connection ), MYSQL_OPT_READ_TIMEOUT ,
641
+ (char * )& timeout );
642
+ }
643
+ #endif
616
644
if (compress != -1 ) {
617
645
mysql_options (& (self -> connection ), MYSQL_OPT_COMPRESS , 0 );
618
646
client_flag |= CLIENT_COMPRESS ;
0 commit comments