@@ -19,12 +19,6 @@ extern VALUE mMysql2, cMysql2Error;
19
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_brackets , intern_merge , intern_merge_bang , intern_new_with_args ;
21
21
22
- #ifndef HAVE_RB_HASH_DUP
23
- VALUE rb_hash_dup (VALUE other ) {
24
- return rb_funcall (rb_cHash , intern_brackets , 1 , other );
25
- }
26
- #endif
27
-
28
22
#define REQUIRE_INITIALIZED (wrapper ) \
29
23
if (!wrapper->initialized) { \
30
24
rb_raise(cMysql2Error, "MySQL client is not initialized"); \
@@ -178,10 +172,8 @@ static VALUE rb_raise_mysql2_error(mysql_client_wrapper *wrapper) {
178
172
VALUE rb_sql_state = rb_tainted_str_new2 (mysql_sqlstate (wrapper -> client ));
179
173
VALUE e ;
180
174
181
- #ifdef HAVE_RUBY_ENCODING_H
182
175
rb_enc_associate (rb_error_msg , rb_utf8_encoding ());
183
176
rb_enc_associate (rb_sql_state , rb_usascii_encoding ());
184
- #endif
185
177
186
178
e = rb_funcall (cMysql2Error , intern_new_with_args , 4 ,
187
179
rb_error_msg ,
@@ -357,9 +349,7 @@ static VALUE rb_mysql_client_escape(RB_MYSQL_UNUSED VALUE klass, VALUE str) {
357
349
return str ;
358
350
} else {
359
351
rb_str = rb_str_new ((const char * )newStr , newLen );
360
- #ifdef HAVE_RUBY_ENCODING_H
361
352
rb_enc_copy (rb_str , str );
362
- #endif
363
353
xfree (newStr );
364
354
return rb_str ;
365
355
}
@@ -386,9 +376,7 @@ static VALUE rb_mysql_info(VALUE self) {
386
376
}
387
377
388
378
rb_str = rb_str_new2 (info );
389
- #ifdef HAVE_RUBY_ENCODING_H
390
379
rb_enc_associate (rb_str , rb_utf8_encoding ());
391
- #endif
392
380
393
381
return rb_str ;
394
382
}
@@ -406,9 +394,7 @@ static VALUE rb_mysql_get_ssl_cipher(VALUE self)
406
394
}
407
395
408
396
rb_str = rb_str_new2 (cipher );
409
- #ifdef HAVE_RUBY_ENCODING_H
410
397
rb_enc_associate (rb_str , rb_utf8_encoding ());
411
- #endif
412
398
413
399
return rb_str ;
414
400
}
@@ -762,12 +748,8 @@ static VALUE rb_query(VALUE self, VALUE sql, VALUE current) {
762
748
rb_iv_set (self , "@current_query_options" , current );
763
749
764
750
Check_Type (sql , T_STRING );
765
- #ifdef HAVE_RUBY_ENCODING_H
766
751
/* ensure the string is in the encoding the connection is expecting */
767
752
args .sql = rb_str_export_to_enc (sql , rb_to_encoding (wrapper -> encoding ));
768
- #else
769
- args .sql = sql ;
770
- #endif
771
753
args .sql_ptr = RSTRING_PTR (args .sql );
772
754
args .sql_len = RSTRING_LEN (args .sql );
773
755
args .wrapper = wrapper ;
@@ -804,42 +786,34 @@ static VALUE rb_mysql_client_real_escape(VALUE self, VALUE str) {
804
786
unsigned char * newStr ;
805
787
VALUE rb_str ;
806
788
unsigned long newLen , oldLen ;
807
- #ifdef HAVE_RUBY_ENCODING_H
808
789
rb_encoding * default_internal_enc ;
809
790
rb_encoding * conn_enc ;
810
- #endif
811
791
GET_CLIENT (self );
812
792
813
793
REQUIRE_CONNECTED (wrapper );
814
794
Check_Type (str , T_STRING );
815
- #ifdef HAVE_RUBY_ENCODING_H
816
795
default_internal_enc = rb_default_internal_encoding ();
817
796
conn_enc = rb_to_encoding (wrapper -> encoding );
818
797
/* ensure the string is in the encoding the connection is expecting */
819
798
str = rb_str_export_to_enc (str , conn_enc );
820
- #endif
821
799
822
800
oldLen = RSTRING_LEN (str );
823
801
newStr = xmalloc (oldLen * 2 + 1 );
824
802
825
803
newLen = mysql_real_escape_string (wrapper -> client , (char * )newStr , RSTRING_PTR (str ), oldLen );
826
804
if (newLen == oldLen ) {
827
805
/* no need to return a new ruby string if nothing changed */
828
- #ifdef HAVE_RUBY_ENCODING_H
829
806
if (default_internal_enc ) {
830
807
str = rb_str_export_to_enc (str , default_internal_enc );
831
808
}
832
- #endif
833
809
xfree (newStr );
834
810
return str ;
835
811
} else {
836
812
rb_str = rb_str_new ((const char * )newStr , newLen );
837
- #ifdef HAVE_RUBY_ENCODING_H
838
813
rb_enc_associate (rb_str , conn_enc );
839
814
if (default_internal_enc ) {
840
815
rb_str = rb_str_export_to_enc (rb_str , default_internal_enc );
841
816
}
842
- #endif
843
817
xfree (newStr );
844
818
return rb_str ;
845
819
}
@@ -950,10 +924,8 @@ static VALUE rb_mysql_client_info(RB_MYSQL_UNUSED VALUE klass) {
950
924
version = rb_str_new2 (mysql_get_client_info ());
951
925
header_version = rb_str_new2 (MYSQL_LINK_VERSION );
952
926
953
- #ifdef HAVE_RUBY_ENCODING_H
954
927
rb_enc_associate (version , rb_usascii_encoding ());
955
928
rb_enc_associate (header_version , rb_usascii_encoding ());
956
- #endif
957
929
958
930
rb_hash_aset (version_info , sym_id , LONG2NUM (mysql_get_client_version ()));
959
931
rb_hash_aset (version_info , sym_version , version );
@@ -969,27 +941,21 @@ static VALUE rb_mysql_client_info(RB_MYSQL_UNUSED VALUE klass) {
969
941
*/
970
942
static VALUE rb_mysql_client_server_info (VALUE self ) {
971
943
VALUE version , server_info ;
972
- #ifdef HAVE_RUBY_ENCODING_H
973
944
rb_encoding * default_internal_enc ;
974
945
rb_encoding * conn_enc ;
975
- #endif
976
946
GET_CLIENT (self );
977
947
978
948
REQUIRE_CONNECTED (wrapper );
979
- #ifdef HAVE_RUBY_ENCODING_H
980
949
default_internal_enc = rb_default_internal_encoding ();
981
950
conn_enc = rb_to_encoding (wrapper -> encoding );
982
- #endif
983
951
984
952
version = rb_hash_new ();
985
953
rb_hash_aset (version , sym_id , LONG2FIX (mysql_get_server_version (wrapper -> client )));
986
954
server_info = rb_str_new2 (mysql_get_server_info (wrapper -> client ));
987
- #ifdef HAVE_RUBY_ENCODING_H
988
955
rb_enc_associate (server_info , conn_enc );
989
956
if (default_internal_enc ) {
990
957
server_info = rb_str_export_to_enc (server_info , default_internal_enc );
991
958
}
992
- #endif
993
959
rb_hash_aset (version , sym_version , server_info );
994
960
return version ;
995
961
}
@@ -1176,7 +1142,6 @@ static VALUE rb_mysql_client_store_result(VALUE self)
1176
1142
return resultObj ;
1177
1143
}
1178
1144
1179
- #ifdef HAVE_RUBY_ENCODING_H
1180
1145
/* call-seq:
1181
1146
* client.encoding
1182
1147
*
@@ -1186,7 +1151,6 @@ static VALUE rb_mysql_client_encoding(VALUE self) {
1186
1151
GET_CLIENT (self );
1187
1152
return wrapper -> encoding ;
1188
1153
}
1189
- #endif
1190
1154
1191
1155
/* call-seq:
1192
1156
* client.automatic_close?
@@ -1272,17 +1236,14 @@ static VALUE set_write_timeout(VALUE self, VALUE value) {
1272
1236
1273
1237
static VALUE set_charset_name (VALUE self , VALUE value ) {
1274
1238
char * charset_name ;
1275
- #ifdef HAVE_RUBY_ENCODING_H
1276
1239
const struct mysql2_mysql_enc_name_to_rb_map * mysql2rb ;
1277
1240
rb_encoding * enc ;
1278
1241
VALUE rb_enc ;
1279
- #endif
1280
1242
GET_CLIENT (self );
1281
1243
1282
1244
Check_Type (value , T_STRING );
1283
1245
charset_name = RSTRING_PTR (value );
1284
1246
1285
- #ifdef HAVE_RUBY_ENCODING_H
1286
1247
mysql2rb = mysql2_mysql_enc_name_to_rb (charset_name , (unsigned int )RSTRING_LEN (value ));
1287
1248
if (mysql2rb == NULL || mysql2rb -> rb_name == NULL ) {
1288
1249
VALUE inspect = rb_inspect (value );
@@ -1292,7 +1253,6 @@ static VALUE set_charset_name(VALUE self, VALUE value) {
1292
1253
rb_enc = rb_enc_from_encoding (enc );
1293
1254
wrapper -> encoding = rb_enc ;
1294
1255
}
1295
- #endif
1296
1256
1297
1257
if (mysql_options (wrapper -> client , MYSQL_SET_CHARSET_NAME , charset_name )) {
1298
1258
/* TODO: warning - unable to set charset */
@@ -1425,9 +1385,7 @@ void init_mysql2_client() {
1425
1385
rb_define_method (cMysql2Client , "warning_count" , rb_mysql_client_warning_count , 0 );
1426
1386
rb_define_method (cMysql2Client , "query_info_string" , rb_mysql_info , 0 );
1427
1387
rb_define_method (cMysql2Client , "ssl_cipher" , rb_mysql_get_ssl_cipher , 0 );
1428
- #ifdef HAVE_RUBY_ENCODING_H
1429
1388
rb_define_method (cMysql2Client , "encoding" , rb_mysql_client_encoding , 0 );
1430
- #endif
1431
1389
1432
1390
rb_define_private_method (cMysql2Client , "connect_timeout=" , set_connect_timeout , 1 );
1433
1391
rb_define_private_method (cMysql2Client , "read_timeout=" , set_read_timeout , 1 );
0 commit comments