diff --git a/connection.go b/connection.go index 80365967d..67fd3df70 100644 --- a/connection.go +++ b/connection.go @@ -95,6 +95,7 @@ func (mc *mysqlConn) Begin() (driver.Tx, error) { func (mc *mysqlConn) Close() (err error) { mc.writeCommandPacket(COM_QUIT) + mc.cfg = nil mc.bufReader = nil mc.netConn.Close() mc.netConn = nil @@ -150,9 +151,9 @@ func (mc *mysqlConn) Exec(query string, args []driver.Value) (driver.Result, err } return &mysqlResult{ - affectedRows: int64(mc.affectedRows), - insertId: int64(mc.insertId)}, - err + affectedRows: int64(mc.affectedRows), + insertId: int64(mc.insertId), + }, err } // Internal function to execute commands diff --git a/const.go b/const.go index dede609f9..62c4d874e 100644 --- a/const.go +++ b/const.go @@ -2,22 +2,22 @@ // // Copyright 2012 Julien Schmidt. All rights reserved. // http://www.julienschmidt.com -// +// // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this file, // You can obtain one at http://mozilla.org/MPL/2.0/. package mysql -// Constants documentation: -// http://dev.mysql.com/doc/internals/en/client-server-protocol.html - const ( MIN_PROTOCOL_VERSION = 10 MAX_PACKET_SIZE = 1<<24 - 1 TIME_FORMAT = "2006-01-02 15:04:05" ) +// MySQL constants documentation: +// http://dev.mysql.com/doc/internals/en/client-server-protocol.html + type ClientFlag uint32 const ( diff --git a/packets.go b/packets.go index 939a3d7dd..c69cedae3 100644 --- a/packets.go +++ b/packets.go @@ -330,10 +330,10 @@ func (mc *mysqlConn) writeCommandPacket(command commandType, args ...interface{} ******************************************************************************/ // Returns error if Packet is not an 'Result OK'-Packet -func (mc *mysqlConn) readResultOK() (err error) { +func (mc *mysqlConn) readResultOK() error { data, err := mc.readPacket() if err != nil { - return + return err } switch data[0] { @@ -342,17 +342,13 @@ func (mc *mysqlConn) readResultOK() (err error) { return mc.handleOkPacket(data) // EOF, someone is using old_passwords case 254: - err = errors.New("It seems like you are using old_passwords, which is unsupported. See https://github.com/Go-SQL-Driver/MySQL/wiki/old_passwords") - return + return errors.New("It seems like you are using old_passwords, which is unsupported. See https://github.com/Go-SQL-Driver/MySQL/wiki/old_passwords") // ERROR case 255: return mc.handleErrorPacket(data) - default: - err = errors.New("Invalid Result Packet-Type") - return } - return + return errors.New("Invalid Result Packet-Type") } /* Error Packet @@ -364,10 +360,9 @@ Bytes Name 5 sqlstate (5 characters) n message */ -func (mc *mysqlConn) handleErrorPacket(data []byte) (err error) { +func (mc *mysqlConn) handleErrorPacket(data []byte) error { if data[0] != 255 { - err = errors.New("Wrong Packet-Type: Not an Error-Packet") - return + return errors.New("Wrong Packet-Type: Not an Error-Packet") } pos := 1 @@ -383,8 +378,7 @@ func (mc *mysqlConn) handleErrorPacket(data []byte) (err error) { // Error Message [string] message := string(data[pos:]) - err = fmt.Errorf("Error %d: %s", errno, message) - return + return fmt.Errorf("Error %d: %s", errno, message) } /* Ok Packet @@ -604,7 +598,7 @@ func (mc *mysqlConn) readRow(columnsCount int) (*[]*[]byte, error) { return &row, nil } -// Reads Packets Packets until EOF-Packet or an Error appears. Returns count of Packets read +// Reads Packets until EOF-Packet or an Error appears. Returns count of Packets read func (mc *mysqlConn) readUntilEOF() (count uint64, err error) { var data []byte diff --git a/utils_test.go b/utils_test.go index d943ffcc7..e0f591c38 100644 --- a/utils_test.go +++ b/utils_test.go @@ -2,7 +2,7 @@ // // Copyright 2013 Julien Schmidt. All rights reserved. // http://www.julienschmidt.com -// +// // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this file, // You can obtain one at http://mozilla.org/MPL/2.0/.