@@ -25,13 +25,14 @@ USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
25
25
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
26
26
PERFORMANCE OF THIS SOFTWARE.
27
27
*/
28
-
28
+ #include <stdbool.h>
29
29
#include "mysql.h"
30
30
#include "mysqld_error.h"
31
31
32
32
#if MYSQL_VERSION_ID >= 80000
33
33
// https://github.com/mysql/mysql-server/commit/eb821c023cedc029ca0b06456dfae365106bee84
34
- #define my_bool _Bool
34
+ // my_bool was typedef of char before MySQL 8.0.0.
35
+ #define my_bool bool
35
36
#endif
36
37
37
38
#if ((MYSQL_VERSION_ID >= 50555 && MYSQL_VERSION_ID <= 50599 ) || \
@@ -71,7 +72,8 @@ static PyObject *_mysql_NotSupportedError;
71
72
typedef struct {
72
73
PyObject_HEAD
73
74
MYSQL connection ;
74
- int open ;
75
+ bool open ;
76
+ bool reconnect ;
75
77
PyObject * converter ;
76
78
} _mysql_ConnectionObject ;
77
79
@@ -443,7 +445,8 @@ _mysql_ConnectionObject_Initialize(
443
445
* auth_plugin = NULL ;
444
446
445
447
self -> converter = NULL ;
446
- self -> open = 0 ;
448
+ self -> open = false;
449
+ self -> reconnect = false;
447
450
448
451
if (!PyArg_ParseTupleAndKeywords (args , kwargs ,
449
452
"|ssssisOiiisssiOsiiiss:connect" ,
@@ -487,7 +490,7 @@ _mysql_ConnectionObject_Initialize(
487
490
PyErr_SetNone (PyExc_MemoryError );
488
491
return -1 ;
489
492
}
490
- self -> open = 1 ;
493
+ self -> open = true ;
491
494
492
495
if (connect_timeout ) {
493
496
unsigned int timeout = connect_timeout ;
@@ -686,7 +689,7 @@ _mysql_ConnectionObject_close(
686
689
Py_BEGIN_ALLOW_THREADS
687
690
mysql_close (& (self -> connection ));
688
691
Py_END_ALLOW_THREADS
689
- self -> open = 0 ;
692
+ self -> open = false ;
690
693
_mysql_ConnectionObject_clear (self );
691
694
Py_RETURN_NONE ;
692
695
}
@@ -1852,18 +1855,18 @@ _mysql_ResultObject_num_rows(
1852
1855
}
1853
1856
1854
1857
static char _mysql_ConnectionObject_ping__doc__ [] =
1855
- "Checks whether or not the connection to the server is\n\
1856
- working. If it has gone down, an automatic reconnection is\n\
1857
- attempted.\n\
1858
+ "Checks whether or not the connection to the server is working.\n\
1858
1859
\n\
1859
1860
This function can be used by clients that remain idle for a\n\
1860
1861
long while, to check whether or not the server has closed the\n\
1861
- connection and reconnect if necessary .\n\
1862
+ connection.\n\
1862
1863
\n\
1863
1864
New in 1.2.2: Accepts an optional reconnect parameter. If True,\n\
1864
1865
then the client will attempt reconnection. Note that this setting\n\
1865
1866
is persistent. By default, this is on in MySQL<5.0.3, and off\n\
1866
1867
thereafter.\n\
1868
+ MySQL 8.0.33 deprecated the MYSQL_OPT_RECONNECT option so reconnect\n\
1869
+ parameter is also deprecated in mysqlclient 2.2.1.\n\
1867
1870
\n\
1868
1871
Non-standard. You should assume that ping() performs an\n\
1869
1872
implicit rollback; use only when starting a new transaction.\n\
@@ -1875,17 +1878,24 @@ _mysql_ConnectionObject_ping(
1875
1878
_mysql_ConnectionObject * self ,
1876
1879
PyObject * args )
1877
1880
{
1878
- int r , reconnect = -1 ;
1879
- if (!PyArg_ParseTuple (args , "|I " , & reconnect )) return NULL ;
1881
+ int reconnect = 0 ;
1882
+ if (!PyArg_ParseTuple (args , "|p " , & reconnect )) return NULL ;
1880
1883
check_connection (self );
1881
- if (reconnect != -1 ) {
1884
+ if (reconnect != (self -> reconnect == true)) {
1885
+ // libmysqlclient show warning to stderr when MYSQL_OPT_RECONNECT is used.
1886
+ // so we avoid using it as possible for now.
1887
+ // TODO: Warn when reconnect is true.
1888
+ // MySQL 8.0.33 show warning to stderr already.
1889
+ // We will emit Pytohn warning in future.
1882
1890
my_bool recon = (my_bool )reconnect ;
1883
1891
mysql_options (& self -> connection , MYSQL_OPT_RECONNECT , & recon );
1892
+ self -> reconnect = (bool )reconnect ;
1884
1893
}
1894
+ int r ;
1885
1895
Py_BEGIN_ALLOW_THREADS
1886
1896
r = mysql_ping (& (self -> connection ));
1887
1897
Py_END_ALLOW_THREADS
1888
- if (r ) return _mysql_Exception (self );
1898
+ if (r ) return _mysql_Exception (self );
1889
1899
Py_RETURN_NONE ;
1890
1900
}
1891
1901
@@ -2165,7 +2175,7 @@ _mysql_ConnectionObject_dealloc(
2165
2175
PyObject_GC_UnTrack (self );
2166
2176
if (self -> open ) {
2167
2177
mysql_close (& (self -> connection ));
2168
- self -> open = 0 ;
2178
+ self -> open = false ;
2169
2179
}
2170
2180
Py_CLEAR (self -> converter );
2171
2181
MyFree (self );
0 commit comments