@@ -1810,6 +1810,49 @@ _mysql_ConnectionObject_read_query_result(
1810
1810
Py_RETURN_NONE ;
1811
1811
}
1812
1812
1813
+ #if MYSQL_VERSION_ID >= 50707
1814
+ static char _mysql_ConnectionObject_get_session_track_gtids__doc__ [] =
1815
+ "If the `session_track_gtids` system variable (global or session) is \n\
1816
+ set to something other than 'OFF' and the client flag `SESSION_TRACK`` \n\
1817
+ is enabled, you can call this method to retrieve all GTIDs created by \n\
1818
+ the session. Returns a list of unicode strings.\n\
1819
+ " ;
1820
+
1821
+ static PyObject *
1822
+ _mysql_ConnectionObject_get_session_track_gtids (
1823
+ _mysql_ConnectionObject * self ,
1824
+ PyObject * noargs )
1825
+ {
1826
+ int r ;
1827
+ const char * data ;
1828
+ size_t length ;
1829
+
1830
+ Py_BEGIN_ALLOW_THREADS
1831
+ r = mysql_session_track_get_first (& (self -> connection ), SESSION_TRACK_GTIDS , & data , & length );
1832
+ Py_END_ALLOW_THREADS
1833
+
1834
+ PyObject * gtids = PyList_New (0 );
1835
+
1836
+ while (r == 0 )
1837
+ {
1838
+ PyObject * gtid = PyUnicode_DecodeUTF8 (data , length , NULL );
1839
+ if (gtid == NULL )
1840
+ {
1841
+ Py_DECREF (gtids );
1842
+ return NULL ;
1843
+ }
1844
+
1845
+ PyList_Append (gtids , gtid );
1846
+
1847
+ Py_BEGIN_ALLOW_THREADS
1848
+ r = mysql_session_track_get_next (& (self -> connection ), SESSION_TRACK_GTIDS , & data , & length );
1849
+ Py_END_ALLOW_THREADS
1850
+ }
1851
+
1852
+ return gtids ;
1853
+ }
1854
+ #endif
1855
+
1813
1856
static char _mysql_ConnectionObject_select_db__doc__ [] =
1814
1857
"Causes the database specified by db to become the default\n\
1815
1858
(current) database on the connection specified by mysql. In subsequent\n\
@@ -2230,6 +2273,14 @@ static PyMethodDef _mysql_ConnectionObject_methods[] = {
2230
2273
METH_NOARGS ,
2231
2274
_mysql_ConnectionObject_read_query_result__doc__ ,
2232
2275
},
2276
+ #if MYSQL_VERSION_ID >= 50707
2277
+ {
2278
+ "get_session_track_gtids" ,
2279
+ (PyCFunction )_mysql_ConnectionObject_get_session_track_gtids ,
2280
+ METH_NOARGS ,
2281
+ _mysql_ConnectionObject_get_session_track_gtids__doc__ ,
2282
+ },
2283
+ #endif
2233
2284
{
2234
2285
"select_db" ,
2235
2286
(PyCFunction )_mysql_ConnectionObject_select_db ,
0 commit comments