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) readResultRows(result *mysql.Result, isBinary bool) (err error) { var data []byte for { data, err = c.readPacket() if err != nil { return } // EOF Packet if c.isEOFPacket(data) { if c.capability&mysql.CLIENT_PROTOCOL_41 > 0 { //result.Warnings = binary.LittleEndian.Uint16(data[1:]) //todo add strict_mode, warning will be treat as error result.Status = binary.LittleEndian.Uint16(data[3:]) c.status = result.Status } break } result.RowDatas = append(result.RowDatas, data) } result.Values = make([][]interface{}, len(result.RowDatas)) for i := range result.Values { result.Values[i], err = result.RowDatas[i].Parse(result.Fields, isBinary) if err != nil { return err } } return nil }
func (c *Conn) readResultColumns(result *mysql.Result) (err error) { var i int = 0 var data []byte for { data, err = c.readPacket() if err != nil { return } // EOF Packet if c.isEOFPacket(data) { if c.capability&mysql.CLIENT_PROTOCOL_41 > 0 { //result.Warnings = binary.LittleEndian.Uint16(data[1:]) //todo add strict_mode, warning will be treat as error result.Status = binary.LittleEndian.Uint16(data[3:]) c.status = result.Status } if i != len(result.Fields) { err = mysql.ErrMalformPacket } return } result.Fields[i], err = mysql.FieldData(data).Parse() if err != nil { return } result.FieldNames[string(result.Fields[i].Name)] = i i++ } }