Skip to content

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

Closed

Description

@yireyun

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

Activity

  1. ChaimHong commented on Feb 11, 2023

    @ChaimHong
  2. methane commented on Feb 5, 2024

    @methane
    Member

    Fixed in #1462

  3. added this to the v1.8.0 milestone on Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions