-
Notifications
You must be signed in to change notification settings - Fork 0
Do not require an open connection for MySQL string escaping #1
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
base: use-vio-is-connected
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 🥇
@@ -887,11 +887,11 @@ def run_gc | |||
end.not_to raise_error | |||
end | |||
|
|||
it "should require an open connection" do | |||
it "should not require an open connection" do |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
@@ -50,6 +52,12 @@ static ID intern_brackets, intern_merge, intern_merge_bang, intern_new_with_args | |||
rb_raise(cMysql2Error, "MySQL connection is already open"); \ | |||
} | |||
|
|||
#define REQUIRE_CONNECTED_ONCE(wrapper) \ | |||
REQUIRE_INITIALIZED(wrapper) \ | |||
if (!wrapper->client->server_version) { \ |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
40e3b86
to
b91dc5d
Compare
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 successfulconnect
.