mysql icon indicating copy to clipboard operation
mysql copied to clipboard

the rows.NextResultSet() will always be blocked, if the second query result is error.

Open yireyun opened this issue 6 years ago • 1 comments

Issue description

When the query returns multiple result sets, if the second query result is wrong, it will not return when calling rows.nextresultset (), and the call will always be blocked.

Example code

// queryMulti
package main

import (
	"database/sql"
	"fmt"

	_ "github.com/go-sql-driver/mysql"
)

func queryMulti() (err error) {
	sqlText := "" +
		"select 'ds1' ds, ifnull(null,'') sex1  ;" +
		"select 'ds2' ds, isnull(null,'') sex2  ;"
	connectionString := "root:game@tcp(192.168.1.88:3306)/GMDB?charset=utf8&multiStatements=true"
	my, err := sql.Open("mysql", connectionString)
	if err != nil {
		fmt.Printf("Open %v\n", err)
		return err
	} else {
		fmt.Printf("Open Success: %v,\n\tStats%v\n", connectionString, my.Stats())
	}

	defer my.Close()

	rows, err := my.Query(sqlText)
	if err != nil {
		fmt.Printf("Query : %v\n", err)
		return err
	}
	defer rows.Close()

	var id, sex string
	var ds, dsr = 1, 1
	for rows.Next() {
		if err := rows.Scan(&id, &sex); err != nil {
			fmt.Printf("Scan Error: %v\n", err)
			return err
		} else {
			fmt.Printf("DS[%2v]Row[%2v] => id[%v], sex[%v]\n",
				ds, dsr, id, sex)
			dsr++
		}
	}
	for rows.NextResultSet() { // <-- blocked
		ds++
		for rows.Next() {
			if err := rows.Scan(&id, &sex); err != nil {
				fmt.Printf("Scan %v\n", err)
				return err
			} else {
				fmt.Printf("DS[%2v]Row[%2v] => id[%v], sex[%v]\n",
					ds, dsr, id, sex)
				dsr++
			}
		}
	}
	return nil
}

func main() {

	if err := queryMulti(); err != nil {
		fmt.Printf("queryMulti : %v\n", err)
	}
}

Error log


Configuration

*Driver version (or git SHA):Release v1.5.0 (#1047) git: 17ef3dd9d98b69acec3e85878995ada9533a9370

*Go version:1.12.15

*Server version:MySQL 5.22

*Server OS: ubuntu

fix fork: https://github.com/yireyun/mysql/commit/eac50bb6f25949d448ebdd2db105cf21b34b2abd

yireyun avatar Jan 14 '20 13:01 yireyun

@methane @julienschmidt @arnehormann @jszwec https://github.com/yireyun/mysql/commit/eac50bb6f25949d448ebdd2db105cf21b34b2abd
Review please

ChaimHong avatar Feb 11 '23 11:02 ChaimHong

Fixed in #1462

methane avatar Feb 05 '24 08:02 methane