Пример #1
0
func (session *Session) writeRows(rs mysql.Rows) error {
	var cols []driver.RawPacket
	var err error
	cols, err = rs.ColumnPackets()

	if err != nil {
		return session.handleMySQLError(err)
	}

	// Send a packet contains column length
	data := make([]byte, 4, 32)
	data = mysql.AppendLengthEncodedInteger(data, uint64(len(cols)))
	if err = session.fc.WritePacket(data); err != nil {
		return err
	}

	// Write Columns Packet
	for _, col := range cols {
		if err := session.fc.WritePacket(col); err != nil {
			log.Debugf("write columns packet error %v", err)
			return err
		}
	}

	// TODO Write a ok packet
	if err = session.fc.WriteEOF(); err != nil {
		return err
	}

	for {
		packet, err := rs.NextRowPacket()

		// Handle Error

		if err != nil {
			if err == io.EOF {
				return session.fc.WriteEOF()
			} else {
				return session.handleMySQLError(err)
			}
		}

		if err := session.fc.WritePacket(packet); err != nil {
			return err
		}
	}

	return nil
}
Пример #2
0
func (session *Session) writeFieldList(rs mysql.Rows) error {

	cols, err := rs.ColumnPackets()

	if err != nil {
		return session.handleMySQLError(err)
	}

	// Write Columns Packet
	for _, col := range cols {
		if err := session.fc.WritePacket(col); err != nil {
			log.Debugf("write columns packet error %v", err)
			return err
		}
	}

	// TODO Write a ok packet
	if err = session.fc.WriteEOF(); err != nil {
		return err
	}

	return nil
}