From f554b55b781e4cc064bad5b499405c10ef71e98f Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Sat, 18 May 2024 16:07:25 +0900 Subject: [PATCH] improve connection.go --- connection.go | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/connection.go b/connection.go index 5a9f954ce..3644464e7 100644 --- a/connection.go +++ b/connection.go @@ -368,33 +368,37 @@ func (mc *mysqlConn) query(query string, args []driver.Value) (*textRows, error) } query = prepared } + // Send command err := mc.writeCommandPacketStr(comQuery, query) - if err == nil { - // Read Result - var resLen int - resLen, err = handleOk.readResultSetHeaderPacket() - if err == nil { - rows := new(textRows) - rows.mc = mc + if err != nil { + return nil, err + } - if resLen == 0 { - rows.rs.done = true + // Read Result + var resLen int + resLen, err = handleOk.readResultSetHeaderPacket() + if err != nil { + return nil, err + } - switch err := rows.NextResultSet(); err { - case nil, io.EOF: - return rows, nil - default: - return nil, err - } - } + rows := new(textRows) + rows.mc = mc - // Columns - rows.rs.columns, err = mc.readColumns(resLen) - return rows, err + if resLen == 0 { + rows.rs.done = true + + switch err := rows.NextResultSet(); err { + case nil, io.EOF: + return rows, nil + default: + return nil, err } } - return nil, err + + // Columns + rows.rs.columns, err = mc.readColumns(resLen) + return rows, err } // Gets the value of the given MySQL System Variable