summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Schurger <jean@schurger.org>2012-10-04 13:45:26 -0400
committerJean Schurger <jean@schurger.org>2012-10-04 13:45:26 -0400
commit417088a3aa3a2591ebb2589e8bca2582246afcb7 (patch)
tree98d26fea3e2b124849692d93fda3f03b36b915c8
parent0164ffeb2534f050148348e50a51641491b6a65d (diff)
downloadmysqldb1-417088a3aa3a2591ebb2589e8bca2582246afcb7.tar.gz
Exposed 'read_timeout' option.
-rw-r--r--MySQLdb/_mysql.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/MySQLdb/_mysql.c b/MySQLdb/_mysql.c
index b721a66..fc0ce24 100644
--- a/MySQLdb/_mysql.c
+++ b/MySQLdb/_mysql.c
@@ -118,6 +118,12 @@ static int _mysql_server_init_done = 0;
#define HAVE_OPENSSL 1
#endif
+/* According to https://dev.mysql.com/doc/refman/5.1/en/mysql-options.html
+ The MYSQL_OPT_READ_TIMEOUT apear in the version 5.1.12 */
+#if MYSQL_VERSION_ID > 50112
+#define HAVE_MYSQL_OPT_READ_TIMEOUT 1
+#endif
+
PyObject *
_mysql_Exception(_mysql_ConnectionObject *c)
{
@@ -557,8 +563,14 @@ _mysql_ConnectionObject_Initialize(
"read_default_file", "read_default_group",
"client_flag", "ssl",
"local_infile",
+#ifdef HAVE_MYSQL_OPT_READ_TIMEOUT
+ "read_timeout",
+#endif
NULL } ;
int connect_timeout = 0;
+#ifdef HAVE_MYSQL_OPT_READ_TIMEOUT
+ int read_timeout = 0;
+#endif
int compress = -1, named_pipe = -1, local_infile = -1;
char *init_command=NULL,
*read_default_file=NULL,
@@ -567,7 +579,13 @@ _mysql_ConnectionObject_Initialize(
self->converter = NULL;
self->open = 0;
check_server_init(-1);
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ssssisOiiisssiOi:connect",
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+#ifdef HAVE_MYSQL_OPT_READ_TIMEOUT
+ "|ssssisOiiisssiOii:connect",
+#else
+ "|ssssisOiiisssiOi:connect",
+#endif
kwlist,
&host, &user, &passwd, &db,
&port, &unix_socket, &conv,
@@ -576,8 +594,11 @@ _mysql_ConnectionObject_Initialize(
&init_command, &read_default_file,
&read_default_group,
&client_flag, &ssl,
- &local_infile /* DO NOT PATCH FOR RECONNECT, IDIOTS
+ &local_infile, /* DO NOT PATCH FOR RECONNECT, IDIOTS
IF YOU DO THIS, I WILL NOT SUPPORT YOUR PACKAGES. */
+#ifdef HAVE_MYSQL_OPT_READ_TIMEOUT
+ &read_timeout
+#endif
))
return -1;
@@ -613,6 +634,13 @@ _mysql_ConnectionObject_Initialize(
mysql_options(&(self->connection), MYSQL_OPT_CONNECT_TIMEOUT,
(char *)&timeout);
}
+#ifdef HAVE_MYSQL_OPT_READ_TIMEOUT
+ if (read_timeout) {
+ unsigned int timeout = read_timeout;
+ mysql_options(&(self->connection), MYSQL_OPT_READ_TIMEOUT,
+ (char *)&timeout);
+ }
+#endif
if (compress != -1) {
mysql_options(&(self->connection), MYSQL_OPT_COMPRESS, 0);
client_flag |= CLIENT_COMPRESS;