@@ -50,6 +50,10 @@ static rb_encoding *binaryEncoding;
50
50
#define MYSQL2_MIN_TIME 62171150401ULL
51
51
#endif
52
52
53
+ #define GET_RESULT (obj ) \
54
+ mysql2_result_wrapper *wrapper; \
55
+ Data_Get_Struct(self, mysql2_result_wrapper, wrapper);
56
+
53
57
static VALUE cMysql2Result ;
54
58
static VALUE cBigDecimal , cDate , cDateTime ;
55
59
static VALUE opt_decimal_zero , opt_float_zero , opt_time_year , opt_time_month , opt_utc_offset ;
@@ -103,9 +107,8 @@ static void *nogvl_fetch_row(void *ptr) {
103
107
}
104
108
105
109
static VALUE rb_mysql_result_fetch_field (VALUE self , unsigned int idx , short int symbolize_keys ) {
106
- mysql2_result_wrapper * wrapper ;
107
110
VALUE rb_field ;
108
- GetMysql2Result (self , wrapper );
111
+ GET_RESULT (self );
109
112
110
113
if (wrapper -> fields == Qnil ) {
111
114
wrapper -> numberOfFields = mysql_num_fields (wrapper -> result );
@@ -193,7 +196,6 @@ static unsigned int msec_char_to_uint(char *msec_char, size_t len)
193
196
194
197
static VALUE rb_mysql_result_fetch_row (VALUE self , ID db_timezone , ID app_timezone , int symbolizeKeys , int asArray , int castBool , int cast , MYSQL_FIELD * fields ) {
195
198
VALUE rowVal ;
196
- mysql2_result_wrapper * wrapper ;
197
199
MYSQL_ROW row ;
198
200
unsigned int i = 0 ;
199
201
unsigned long * fieldLengths ;
@@ -202,7 +204,7 @@ static VALUE rb_mysql_result_fetch_row(VALUE self, ID db_timezone, ID app_timezo
202
204
rb_encoding * default_internal_enc ;
203
205
rb_encoding * conn_enc ;
204
206
#endif
205
- GetMysql2Result (self , wrapper );
207
+ GET_RESULT (self );
206
208
207
209
#ifdef HAVE_RUBY_ENCODING_H
208
210
default_internal_enc = rb_default_internal_encoding ();
@@ -413,12 +415,11 @@ static VALUE rb_mysql_result_fetch_row(VALUE self, ID db_timezone, ID app_timezo
413
415
}
414
416
415
417
static VALUE rb_mysql_result_fetch_fields (VALUE self ) {
416
- mysql2_result_wrapper * wrapper ;
417
418
unsigned int i = 0 ;
418
419
short int symbolizeKeys = 0 ;
419
420
VALUE defaults ;
420
421
421
- GetMysql2Result (self , wrapper );
422
+ GET_RESULT (self );
422
423
423
424
defaults = rb_iv_get (self , "@query_options" );
424
425
Check_Type (defaults , T_HASH );
@@ -443,13 +444,12 @@ static VALUE rb_mysql_result_fetch_fields(VALUE self) {
443
444
static VALUE rb_mysql_result_each (int argc , VALUE * argv , VALUE self ) {
444
445
VALUE defaults , opts , block ;
445
446
ID db_timezone , app_timezone , dbTz , appTz ;
446
- mysql2_result_wrapper * wrapper ;
447
447
unsigned long i ;
448
448
const char * errstr ;
449
449
int symbolizeKeys , asArray , castBool , cacheRows , cast ;
450
450
MYSQL_FIELD * fields = NULL ;
451
451
452
- GetMysql2Result (self , wrapper );
452
+ GET_RESULT (self );
453
453
454
454
defaults = rb_iv_get (self , "@query_options" );
455
455
Check_Type (defaults , T_HASH );
@@ -466,7 +466,7 @@ static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self) {
466
466
cast = RTEST (rb_hash_aref (opts , sym_cast ));
467
467
468
468
if (wrapper -> is_streaming && cacheRows ) {
469
- rb_warn ("cacheRows is ignored if streaming is true" );
469
+ rb_warn (":cache_rows is ignored if :stream is true" );
470
470
}
471
471
472
472
dbTz = rb_hash_aref (opts , sym_database_timezone );
@@ -577,9 +577,8 @@ static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self) {
577
577
}
578
578
579
579
static VALUE rb_mysql_result_count (VALUE self ) {
580
- mysql2_result_wrapper * wrapper ;
580
+ GET_RESULT ( self ) ;
581
581
582
- GetMysql2Result (self , wrapper );
583
582
if (wrapper -> is_streaming ) {
584
583
/* This is an unsigned long per result.h */
585
584
return ULONG2NUM (wrapper -> numberOfRows );
@@ -598,6 +597,7 @@ static VALUE rb_mysql_result_count(VALUE self) {
598
597
VALUE rb_mysql_result_to_obj (VALUE client , VALUE encoding , VALUE options , MYSQL_RES * r ) {
599
598
VALUE obj ;
600
599
mysql2_result_wrapper * wrapper ;
600
+
601
601
obj = Data_Make_Struct (cMysql2Result , mysql2_result_wrapper , rb_mysql_result_mark , rb_mysql_result_free , wrapper );
602
602
wrapper -> numberOfFields = 0 ;
603
603
wrapper -> numberOfRows = 0 ;
0 commit comments