Skip to content

Ruby binding throws TRILOGY_INVALID_SEQUENCE_ID when a multi-statement is followed by another query #195

Open
@iandelahorne

Description

👋 Hello! We discovered that the ruby binding will throw TRILOGY_INVALID_SEQUENCE_ID when executing a multi-statement query followed directly another query, without fetching all results with next_result.

For example, the following snippet works fine:

client.query("SELECT 1; SELECT 2;")
client.next_result while client.more_results_exist?
client.query("SELECT 3")

This next snippet, however, throws TRILOGY_INVALID_SEQUENCE_ID

client.query("SELECT 1; SELECT 2;")
client.query("SELECT 3")

Here's a script to reproduce:

require "trilogy"

config = { host: "127.0.01", port: 3306, username: "root", password: "", ssl: false, multi_statement: true}
client = Trilogy.new config

# OK
client.query("SELECT 1; SELECT 2;")
client.next_result while client.more_results_exist?
client.query("SELECT 3")

# Not OK
client.query("SELECT 1; SELECT 2;")
client.query("SELECT 3")

Running this yields:

$ ruby test.rb
test.rb:13:in `query': trilogy_query_recv: TRILOGY_INVALID_SEQUENCE_ID (Trilogy::QueryError)
	from test.rb:13:in `<main>'

We're seeing this with Trilogy 2.8.1 against MySQL 8.3.0 on OSX using Ruby 3.3.2 (ruby 3.3.2 (2024-05-30 revision e5a195edf6) [arm64-darwin23])

From what I can tell (i'm not familiar with the codebase and it's been a minute since I've written C) it seems that something isn't getting reset correctly when client.query is called and trilogy_packet_parser_execute() isn't agreeing with it's current state vs what is coming in off the wire.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions