ziutek / mymysql

MySQL Client API written entirely in Go
Other
735 stars 161 forks source link

has issue with multi result #131

Open yanghaikun opened 8 years ago

yanghaikun commented 8 years ago

when exec multi result query as the example, the first result is correct, and the res.MoreResults() shows true, but res.NextResult() returns the nex result has nil data here is my code:

func main() {
    fmt.Println("My First MySQL Application")
    db := mysql.New("tcp", "", "127.0.0.1:3306", "root", "root", "reckoning")
    err := db.Connect()
    if err != nil {
        panic(err)
    }
    sql := "SELECT * from reckoning.reckoning_bits WHERE id = 10000; SELECT * FROM reckoning.inventory_bits where instance_id = 10080;"
    res, _ := db.Start(sql)
    row, _ := res.GetRow()
    fmt.Printf("id is %v \n", row.Str(0))

    res, _ = res.NextResult()
    if res == nil {
        fmt.Println("Hmm, there is no result. Why?!")
    }
    row, _ = res.GetRow()
    fmt.Printf("instance_id is %v \n", row.Int(0))
}
ziutek commented 8 years ago
  1. Please add all required error check to this code.
  2. Before call NextResult, let the GetRow method tell you that there are no more rows (or use method that returns first/last row and discard other).