Skip to content

Commit

Permalink
Allow disabling multi_results capability
Browse files Browse the repository at this point in the history
#57 set multi-results capability
as a default.

To safely upgrade to the latest version of Trilogy, we want to turn that
option off and then turn it on one cluster at a time.

This commit removes the multi-results capability default from
TRILOGY_CAPABILITIES_CLIENT but will still set it unless the client is
initialized with `multi_results: false`.

We had an option to enable
multi results, but removed it in
#68 because the option was always
a no-op. This PR adds the option back, with some modification.

Co-authored-by: Daniel Colson <composerinteralia@github.com>
  • Loading branch information
luanzeba and composerinteralia committed May 17, 2023
1 parent c024516 commit be0fa65
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
7 changes: 6 additions & 1 deletion contrib/ruby/ext/trilogy-ruby/cext.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static ID id_socket, id_host, id_port, id_username, id_password, id_found_rows,
id_write_timeout, id_keepalive_enabled, id_keepalive_idle, id_keepalive_interval, id_keepalive_count,
id_ivar_affected_rows, id_ivar_fields, id_ivar_last_insert_id, id_ivar_rows, id_ivar_query_time, id_password,
id_database, id_ssl_ca, id_ssl_capath, id_ssl_cert, id_ssl_cipher, id_ssl_crl, id_ssl_crlpath, id_ssl_key,
id_ssl_mode, id_tls_ciphersuites, id_tls_min_version, id_tls_max_version, id_multi_statement,
id_ssl_mode, id_tls_ciphersuites, id_tls_min_version, id_tls_max_version, id_multi_statement, id_multi_result,
id_from_code, id_from_errno, id_connection_options;

struct trilogy_ctx {
Expand Down Expand Up @@ -455,6 +455,10 @@ static VALUE rb_trilogy_initialize(VALUE self, VALUE encoding, VALUE charset, VA
connopt.flags |= TRILOGY_CAPABILITIES_FOUND_ROWS;
}

if (rb_hash_aref(opts, ID2SYM(id_multi_result)) != Qfalse) {
connopt.flags |= TRILOGY_CAPABILITIES_MULTI_RESULTS;
}

if (RTEST(rb_hash_aref(opts, ID2SYM(id_multi_statement)))) {
connopt.flags |= TRILOGY_CAPABILITIES_MULTI_STATEMENTS;
}
Expand Down Expand Up @@ -1127,6 +1131,7 @@ RUBY_FUNC_EXPORTED void Init_cext()
id_tls_min_version = rb_intern("tls_min_version");
id_tls_max_version = rb_intern("tls_max_version");
id_multi_statement = rb_intern("multi_statement");
id_multi_result = rb_intern("multi_result");
id_from_code = rb_intern("from_code");
id_from_errno = rb_intern("from_errno");
id_ivar_affected_rows = rb_intern("@affected_rows");
Expand Down
12 changes: 12 additions & 0 deletions contrib/ruby/test/client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,18 @@ def test_trilogy_multiple_results_doesnt_allow_multi_statement_queries
end
end

def test_trilogy_multiple_results_disabled
client = new_tcp_client(multi_result: false)
create_test_table(client)

client.query("DROP PROCEDURE IF EXISTS test_proc")
client.query("CREATE PROCEDURE test_proc() BEGIN SELECT 1 AS 'set_1'; SELECT 2 AS 'set_2'; END")

assert_raises(Trilogy::ProtocolError) do
client.query("CALL test_proc()")
end
end

def test_trilogy_next_result_raises_when_response_has_error
client = new_tcp_client(multi_statement: true)
create_test_table(client)
Expand Down
3 changes: 1 addition & 2 deletions inc/trilogy/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ typedef enum {
/* A convenience bitmask with common client capabilities set. */
TRILOGY_CAPABILITIES_CLIENT = (TRILOGY_CAPABILITIES_PROTOCOL_41 | TRILOGY_CAPABILITIES_SECURE_CONNECTION |
TRILOGY_CAPABILITIES_DEPRECATE_EOF | TRILOGY_CAPABILITIES_SESSION_TRACK |
TRILOGY_CAPABILITIES_PLUGIN_AUTH | TRILOGY_CAPABILITIES_TRANSACTIONS |
TRILOGY_CAPABILITIES_MULTI_RESULTS)
TRILOGY_CAPABILITIES_PLUGIN_AUTH | TRILOGY_CAPABILITIES_TRANSACTIONS)
} TRILOGY_CAPABILITIES_t;

#define TRILOGY_SERVER_STATUS(XX) \
Expand Down
16 changes: 8 additions & 8 deletions test/protocol/building/auth_packet_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ TEST test_build_auth_packet_native()
err = trilogy_build_auth_packet(&builder, user, NULL, 0, NULL, 45, "mysql_native_password", scramble, 0);
ASSERT_OK(err);

static const uint8_t expected[] = {0x3c, 0x00, 0x00, 0x01, 0x00, 0xa2, 0x8a, 0x01, 0xff, 0xff, 0xff, 0x00, 0x2d,
static const uint8_t expected[] = {0x3c, 0x00, 0x00, 0x01, 0x00, 0xa2, 0x88, 0x01, 0xff, 0xff, 0xff, 0x00, 0x2d,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72, 0x6f, 0x6f,
0x74, 0x00, 0x00, 0x6d, 0x79, 0x73, 0x71, 0x6c, 0x5f, 0x6e, 0x61, 0x74, 0x69,
Expand Down Expand Up @@ -57,7 +57,7 @@ TEST test_build_auth_packet_sha2()
err = trilogy_build_auth_packet(&builder, user, NULL, 0, NULL, 45, "caching_sha2_password", scramble, 0);
ASSERT_OK(err);

static const uint8_t expected[] = {0x3c, 0x00, 0x00, 0x01, 0x00, 0xa2, 0x8a, 0x01, 0xff, 0xff, 0xff, 0x00, 0x2d,
static const uint8_t expected[] = {0x3c, 0x00, 0x00, 0x01, 0x00, 0xa2, 0x88, 0x01, 0xff, 0xff, 0xff, 0x00, 0x2d,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72, 0x6f, 0x6f,
0x74, 0x00, 0x00, 0x63, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x67, 0x5f, 0x73, 0x68,
Expand Down Expand Up @@ -87,7 +87,7 @@ TEST test_build_auth_packet_native_with_pass()
ASSERT_OK(err);

static const uint8_t expected[] = {
0x50, 0x00, 0x00, 0x01, 0x00, 0xa2, 0x8a, 0x01, 0xff, 0xff, 0xff, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x00,
0x50, 0x00, 0x00, 0x01, 0x00, 0xa2, 0x88, 0x01, 0xff, 0xff, 0xff, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x72, 0x6f, 0x6f, 0x74, 0x00, 0x14, 0xdd, 0x50, 0x11, 0x25, 0x22, 0x39, 0x2e, 0x81, 0xd0,
0x48, 0x7c, 0x68, 0x95, 0x08, 0x67, 0x15, 0xf2, 0x93, 0xe7, 0x34, 0x6d, 0x79, 0x73, 0x71, 0x6c, 0x5f,
Expand Down Expand Up @@ -117,7 +117,7 @@ TEST test_build_auth_packet_sha2_with_pass()
ASSERT_OK(err);

static const uint8_t expected[] = {
0x5c, 0x00, 0x00, 0x01, 0x00, 0xa2, 0x8a, 0x01, 0xff, 0xff, 0xff, 0x00, 0x2d, 0x00, 0x00, 0x00,
0x5c, 0x00, 0x00, 0x01, 0x00, 0xa2, 0x88, 0x01, 0xff, 0xff, 0xff, 0x00, 0x2d, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x72, 0x6f, 0x6f, 0x74, 0x00, 0x20, 0xfc, 0x30, 0xeb, 0x5a, 0x4b, 0x6d,
0x62, 0x82, 0x52, 0x0d, 0x8a, 0x78, 0x7b, 0xd3, 0xcf, 0xc8, 0x46, 0xb8, 0x7f, 0x2e, 0x31, 0x14,
Expand Down Expand Up @@ -148,7 +148,7 @@ TEST test_build_auth_packet_native_with_database()
ASSERT_OK(err);

static const uint8_t expected[] = {
0x41, 0x00, 0x00, 0x01, 0x08, 0xa2, 0x8a, 0x01, 0xff, 0xff, 0xff, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x00,
0x41, 0x00, 0x00, 0x01, 0x08, 0xa2, 0x88, 0x01, 0xff, 0xff, 0xff, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x72, 0x6f, 0x6f, 0x74, 0x00, 0x00, 0x74, 0x65, 0x73, 0x74, 0x00, 0x6d, 0x79, 0x73, 0x71, 0x6c, 0x5f, 0x6e,
0x61, 0x74, 0x69, 0x76, 0x65, 0x5f, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x00};
Expand Down Expand Up @@ -177,7 +177,7 @@ TEST test_build_auth_packet_sha2_with_database()
ASSERT_OK(err);

static const uint8_t expected[] = {
0x41, 0x00, 0x00, 0x01, 0x08, 0xa2, 0x8a, 0x01, 0xff, 0xff, 0xff, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x00,
0x41, 0x00, 0x00, 0x01, 0x08, 0xa2, 0x88, 0x01, 0xff, 0xff, 0xff, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x72, 0x6f, 0x6f, 0x74, 0x00, 0x00, 0x74, 0x65, 0x73, 0x74, 0x00, 0x63, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x67,
0x5f, 0x73, 0x68, 0x61, 0x32, 0x5f, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x00};
Expand Down Expand Up @@ -206,7 +206,7 @@ TEST test_build_auth_packet_native_with_pass_and_database()
ASSERT_OK(err);

static const uint8_t expected[] = {
0x55, 0x00, 0x00, 0x01, 0x08, 0xa2, 0x8a, 0x01, 0xff, 0xff, 0xff, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x00,
0x55, 0x00, 0x00, 0x01, 0x08, 0xa2, 0x88, 0x01, 0xff, 0xff, 0xff, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x72, 0x6f, 0x6f, 0x74, 0x00, 0x14, 0xdd, 0x50, 0x11, 0x25, 0x22, 0x39, 0x2e, 0x81, 0xd0, 0x48, 0x7c, 0x68,
0x95, 0x08, 0x67, 0x15, 0xf2, 0x93, 0xe7, 0x34, 0x74, 0x65, 0x73, 0x74, 0x00, 0x6d, 0x79, 0x73, 0x71, 0x6c,
Expand Down Expand Up @@ -236,7 +236,7 @@ TEST test_build_auth_packet_sha2_with_pass_and_database()
ASSERT_OK(err);

static const uint8_t expected[] = {
0x61, 0x00, 0x00, 0x01, 0x08, 0xa2, 0x8a, 0x01, 0xff, 0xff, 0xff, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x00,
0x61, 0x00, 0x00, 0x01, 0x08, 0xa2, 0x88, 0x01, 0xff, 0xff, 0xff, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x72, 0x6f, 0x6f, 0x74, 0x00, 0x20, 0xfc, 0x30, 0xeb, 0x5a, 0x4b, 0x6d, 0x62, 0x82, 0x52,
0x0d, 0x8a, 0x78, 0x7b, 0xd3, 0xcf, 0xc8, 0x46, 0xb8, 0x7f, 0x2e, 0x31, 0x14, 0x67, 0x57, 0x84, 0xee,
Expand Down

0 comments on commit be0fa65

Please sign in to comment.