func (c *Conn) handleOKPacket(data []byte) (*mysql.Result, error) { var n int var pos int = 1 r := new(mysql.Result) r.AffectedRows, _, n = mysql.LengthEncodedInt(data[pos:]) pos += n r.InsertId, _, n = mysql.LengthEncodedInt(data[pos:]) pos += n if c.capability&mysql.CLIENT_PROTOCOL_41 > 0 { r.Status = binary.LittleEndian.Uint16(data[pos:]) c.status = r.Status pos += 2 //todo:strict_mode, check warnings as error //Warnings := binary.LittleEndian.Uint16(data[pos:]) //pos += 2 } else if c.capability&mysql.CLIENT_TRANSACTIONS > 0 { r.Status = binary.LittleEndian.Uint16(data[pos:]) c.status = r.Status pos += 2 } //info return r, nil }
func (c *Conn) readResultset(data []byte, binary bool) (*mysql.Result, error) { result := &mysql.Result{ Status: 0, InsertId: 0, AffectedRows: 0, Resultset: &mysql.Resultset{}, } // column count count, _, n := mysql.LengthEncodedInt(data) if n-len(data) != 0 { return nil, mysql.ErrMalformPacket } result.Fields = make([]*mysql.Field, count) result.FieldNames = make(map[string]int, count) if err := c.readResultColumns(result); err != nil { return nil, err } if err := c.readResultRows(result, binary); err != nil { return nil, err } return result, nil }