Skip to content

Commit 74e445d

Browse files
committed
wait as late as we can to mark the connection active
1 parent 0f2f3c0 commit 74e445d

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

ext/mysql2/client.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -431,13 +431,6 @@ static VALUE rb_mysql_client_query(int argc, VALUE * argv, VALUE self) {
431431
REQUIRE_OPEN_DB(wrapper);
432432
args.mysql = wrapper->client;
433433

434-
// see if this connection is still waiting on a result from a previous query
435-
if (wrapper->active == 0) {
436-
// mark this connection active
437-
wrapper->active = 1;
438-
} else {
439-
rb_raise(cMysql2Error, "This connection is still waiting for a result, try again once you have the result");
440-
}
441434

442435
defaults = rb_iv_get(self, "@query_options");
443436
if (rb_scan_args(argc, argv, "11", &args.sql, &opts) == 2) {
@@ -458,6 +451,14 @@ static VALUE rb_mysql_client_query(int argc, VALUE * argv, VALUE self) {
458451
args.sql = rb_str_export_to_enc(args.sql, conn_enc);
459452
#endif
460453

454+
// see if this connection is still waiting on a result from a previous query
455+
if (wrapper->active == 0) {
456+
// mark this connection active
457+
wrapper->active = 1;
458+
} else {
459+
rb_raise(cMysql2Error, "This connection is still waiting for a result, try again once you have the result");
460+
}
461+
461462
args.wrapper = wrapper;
462463
rb_rescue2(do_send_query, (VALUE)&args, disconnect_and_raise, self, rb_eException, (VALUE)0);
463464

0 commit comments

Comments
 (0)