@@ -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
typedef struct {
54
58
int symbolizeKeys ;
55
59
int asArray ;
@@ -141,9 +145,8 @@ static void *nogvl_stmt_fetch(void *ptr) {
141
145
142
146
143
147
static VALUE rb_mysql_result_fetch_field (VALUE self , unsigned int idx , short int symbolize_keys ) {
144
- mysql2_result_wrapper * wrapper ;
145
148
VALUE rb_field ;
146
- GetMysql2Result (self , wrapper );
149
+ GET_RESULT (self );
147
150
148
151
if (wrapper -> fields == Qnil ) {
149
152
wrapper -> numberOfFields = mysql_num_fields (wrapper -> result );
@@ -231,8 +234,7 @@ static unsigned int msec_char_to_uint(char *msec_char, size_t len)
231
234
232
235
static void rb_mysql_result_alloc_result_buffers (VALUE self , MYSQL_FIELD * fields ) {
233
236
unsigned int i ;
234
- mysql2_result_wrapper * wrapper ;
235
- GetMysql2Result (self , wrapper );
237
+ GET_RESULT (self );
236
238
237
239
if (wrapper -> result_buffers != NULL ) return ;
238
240
@@ -309,14 +311,13 @@ static void rb_mysql_result_alloc_result_buffers(VALUE self, MYSQL_FIELD *fields
309
311
static VALUE rb_mysql_result_fetch_row_stmt (VALUE self , MYSQL_FIELD * fields , const result_each_args * args )
310
312
{
311
313
VALUE rowVal ;
312
- mysql2_result_wrapper * wrapper ;
313
314
unsigned int i = 0 ;
314
315
315
316
#ifdef HAVE_RUBY_ENCODING_H
316
317
rb_encoding * default_internal_enc ;
317
318
rb_encoding * conn_enc ;
318
319
#endif
319
- GetMysql2Result (self , wrapper );
320
+ GET_RESULT (self );
320
321
321
322
#ifdef HAVE_RUBY_ENCODING_H
322
323
default_internal_enc = rb_default_internal_encoding ();
@@ -509,7 +510,6 @@ static VALUE rb_mysql_result_fetch_row_stmt(VALUE self, MYSQL_FIELD * fields, co
509
510
static VALUE rb_mysql_result_fetch_row (VALUE self , MYSQL_FIELD * fields , const result_each_args * args )
510
511
{
511
512
VALUE rowVal ;
512
- mysql2_result_wrapper * wrapper ;
513
513
MYSQL_ROW row ;
514
514
unsigned int i = 0 ;
515
515
unsigned long * fieldLengths ;
@@ -518,7 +518,7 @@ static VALUE rb_mysql_result_fetch_row(VALUE self, MYSQL_FIELD * fields, const r
518
518
rb_encoding * default_internal_enc ;
519
519
rb_encoding * conn_enc ;
520
520
#endif
521
- GetMysql2Result (self , wrapper );
521
+ GET_RESULT (self );
522
522
523
523
#ifdef HAVE_RUBY_ENCODING_H
524
524
default_internal_enc = rb_default_internal_encoding ();
@@ -729,12 +729,11 @@ static VALUE rb_mysql_result_fetch_row(VALUE self, MYSQL_FIELD * fields, const r
729
729
}
730
730
731
731
static VALUE rb_mysql_result_fetch_fields (VALUE self ) {
732
- mysql2_result_wrapper * wrapper ;
733
732
unsigned int i = 0 ;
734
733
short int symbolizeKeys = 0 ;
735
734
VALUE defaults ;
736
735
737
- GetMysql2Result (self , wrapper );
736
+ GET_RESULT (self );
738
737
739
738
defaults = rb_iv_get (self , "@query_options" );
740
739
Check_Type (defaults , T_HASH );
@@ -760,12 +759,11 @@ static VALUE rb_mysql_result_each_(VALUE self,
760
759
VALUE (* fetch_row_func )(VALUE , MYSQL_FIELD * fields , const result_each_args * args ),
761
760
const result_each_args * args )
762
761
{
763
- mysql2_result_wrapper * wrapper ;
764
762
unsigned long i ;
765
763
const char * errstr ;
766
764
MYSQL_FIELD * fields = NULL ;
767
765
768
- GetMysql2Result (self , wrapper );
766
+ GET_RESULT (self );
769
767
770
768
if (wrapper -> is_streaming ) {
771
769
/* When streaming, we will only yield rows, not return them. */
@@ -850,10 +848,9 @@ static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self) {
850
848
result_each_args args ;
851
849
VALUE defaults , opts , block , (* fetch_row_func )(VALUE , MYSQL_FIELD * fields , const result_each_args * args );
852
850
ID db_timezone , app_timezone , dbTz , appTz ;
853
- mysql2_result_wrapper * wrapper ;
854
851
int symbolizeKeys , asArray , castBool , cacheRows , cast ;
855
852
856
- GetMysql2Result (self , wrapper );
853
+ GET_RESULT (self );
857
854
858
855
defaults = rb_iv_get (self , "@query_options" );
859
856
Check_Type (defaults , T_HASH );
@@ -870,15 +867,15 @@ static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self) {
870
867
cast = RTEST (rb_hash_aref (opts , sym_cast ));
871
868
872
869
if (wrapper -> is_streaming && cacheRows ) {
873
- rb_warn ("cacheRows is ignored if streaming is true" );
870
+ rb_warn (":cache_rows is ignored if :stream is true" );
874
871
}
875
872
876
873
if (wrapper -> stmt && !cacheRows && !wrapper -> is_streaming ) {
877
- rb_warn ("cacheRows is forced for prepared statements (if not streaming)" );
874
+ rb_warn (":cache_rows is forced for prepared statements (if not streaming)" );
878
875
}
879
876
880
877
if (wrapper -> stmt && !cast ) {
881
- rb_warn ("cast is forced for prepared statements" );
878
+ rb_warn (": cast is forced for prepared statements" );
882
879
}
883
880
884
881
dbTz = rb_hash_aref (opts , sym_database_timezone );
@@ -931,9 +928,8 @@ static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self) {
931
928
}
932
929
933
930
static VALUE rb_mysql_result_count (VALUE self ) {
934
- mysql2_result_wrapper * wrapper ;
931
+ GET_RESULT ( self ) ;
935
932
936
- GetMysql2Result (self , wrapper );
937
933
if (wrapper -> is_streaming ) {
938
934
/* This is an unsigned long per result.h */
939
935
return ULONG2NUM (wrapper -> numberOfRows );
@@ -957,7 +953,6 @@ VALUE rb_mysql_result_to_obj(VALUE client, VALUE encoding, VALUE options, MYSQL_
957
953
VALUE obj ;
958
954
mysql2_result_wrapper * wrapper ;
959
955
960
-
961
956
obj = Data_Make_Struct (cMysql2Result , mysql2_result_wrapper , rb_mysql_result_mark , rb_mysql_result_free , wrapper );
962
957
wrapper -> numberOfFields = 0 ;
963
958
wrapper -> numberOfRows = 0 ;
0 commit comments