diff --git a/ext/mysql2/client.c b/ext/mysql2/client.c index 8acf08219..b598fdc47 100644 --- a/ext/mysql2/client.c +++ b/ext/mysql2/client.c @@ -1036,7 +1036,7 @@ static VALUE rb_mysql_client_session_track(VALUE self, VALUE type) { REQUIRE_CONNECTED(wrapper); retVal = mysql_session_track_get_first(wrapper->client, NUM2INT(type), &data, &length); if (retVal != 0) { - rb_raise_mysql2_error(wrapper); + return Qnil; } VALUE rbAry = rb_ary_new(); VALUE rbFirst = rb_str_new(data, length); diff --git a/spec/mysql2/client_spec.rb b/spec/mysql2/client_spec.rb index 5a3b8a242..3c7a24550 100644 --- a/spec/mysql2/client_spec.rb +++ b/spec/mysql2/client_spec.rb @@ -1026,6 +1026,46 @@ def run_gc expect(@client).to respond_to(:ping) end + context "session_track" do + before(:each) do + @client.query("SET @@SESSION.session_track_system_variables='*';") + end + + it "returns changes system variables for SESSION_TRACK_SYSTEM_VARIABLES" do + @client.query("SET @@SESSION.session_track_state_change=ON;") + res = @client.session_track(Mysql2::Client::SESSION_TRACK_SYSTEM_VARIABLES) + expect(res).to eq(["session_track_state_change", "ON"]) + end + + it "returns database name for SESSION_TRACK_SCHEMA" do + @client.query("USE information_schema") + res = @client.session_track(Mysql2::Client::SESSION_TRACK_SCHEMA) + expect(res).to eq(["information_schema"]) + end + + it "returns multiple session track type values when available" do + @client.query("SET @@SESSION.session_track_transaction_info='CHARACTERISTICS'") + + res = @client.session_track(Mysql2::Client::SESSION_TRACK_TRANSACTION_STATE) + expect(res).to eq(["________"]) + + res = @client.session_track(Mysql2::Client::SESSION_TRACK_TRANSACTION_CHARACTERISTICS) + expect(res).to eq([""]) + + res = @client.session_track(Mysql2::Client::SESSION_TRACK_STATE_CHANGE) + expect(res).to be_nil + + res = @client.session_track(Mysql2::Client::SESSION_TRACK_SYSTEM_VARIABLES) + expect(res).to eq(["session_track_transaction_info", "CHARACTERISTICS"]) + end + + it "returns empty array if session track type not found" do + @client.query("SET @@SESSION.session_track_state_change=ON;") + res = @client.session_track(Mysql2::Client::SESSION_TRACK_TRANSACTION_CHARACTERISTICS) + expect(res).to be_nil + end + end + context "select_db" do before(:each) do 2.times do |i|