@@ -212,6 +212,7 @@ func TestEmptyQuery(t *testing.T) {
212212 runTests (t , dsn , func (dbt * DBTest ) {
213213 // just a comment, no query
214214 rows := dbt .mustQuery ("--" )
215+ defer rows .Close ()
215216 // will hang before #255
216217 if rows .Next () {
217218 dbt .Errorf ("next on rows must be false" )
@@ -230,6 +231,7 @@ func TestCRUD(t *testing.T) {
230231 if rows .Next () {
231232 dbt .Error ("unexpected data in empty table" )
232233 }
234+ rows .Close ()
233235
234236 // Create Data
235237 res := dbt .mustExec ("INSERT INTO test VALUES (1)" )
@@ -263,6 +265,7 @@ func TestCRUD(t *testing.T) {
263265 } else {
264266 dbt .Error ("no data" )
265267 }
268+ rows .Close ()
266269
267270 // Update
268271 res = dbt .mustExec ("UPDATE test SET value = ? WHERE value = ?" , false , true )
@@ -288,6 +291,7 @@ func TestCRUD(t *testing.T) {
288291 } else {
289292 dbt .Error ("no data" )
290293 }
294+ rows .Close ()
291295
292296 // Delete
293297 res = dbt .mustExec ("DELETE FROM test WHERE value = ?" , false )
@@ -351,6 +355,7 @@ func TestMultiQuery(t *testing.T) {
351355 } else {
352356 dbt .Error ("no data" )
353357 }
358+ rows .Close ()
354359
355360 })
356361}
@@ -377,6 +382,7 @@ func TestInt(t *testing.T) {
377382 } else {
378383 dbt .Errorf ("%s: no data" , v )
379384 }
385+ rows .Close ()
380386
381387 dbt .mustExec ("DROP TABLE IF EXISTS test" )
382388 }
@@ -396,6 +402,7 @@ func TestInt(t *testing.T) {
396402 } else {
397403 dbt .Errorf ("%s ZEROFILL: no data" , v )
398404 }
405+ rows .Close ()
399406
400407 dbt .mustExec ("DROP TABLE IF EXISTS test" )
401408 }
@@ -420,6 +427,7 @@ func TestFloat32(t *testing.T) {
420427 } else {
421428 dbt .Errorf ("%s: no data" , v )
422429 }
430+ rows .Close ()
423431 dbt .mustExec ("DROP TABLE IF EXISTS test" )
424432 }
425433 })
@@ -443,6 +451,7 @@ func TestFloat64(t *testing.T) {
443451 } else {
444452 dbt .Errorf ("%s: no data" , v )
445453 }
454+ rows .Close ()
446455 dbt .mustExec ("DROP TABLE IF EXISTS test" )
447456 }
448457 })
@@ -466,6 +475,7 @@ func TestFloat64Placeholder(t *testing.T) {
466475 } else {
467476 dbt .Errorf ("%s: no data" , v )
468477 }
478+ rows .Close ()
469479 dbt .mustExec ("DROP TABLE IF EXISTS test" )
470480 }
471481 })
@@ -492,6 +502,7 @@ func TestString(t *testing.T) {
492502 } else {
493503 dbt .Errorf ("%s: no data" , v )
494504 }
505+ rows .Close ()
495506
496507 dbt .mustExec ("DROP TABLE IF EXISTS test" )
497508 }
@@ -524,6 +535,7 @@ func TestRawBytes(t *testing.T) {
524535 v1 := []byte ("aaa" )
525536 v2 := []byte ("bbb" )
526537 rows := dbt .mustQuery ("SELECT ?, ?" , v1 , v2 )
538+ defer rows .Close ()
527539 if rows .Next () {
528540 var o1 , o2 sql.RawBytes
529541 if err := rows .Scan (& o1 , & o2 ); err != nil {
@@ -572,6 +584,7 @@ func TestValuer(t *testing.T) {
572584 } else {
573585 dbt .Errorf ("Valuer: no data" )
574586 }
587+ rows .Close ()
575588
576589 dbt .mustExec ("DROP TABLE IF EXISTS test" )
577590 })
@@ -884,6 +897,7 @@ func TestTimestampMicros(t *testing.T) {
884897 dbt .mustExec ("INSERT INTO test SET value0=?, value1=?, value6=?" , f0 , f1 , f6 )
885898 var res0 , res1 , res6 string
886899 rows := dbt .mustQuery ("SELECT * FROM test" )
900+ defer rows .Close ()
887901 if ! rows .Next () {
888902 dbt .Errorf ("test contained no selectable values" )
889903 }
@@ -1042,6 +1056,7 @@ func TestNULL(t *testing.T) {
10421056
10431057 var out interface {}
10441058 rows := dbt .mustQuery ("SELECT * FROM test" )
1059+ defer rows .Close ()
10451060 if rows .Next () {
10461061 rows .Scan (& out )
10471062 if out != nil {
@@ -1121,6 +1136,7 @@ func TestLongData(t *testing.T) {
11211136 inS := in [:maxAllowedPacketSize - nonDataQueryLen ]
11221137 dbt .mustExec ("INSERT INTO test VALUES('" + inS + "')" )
11231138 rows = dbt .mustQuery ("SELECT value FROM test" )
1139+ defer rows .Close ()
11241140 if rows .Next () {
11251141 rows .Scan (& out )
11261142 if inS != out {
@@ -1139,6 +1155,7 @@ func TestLongData(t *testing.T) {
11391155 // Long binary data
11401156 dbt .mustExec ("INSERT INTO test VALUES(?)" , in )
11411157 rows = dbt .mustQuery ("SELECT value FROM test WHERE 1=?" , 1 )
1158+ defer rows .Close ()
11421159 if rows .Next () {
11431160 rows .Scan (& out )
11441161 if in != out {
@@ -1314,6 +1331,7 @@ func TestTLS(t *testing.T) {
13141331 }
13151332
13161333 rows := dbt .mustQuery ("SHOW STATUS LIKE 'Ssl_cipher'" )
1334+ defer rows .Close ()
13171335
13181336 var variable , value * sql.RawBytes
13191337 for rows .Next () {
@@ -1474,9 +1492,9 @@ func TestColumnsWithAlias(t *testing.T) {
14741492 if cols [0 ] != "A" {
14751493 t .Fatalf ("expected column name \" A\" , got \" %s\" " , cols [0 ])
14761494 }
1477- rows .Close ()
14781495
14791496 rows = dbt .mustQuery ("SELECT * FROM (SELECT 1 AS one) AS A" )
1497+ defer rows .Close ()
14801498 cols , _ = rows .Columns ()
14811499 if len (cols ) != 1 {
14821500 t .Fatalf ("expected 1 column, got %d" , len (cols ))
@@ -1520,6 +1538,7 @@ func TestTimezoneConversion(t *testing.T) {
15201538
15211539 // Retrieve time from DB
15221540 rows := dbt .mustQuery ("SELECT ts FROM test" )
1541+ defer rows .Close ()
15231542 if ! rows .Next () {
15241543 dbt .Fatal ("did not get any rows out" )
15251544 }
@@ -2017,6 +2036,7 @@ func TestInterruptBySignal(t *testing.T) {
20172036 dbt .Errorf ("expected val to be 42" )
20182037 }
20192038 }
2039+ rows .Close ()
20202040
20212041 // binary protocol
20222042 rows , err = dbt .db .Query ("CALL test_signal(?)" , 42 )
@@ -2030,6 +2050,7 @@ func TestInterruptBySignal(t *testing.T) {
20302050 dbt .Errorf ("expected val to be 42" )
20312051 }
20322052 }
2053+ rows .Close ()
20332054 })
20342055}
20352056
0 commit comments