Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add last_result_size to ruby connection #190

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions contrib/ruby/ext/trilogy-ruby/cext.c
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,8 @@ static VALUE rb_trilogy_server_status(VALUE self) { return LONG2FIX(get_open_ctx

static VALUE rb_trilogy_server_version(VALUE self) { return rb_str_new_cstr(get_open_ctx(self)->server_version); }

static VALUE rb_trilogy_last_result_size(VALUE self) { return rb_int_new(get_open_ctx(self)->conn.recv_buff_len); }

RUBY_FUNC_EXPORTED void Init_cext(void)
{
VALUE Trilogy = rb_const_get(rb_cObject, rb_intern("Trilogy"));
Expand Down Expand Up @@ -1161,6 +1163,7 @@ RUBY_FUNC_EXPORTED void Init_cext(void)
rb_define_method(Trilogy, "more_results_exist?", rb_trilogy_more_results_exist, 0);
rb_define_method(Trilogy, "next_result", rb_trilogy_next_result, 0);
rb_define_method(Trilogy, "set_server_option", rb_trilogy_set_server_option, 1);
rb_define_method(Trilogy, "last_result_size", rb_trilogy_last_result_size, 0);
rb_define_const(Trilogy, "TLS_VERSION_10", INT2NUM(TRILOGY_TLS_VERSION_10));
rb_define_const(Trilogy, "TLS_VERSION_11", INT2NUM(TRILOGY_TLS_VERSION_11));
rb_define_const(Trilogy, "TLS_VERSION_12", INT2NUM(TRILOGY_TLS_VERSION_12));
Expand Down
14 changes: 14 additions & 0 deletions contrib/ruby/test/client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,20 @@ def test_trilogy_set_server_option_with_invalid_option
assert_match(/1047: Unknown command/, e.message)
end

def test_trilogy_last_result_size
client = new_tcp_client
create_test_table(client)

client.query("INSERT INTO trilogy_test (int_test) VALUES ('4')")
client.query("INSERT INTO trilogy_test (int_test) VALUES ('3')")

result = client.query("SELECT id, int_test FROM trilogy_test")
result_size = client.last_result_size

assert_equal [1, 4, 2, 3], result.rows.flatten
assert_includes 150..170, result_size, "Expected last_result_size to be between 150 and 170, but was #{result_size}"
end

def test_trilogy_set_server_option_multi_statement
# Start with multi_statement disabled, enable it during connection
client = new_tcp_client
Expand Down