Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
yireyun opened this issue Jan 14, 2020 · 2 comments
Milestone

Comments

@yireyun
Copy link

yireyun commented Jan 14, 2020

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: 17ef3dd

*Go version:1.12.15

*Server version:MySQL 5.22

*Server OS: ubuntu

fix fork:
yireyun@eac50bb

@ChaimHong
Copy link

ChaimHong commented Feb 11, 2023

@methane
Copy link
Member

methane commented Feb 5, 2024

Fixed in #1462

@methane methane closed this as completed Feb 5, 2024
@methane methane added this to the v1.8.0 milestone Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants