Busy wait in Commit, Rows.Next and Rows.Close also ignores the context

Hey @cznic thanks for fixing #262 (closed) in v1.61.0.

A statement run with a context now stops waiting for a lock once that context is done. But Tx.Commit, Rows.Next after the first row, and Rows.Close still wait the full busy_timeout.

Context

package main

import (
	"context"
	"database/sql"
	"fmt"
	"os"
	"path/filepath"
	"time"

	_ "modernc.org/sqlite"
)

func main() {
	dir, err := os.MkdirTemp("", "busy")
	check(err)
	defer os.RemoveAll(dir)

	db, err := sql.Open("sqlite", "file:"+filepath.Join(dir, "test.db")+"?_busy_timeout=2000")
	check(err)
	defer db.Close()
	_, err = db.Exec("CREATE TABLE t (x INTEGER)")
	check(err)

	ctx := context.Background()
	reader, err := db.Conn(ctx)
	check(err)
	_, err = reader.ExecContext(ctx, "BEGIN")
	check(err)
	var n int
	check(reader.QueryRowContext(ctx, "SELECT count(*) FROM t").Scan(&n))

	tctx, cancel := context.WithTimeout(ctx, 100*time.Millisecond)
	defer cancel()
	tx, err := db.BeginTx(tctx, nil)
	check(err)
	_, err = tx.Exec("INSERT INTO t VALUES (1)")
	check(err)
	start := time.Now()
	err = tx.Commit()
	fmt.Println("Commit:", time.Since(start).Round(time.Millisecond), err)

	qctx, cancel2 := context.WithTimeout(ctx, 100*time.Millisecond)
	defer cancel2()
	rows, err := db.QueryContext(qctx, "INSERT INTO t VALUES (2) RETURNING x")
	check(err)
	rows.Next()
	start = time.Now()
	err = rows.Close()
	fmt.Println("Rows.Close:", time.Since(start).Round(time.Millisecond), err)
}

func check(err error) {
	if err != nil {
		panic(err)
	}
}

The database uses the default rollback journal, so the reader's open transaction blocks both commits.

Now on v1.61.0 it prints:

Commit: 2.007s database is locked (5) (SQLITE_BUSY)
Rows.Close: 2.007s database is locked (5) (SQLITE_BUSY)

Tx.Commit runs commit with context.Background(), so it ignores the context given to BeginTx. Rows.Next steps, and Rows.Close finalizes, with no context, so both ignore the query's context. Closing the rows of an INSERT ... RETURNING outside a transaction commits the insert, so the close can wait. QueryRowContext(ctx, "INSERT ... RETURNING id").Scan(&id) hits this too, since Row.Scan closes the rows after the first row.

Could the wait in Commit end with the context given to BeginTx, and the waits in Next and Close with the query's context? Rollback should keep waiting as it does now, since database/sql calls it to clean up after the context is done.