@@ -382,10 +382,13 @@ func (this *Applier) ReadMigrationMinValues(uniqueKey *sql.UniqueKey) error {
382382 if err != nil {
383383 return err
384384 }
385+
385386 rows , err := this .db .Query (query )
386387 if err != nil {
387388 return err
388389 }
390+ defer rows .Close ()
391+
389392 for rows .Next () {
390393 this .migrationContext .MigrationRangeMinValues = sql .NewColumnValues (uniqueKey .Len ())
391394 if err = rows .Scan (this .migrationContext .MigrationRangeMinValues .ValuesPointers ... ); err != nil {
@@ -394,8 +397,7 @@ func (this *Applier) ReadMigrationMinValues(uniqueKey *sql.UniqueKey) error {
394397 }
395398 this .migrationContext .Log .Infof ("Migration min values: [%s]" , this .migrationContext .MigrationRangeMinValues )
396399
397- err = rows .Err ()
398- return err
400+ return rows .Err ()
399401}
400402
401403// ReadMigrationMaxValues returns the maximum values to be iterated on rowcopy
@@ -405,10 +407,13 @@ func (this *Applier) ReadMigrationMaxValues(uniqueKey *sql.UniqueKey) error {
405407 if err != nil {
406408 return err
407409 }
410+
408411 rows , err := this .db .Query (query )
409412 if err != nil {
410413 return err
411414 }
415+ defer rows .Close ()
416+
412417 for rows .Next () {
413418 this .migrationContext .MigrationRangeMaxValues = sql .NewColumnValues (uniqueKey .Len ())
414419 if err = rows .Scan (this .migrationContext .MigrationRangeMaxValues .ValuesPointers ... ); err != nil {
@@ -417,8 +422,7 @@ func (this *Applier) ReadMigrationMaxValues(uniqueKey *sql.UniqueKey) error {
417422 }
418423 this .migrationContext .Log .Infof ("Migration max values: [%s]" , this .migrationContext .MigrationRangeMaxValues )
419424
420- err = rows .Err ()
421- return err
425+ return rows .Err ()
422426}
423427
424428// ReadMigrationRangeValues reads min/max values that will be used for rowcopy.
@@ -479,10 +483,13 @@ func (this *Applier) CalculateNextIterationRangeEndValues() (hasFurtherRange boo
479483 if err != nil {
480484 return hasFurtherRange , err
481485 }
486+
482487 rows , err := this .db .Query (query , explodedArgs ... )
483488 if err != nil {
484489 return hasFurtherRange , err
485490 }
491+ defer rows .Close ()
492+
486493 iterationRangeMaxValues := sql .NewColumnValues (this .migrationContext .UniqueKey .Len ())
487494 for rows .Next () {
488495 if err = rows .Scan (iterationRangeMaxValues .ValuesPointers ... ); err != nil {
0 commit comments