@@ -429,6 +429,7 @@ static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self) {
429
429
ID db_timezone , app_timezone , dbTz , appTz ;
430
430
mysql2_result_wrapper * wrapper ;
431
431
unsigned long i ;
432
+ const char * errstr ;
432
433
int symbolizeKeys = 0 , asArray = 0 , castBool = 0 , cacheRows = 1 , cast = 1 , streaming = 0 ;
433
434
MYSQL_FIELD * fields = NULL ;
434
435
@@ -492,7 +493,7 @@ static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self) {
492
493
}
493
494
494
495
if (wrapper -> lastRowProcessed == 0 ) {
495
- if (streaming ) {
496
+ if (streaming ) {
496
497
/* We can't get number of rows if we're streaming, */
497
498
/* until we've finished fetching all rows */
498
499
wrapper -> numberOfRows = 0 ;
@@ -508,7 +509,7 @@ static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self) {
508
509
}
509
510
510
511
if (streaming ) {
511
- if (!wrapper -> streamingComplete ) {
512
+ if (!wrapper -> streamingComplete ) {
512
513
VALUE row ;
513
514
514
515
fields = mysql_fetch_fields (wrapper -> result );
@@ -526,6 +527,13 @@ static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self) {
526
527
527
528
wrapper -> numberOfRows = wrapper -> lastRowProcessed ;
528
529
wrapper -> streamingComplete = 1 ;
530
+
531
+ // Check for errors, the connection might have gone out from under us
532
+ // mysql_error returns an empty string if there is no error
533
+ errstr = mysql_error (wrapper -> client_wrapper -> client );
534
+ if (errstr [0 ]) {
535
+ rb_raise (cMysql2Error , "%s" , errstr );
536
+ }
529
537
} else {
530
538
rb_raise (cMysql2Error , "You have already fetched all the rows for this query and streaming is true. (to reiterate you must requery)." );
531
539
}
0 commit comments