@@ -38,10 +38,12 @@ static ID intern_brackets, intern_merge, intern_merge_bang, intern_new_with_args
38
38
#define CONNECTED (wrapper ) (wrapper->client->net.pvio != NULL && wrapper->client->net.fd != -1 && VIO_IS_CONNECTED(wrapper))
39
39
#endif
40
40
41
+ #define MYSQL_CLIENT_NOT_CONNECTED_STR "MySQL client is not connected"
42
+
41
43
#define REQUIRE_CONNECTED (wrapper ) \
42
44
REQUIRE_INITIALIZED(wrapper) \
43
45
if (!CONNECTED(wrapper) && !wrapper->reconnect_enabled) { \
44
- rb_raise(cMysql2Error, "MySQL client is not connected" ); \
46
+ rb_raise(cMysql2Error, MYSQL_CLIENT_NOT_CONNECTED_STR ); \
45
47
}
46
48
47
49
#define REQUIRE_NOT_CONNECTED (wrapper ) \
@@ -50,6 +52,12 @@ static ID intern_brackets, intern_merge, intern_merge_bang, intern_new_with_args
50
52
rb_raise(cMysql2Error, "MySQL connection is already open"); \
51
53
}
52
54
55
+ #define REQUIRE_CONNECTED_ONCE (wrapper ) \
56
+ REQUIRE_INITIALIZED(wrapper) \
57
+ if (!wrapper->client->server_version) { \
58
+ rb_raise(cMysql2Error, MYSQL_CLIENT_NOT_CONNECTED_STR); \
59
+ }
60
+
53
61
/*
54
62
* compatability with mysql-connector-c, where LIBMYSQL_VERSION is the correct
55
63
* variable to use, but MYSQL_SERVER_VERSION gives the correct numbers when
@@ -819,7 +827,7 @@ static VALUE rb_mysql_client_real_escape(VALUE self, VALUE str) {
819
827
rb_encoding * conn_enc ;
820
828
GET_CLIENT (self );
821
829
822
- REQUIRE_CONNECTED (wrapper );
830
+ REQUIRE_CONNECTED_ONCE (wrapper );
823
831
Check_Type (str , T_STRING );
824
832
default_internal_enc = rb_default_internal_encoding ();
825
833
conn_enc = rb_to_encoding (wrapper -> encoding );
0 commit comments