@@ -57,6 +57,17 @@ static ID intern_brackets, intern_merge, intern_merge_bang, intern_new_with_args
57
57
#define MYSQL_LINK_VERSION MYSQL_SERVER_VERSION
58
58
#endif
59
59
60
+ /*
61
+ * mariadb-connector-c defines CLIENT_SESSION_TRACKING and SESSION_TRACK_TRANSACTION_TYPE
62
+ * while mysql-connector-c defines CLIENT_SESSION_TRACK and SESSION_TRACK_TRANSACTION_STATE
63
+ * This is a hack to take care of both clients.
64
+ */
65
+ #if defined(CLIENT_SESSION_TRACK )
66
+ #elif defined(CLIENT_SESSION_TRACKING )
67
+ #define CLIENT_SESSION_TRACK CLIENT_SESSION_TRACKING
68
+ #define SESSION_TRACK_TRANSACTION_STATE SESSION_TRACK_TRANSACTION_TYPE
69
+ #endif
70
+
60
71
/*
61
72
* compatibility with mysql-connector-c 6.1.x, and with MySQL 5.7.3 - 5.7.10.
62
73
*/
@@ -1022,6 +1033,36 @@ static VALUE rb_mysql_client_last_id(VALUE self) {
1022
1033
return ULL2NUM (mysql_insert_id (wrapper -> client ));
1023
1034
}
1024
1035
1036
+ /* call-seq:
1037
+ * client.session_track
1038
+ *
1039
+ * Returns information about changes to the session state on the server.
1040
+ */
1041
+ static VALUE rb_mysql_client_session_track (VALUE self , VALUE type ) {
1042
+ #ifdef CLIENT_SESSION_TRACK
1043
+ const char * data ;
1044
+ size_t length ;
1045
+ my_ulonglong retVal ;
1046
+ GET_CLIENT (self );
1047
+
1048
+ REQUIRE_CONNECTED (wrapper );
1049
+ retVal = mysql_session_track_get_first (wrapper -> client , NUM2INT (type ), & data , & length );
1050
+ if (retVal != 0 ) {
1051
+ return Qnil ;
1052
+ }
1053
+ VALUE rbAry = rb_ary_new ();
1054
+ VALUE rbFirst = rb_str_new (data , length );
1055
+ rb_ary_push (rbAry , rbFirst );
1056
+ while (mysql_session_track_get_next (wrapper -> client , NUM2INT (type ), & data , & length ) == 0 ) {
1057
+ VALUE rbNext = rb_str_new (data , length );
1058
+ rb_ary_push (rbAry , rbNext );
1059
+ }
1060
+ return rbAry ;
1061
+ #else
1062
+ return Qnil ;
1063
+ #endif
1064
+ }
1065
+
1025
1066
/* call-seq:
1026
1067
* client.affected_rows
1027
1068
*
@@ -1442,6 +1483,7 @@ void init_mysql2_client() {
1442
1483
rb_define_method (cMysql2Client , "query_info_string" , rb_mysql_info , 0 );
1443
1484
rb_define_method (cMysql2Client , "ssl_cipher" , rb_mysql_get_ssl_cipher , 0 );
1444
1485
rb_define_method (cMysql2Client , "encoding" , rb_mysql_client_encoding , 0 );
1486
+ rb_define_method (cMysql2Client , "session_track" , rb_mysql_client_session_track , 1 );
1445
1487
1446
1488
rb_define_private_method (cMysql2Client , "connect_timeout=" , set_connect_timeout , 1 );
1447
1489
rb_define_private_method (cMysql2Client , "read_timeout=" , set_read_timeout , 1 );
@@ -1614,6 +1656,17 @@ void init_mysql2_client() {
1614
1656
INT2NUM (0 ));
1615
1657
#endif
1616
1658
1659
+ #ifdef CLIENT_SESSION_TRACK
1660
+ rb_const_set (cMysql2Client , rb_intern ("SESSION_TRACK" ), INT2NUM (CLIENT_SESSION_TRACK ));
1661
+ /* From mysql_com.h -- but stable from at least 5.7.4 through 8.0.20 */
1662
+ rb_const_set (cMysql2Client , rb_intern ("SESSION_TRACK_SYSTEM_VARIABLES" ), INT2NUM (SESSION_TRACK_SYSTEM_VARIABLES ));
1663
+ rb_const_set (cMysql2Client , rb_intern ("SESSION_TRACK_SCHEMA" ), INT2NUM (SESSION_TRACK_SCHEMA ));
1664
+ rb_const_set (cMysql2Client , rb_intern ("SESSION_TRACK_STATE_CHANGE" ), INT2NUM (SESSION_TRACK_STATE_CHANGE ));
1665
+ rb_const_set (cMysql2Client , rb_intern ("SESSION_TRACK_GTIDS" ), INT2NUM (SESSION_TRACK_GTIDS ));
1666
+ rb_const_set (cMysql2Client , rb_intern ("SESSION_TRACK_TRANSACTION_CHARACTERISTICS" ), INT2NUM (SESSION_TRACK_TRANSACTION_CHARACTERISTICS ));
1667
+ rb_const_set (cMysql2Client , rb_intern ("SESSION_TRACK_TRANSACTION_STATE" ), INT2NUM (SESSION_TRACK_TRANSACTION_STATE ));
1668
+ #endif
1669
+
1617
1670
#if defined(FULL_SSL_MODE_SUPPORT ) // MySQL 5.7.11 and above
1618
1671
rb_const_set (cMysql2Client , rb_intern ("SSL_MODE_DISABLED" ), INT2NUM (SSL_MODE_DISABLED ));
1619
1672
rb_const_set (cMysql2Client , rb_intern ("SSL_MODE_PREFERRED" ), INT2NUM (SSL_MODE_PREFERRED ));
0 commit comments