@@ -1802,6 +1802,49 @@ _mysql_ConnectionObject_read_query_result(
1802
1802
Py_RETURN_NONE ;
1803
1803
}
1804
1804
1805
+ #if MYSQL_VERSION_ID >= 50707
1806
+ static char _mysql_ConnectionObject_get_session_track_gtids__doc__ [] =
1807
+ "If the `session_track_gtids` system variable (global or session) is \n\
1808
+ set to something other than 'OFF' and the client flag `SESSION_TRACK`` \n\
1809
+ is enabled, you can call this method to retrieve all GTIDs created by \n\
1810
+ the session. Returns a list of unicode strings.\n\
1811
+ " ;
1812
+
1813
+ static PyObject *
1814
+ _mysql_ConnectionObject_get_session_track_gtids (
1815
+ _mysql_ConnectionObject * self ,
1816
+ PyObject * noargs )
1817
+ {
1818
+ int r ;
1819
+ const char * data ;
1820
+ size_t length ;
1821
+
1822
+ Py_BEGIN_ALLOW_THREADS
1823
+ r = mysql_session_track_get_first (& (self -> connection ), SESSION_TRACK_GTIDS , & data , & length );
1824
+ Py_END_ALLOW_THREADS
1825
+
1826
+ PyObject * gtids = PyList_New (0 );
1827
+
1828
+ while (r == 0 )
1829
+ {
1830
+ PyObject * gtid = PyUnicode_DecodeUTF8 (data , length , NULL );
1831
+ if (gtid == NULL )
1832
+ {
1833
+ Py_DECREF (gtids );
1834
+ return NULL ;
1835
+ }
1836
+
1837
+ PyList_Append (gtids , gtid );
1838
+
1839
+ Py_BEGIN_ALLOW_THREADS
1840
+ r = mysql_session_track_get_next (& (self -> connection ), SESSION_TRACK_GTIDS , & data , & length );
1841
+ Py_END_ALLOW_THREADS
1842
+ }
1843
+
1844
+ return gtids ;
1845
+ }
1846
+ #endif
1847
+
1805
1848
static char _mysql_ConnectionObject_select_db__doc__ [] =
1806
1849
"Causes the database specified by db to become the default\n\
1807
1850
(current) database on the connection specified by mysql. In subsequent\n\
@@ -2222,6 +2265,14 @@ static PyMethodDef _mysql_ConnectionObject_methods[] = {
2222
2265
METH_NOARGS ,
2223
2266
_mysql_ConnectionObject_read_query_result__doc__ ,
2224
2267
},
2268
+ #if MYSQL_VERSION_ID >= 50707
2269
+ {
2270
+ "get_session_track_gtids" ,
2271
+ (PyCFunction )_mysql_ConnectionObject_get_session_track_gtids ,
2272
+ METH_NOARGS ,
2273
+ _mysql_ConnectionObject_get_session_track_gtids__doc__ ,
2274
+ },
2275
+ #endif
2225
2276
{
2226
2277
"select_db" ,
2227
2278
(PyCFunction )_mysql_ConnectionObject_select_db ,
0 commit comments