|
16 | 16 |
|
17 | 17 | VALUE cMysql2Client;
|
18 | 18 | extern VALUE mMysql2, cMysql2Error;
|
19 |
| -static VALUE sym_id, sym_version, sym_async, sym_symbolize_keys, sym_as, sym_array, sym_stream; |
| 19 | +static VALUE sym_id, sym_version, sym_header_version, sym_async, sym_symbolize_keys, sym_as, sym_array, sym_stream; |
20 | 20 | static ID intern_merge, intern_merge_bang, intern_error_number_eql, intern_sql_state_eql;
|
21 | 21 |
|
22 | 22 | #ifndef HAVE_RB_HASH_DUP
|
@@ -287,7 +287,7 @@ static VALUE rb_mysql_client_escape(RB_MYSQL_UNUSED VALUE klass, VALUE str) {
|
287 | 287 | oldLen = RSTRING_LEN(str);
|
288 | 288 | newStr = xmalloc(oldLen*2+1);
|
289 | 289 |
|
290 |
| - newLen = mysql_escape_string((char *)newStr, StringValuePtr(str), oldLen); |
| 290 | + newLen = mysql_escape_string((char *)newStr, RSTRING_PTR(str), oldLen); |
291 | 291 | if (newLen == oldLen) {
|
292 | 292 | /* no need to return a new ruby string if nothing changed */
|
293 | 293 | xfree(newStr);
|
@@ -337,13 +337,13 @@ static VALUE rb_connect(VALUE self, VALUE user, VALUE pass, VALUE host, VALUE po
|
337 | 337 | VALUE rv;
|
338 | 338 | GET_CLIENT(self);
|
339 | 339 |
|
340 |
| - args.host = NIL_P(host) ? NULL : StringValuePtr(host); |
341 |
| - args.unix_socket = NIL_P(socket) ? NULL : StringValuePtr(socket); |
342 |
| - args.port = NIL_P(port) ? 0 : NUM2INT(port); |
343 |
| - args.user = NIL_P(user) ? NULL : StringValuePtr(user); |
344 |
| - args.passwd = NIL_P(pass) ? NULL : StringValuePtr(pass); |
345 |
| - args.db = NIL_P(database) ? NULL : StringValuePtr(database); |
346 |
| - args.mysql = wrapper->client; |
| 340 | + args.host = NIL_P(host) ? NULL : StringValueCStr(host); |
| 341 | + args.unix_socket = NIL_P(socket) ? NULL : StringValueCStr(socket); |
| 342 | + args.port = NIL_P(port) ? 0 : NUM2INT(port); |
| 343 | + args.user = NIL_P(user) ? NULL : StringValueCStr(user); |
| 344 | + args.passwd = NIL_P(pass) ? NULL : StringValueCStr(pass); |
| 345 | + args.db = NIL_P(database) ? NULL : StringValueCStr(database); |
| 346 | + args.mysql = wrapper->client; |
347 | 347 | args.client_flag = NUM2ULONG(flags);
|
348 | 348 |
|
349 | 349 | if (wrapper->connect_timeout)
|
@@ -669,7 +669,7 @@ static VALUE rb_mysql_client_query(int argc, VALUE * argv, VALUE self) {
|
669 | 669 | /* ensure the string is in the encoding the connection is expecting */
|
670 | 670 | args.sql = rb_str_export_to_enc(args.sql, conn_enc);
|
671 | 671 | #endif
|
672 |
| - args.sql_ptr = StringValuePtr(args.sql); |
| 672 | + args.sql_ptr = RSTRING_PTR(args.sql); |
673 | 673 | args.sql_len = RSTRING_LEN(args.sql);
|
674 | 674 |
|
675 | 675 | /* see if this connection is still waiting on a result from a previous query */
|
@@ -736,9 +736,14 @@ static VALUE rb_mysql_client_real_escape(VALUE self, VALUE str) {
|
736 | 736 | oldLen = RSTRING_LEN(str);
|
737 | 737 | newStr = xmalloc(oldLen*2+1);
|
738 | 738 |
|
739 |
| - newLen = mysql_real_escape_string(wrapper->client, (char *)newStr, StringValuePtr(str), oldLen); |
| 739 | + newLen = mysql_real_escape_string(wrapper->client, (char *)newStr, RSTRING_PTR(str), oldLen); |
740 | 740 | if (newLen == oldLen) {
|
741 | 741 | /* no need to return a new ruby string if nothing changed */
|
| 742 | +#ifdef HAVE_RUBY_ENCODING_H |
| 743 | + if (default_internal_enc) { |
| 744 | + str = rb_str_export_to_enc(str, default_internal_enc); |
| 745 | + } |
| 746 | +#endif |
742 | 747 | xfree(newStr);
|
743 | 748 | return str;
|
744 | 749 | } else {
|
@@ -800,17 +805,17 @@ static VALUE _mysql_client_options(VALUE self, int opt, VALUE value) {
|
800 | 805 | break;
|
801 | 806 |
|
802 | 807 | case MYSQL_READ_DEFAULT_FILE:
|
803 |
| - charval = (const char *)StringValuePtr(value); |
| 808 | + charval = (const char *)StringValueCStr(value); |
804 | 809 | retval = charval;
|
805 | 810 | break;
|
806 | 811 |
|
807 | 812 | case MYSQL_READ_DEFAULT_GROUP:
|
808 |
| - charval = (const char *)StringValuePtr(value); |
| 813 | + charval = (const char *)StringValueCStr(value); |
809 | 814 | retval = charval;
|
810 | 815 | break;
|
811 | 816 |
|
812 | 817 | case MYSQL_INIT_COMMAND:
|
813 |
| - charval = (const char *)StringValuePtr(value); |
| 818 | + charval = (const char *)StringValueCStr(value); |
814 | 819 | retval = charval;
|
815 | 820 | break;
|
816 | 821 |
|
@@ -843,30 +848,23 @@ static VALUE _mysql_client_options(VALUE self, int opt, VALUE value) {
|
843 | 848 | *
|
844 | 849 | * Returns a string that represents the client library version.
|
845 | 850 | */
|
846 |
| -static VALUE rb_mysql_client_info(VALUE self) { |
847 |
| - VALUE version, client_info; |
848 |
| -#ifdef HAVE_RUBY_ENCODING_H |
849 |
| - rb_encoding *default_internal_enc; |
850 |
| - rb_encoding *conn_enc; |
851 |
| - GET_CLIENT(self); |
852 |
| -#endif |
853 |
| - version = rb_hash_new(); |
| 851 | +static VALUE rb_mysql_client_info(RB_MYSQL_UNUSED VALUE klass) { |
| 852 | + VALUE version_info, version, header_version; |
| 853 | + version_info = rb_hash_new(); |
854 | 854 |
|
855 |
| -#ifdef HAVE_RUBY_ENCODING_H |
856 |
| - default_internal_enc = rb_default_internal_encoding(); |
857 |
| - conn_enc = rb_to_encoding(wrapper->encoding); |
858 |
| -#endif |
| 855 | + version = rb_str_new2(mysql_get_client_info()); |
| 856 | + header_version = rb_str_new2(MYSQL_LINK_VERSION); |
859 | 857 |
|
860 |
| - rb_hash_aset(version, sym_id, LONG2NUM(mysql_get_client_version())); |
861 |
| - client_info = rb_str_new2(mysql_get_client_info()); |
862 | 858 | #ifdef HAVE_RUBY_ENCODING_H
|
863 |
| - rb_enc_associate(client_info, conn_enc); |
864 |
| - if (default_internal_enc) { |
865 |
| - client_info = rb_str_export_to_enc(client_info, default_internal_enc); |
866 |
| - } |
| 859 | + rb_enc_associate(version, rb_usascii_encoding()); |
| 860 | + rb_enc_associate(header_version, rb_usascii_encoding()); |
867 | 861 | #endif
|
868 |
| - rb_hash_aset(version, sym_version, client_info); |
869 |
| - return version; |
| 862 | + |
| 863 | + rb_hash_aset(version_info, sym_id, LONG2NUM(mysql_get_client_version())); |
| 864 | + rb_hash_aset(version_info, sym_version, version); |
| 865 | + rb_hash_aset(version_info, sym_header_version, header_version); |
| 866 | + |
| 867 | + return version_info; |
870 | 868 | }
|
871 | 869 |
|
872 | 870 | /* call-seq:
|
@@ -907,14 +905,10 @@ static VALUE rb_mysql_client_server_info(VALUE self) {
|
907 | 905 | * Return the file descriptor number for this client.
|
908 | 906 | */
|
909 | 907 | static VALUE rb_mysql_client_socket(VALUE self) {
|
910 |
| - GET_CLIENT(self); |
911 | 908 | #ifndef _WIN32
|
912 |
| - { |
913 |
| - int fd_set_fd; |
914 |
| - REQUIRE_CONNECTED(wrapper); |
915 |
| - fd_set_fd = wrapper->client->net.fd; |
916 |
| - return INT2NUM(fd_set_fd); |
917 |
| - } |
| 909 | + GET_CLIENT(self); |
| 910 | + REQUIRE_CONNECTED(wrapper); |
| 911 | + return INT2NUM(wrapper->client->net.fd); |
918 | 912 | #else
|
919 | 913 | rb_raise(cMysql2Error, "Raw access to the mysql file descriptor isn't supported on Windows");
|
920 | 914 | #endif
|
@@ -987,7 +981,7 @@ static VALUE rb_mysql_client_select_db(VALUE self, VALUE db)
|
987 | 981 | REQUIRE_CONNECTED(wrapper);
|
988 | 982 |
|
989 | 983 | args.mysql = wrapper->client;
|
990 |
| - args.db = StringValuePtr(db); |
| 984 | + args.db = StringValueCStr(db); |
991 | 985 |
|
992 | 986 | if (rb_thread_call_without_gvl(nogvl_select_db, &args, RUBY_UBF_IO, 0) == Qfalse)
|
993 | 987 | rb_raise_mysql2_error(wrapper);
|
@@ -1183,11 +1177,11 @@ static VALUE set_ssl_options(VALUE self, VALUE key, VALUE cert, VALUE ca, VALUE
|
1183 | 1177 | GET_CLIENT(self);
|
1184 | 1178 |
|
1185 | 1179 | mysql_ssl_set(wrapper->client,
|
1186 |
| - NIL_P(key) ? NULL : StringValuePtr(key), |
1187 |
| - NIL_P(cert) ? NULL : StringValuePtr(cert), |
1188 |
| - NIL_P(ca) ? NULL : StringValuePtr(ca), |
1189 |
| - NIL_P(capath) ? NULL : StringValuePtr(capath), |
1190 |
| - NIL_P(cipher) ? NULL : StringValuePtr(cipher)); |
| 1180 | + NIL_P(key) ? NULL : StringValueCStr(key), |
| 1181 | + NIL_P(cert) ? NULL : StringValueCStr(cert), |
| 1182 | + NIL_P(ca) ? NULL : StringValueCStr(ca), |
| 1183 | + NIL_P(capath) ? NULL : StringValueCStr(capath), |
| 1184 | + NIL_P(cipher) ? NULL : StringValueCStr(cipher)); |
1191 | 1185 |
|
1192 | 1186 | return self;
|
1193 | 1187 | }
|
@@ -1254,12 +1248,12 @@ void init_mysql2_client() {
|
1254 | 1248 | rb_define_alloc_func(cMysql2Client, allocate);
|
1255 | 1249 |
|
1256 | 1250 | rb_define_singleton_method(cMysql2Client, "escape", rb_mysql_client_escape, 1);
|
| 1251 | + rb_define_singleton_method(cMysql2Client, "info", rb_mysql_client_info, 0); |
1257 | 1252 |
|
1258 | 1253 | rb_define_method(cMysql2Client, "close", rb_mysql_client_close, 0);
|
1259 | 1254 | rb_define_method(cMysql2Client, "query", rb_mysql_client_query, -1);
|
1260 | 1255 | rb_define_method(cMysql2Client, "abandon_results!", rb_mysql_client_abandon_results, 0);
|
1261 | 1256 | rb_define_method(cMysql2Client, "escape", rb_mysql_client_real_escape, 1);
|
1262 |
| - rb_define_method(cMysql2Client, "info", rb_mysql_client_info, 0); |
1263 | 1257 | rb_define_method(cMysql2Client, "server_info", rb_mysql_client_server_info, 0);
|
1264 | 1258 | rb_define_method(cMysql2Client, "socket", rb_mysql_client_socket, 0);
|
1265 | 1259 | rb_define_method(cMysql2Client, "async_result", rb_mysql_client_async_result, 0);
|
@@ -1293,6 +1287,7 @@ void init_mysql2_client() {
|
1293 | 1287 |
|
1294 | 1288 | sym_id = ID2SYM(rb_intern("id"));
|
1295 | 1289 | sym_version = ID2SYM(rb_intern("version"));
|
| 1290 | + sym_header_version = ID2SYM(rb_intern("header_version")); |
1296 | 1291 | sym_async = ID2SYM(rb_intern("async"));
|
1297 | 1292 | sym_symbolize_keys = ID2SYM(rb_intern("symbolize_keys"));
|
1298 | 1293 | sym_as = ID2SYM(rb_intern("as"));
|
|
0 commit comments