Skip to content

Conversation

csfrancis
Copy link
Owner

@csfrancis csfrancis commented Mar 12, 2019

The detection of closed connections was made more robust by brianmario#1022. As a result, in situations where the connection was actually closed, calls to rb_mysql_client_real_escape are now raising an exception when they would not have before.

This modifies the behaviour of the mysql2 gem to not require an open connection to perform an underlying call to mysql_real_escape_string. This is effectively emulating the same behaviour as before brianmario#1022.

I tried to write a test for the negative case that would raise when we haven't connected at least once. I could not come up with a way to create a Mysql2::Client instance without performing a successful connect.

Copy link

@jeremycole jeremycole left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 🥇

end

it "should require an open connection" do
it "should not require an open connection" do
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we change this to allows to escape on a closed connection?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like it's basically the same thing. It's running in the #escape context.


#define REQUIRE_CONNECTED_ONCE(wrapper) \
REQUIRE_INITIALIZED(wrapper) \
if (!wrapper->client->server_version) { \
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some others places in client.c use wrapper->server_version, is there a difference with wrapper->client->server_version?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my precursory look, it appears that wrapper->server_version is used to cache the response of mysql_get_server_version, which is an integer. wrapper->client->server_version should be a string representation of the server version that is set by the mysql client library upon connection.

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

None yet

3 participants