Beispiel #1
0
func (my *Conn) init() {
	my.seq = 0 // Reset sequence number, mainly for reconnect
	if my.Debug {
		log.Printf("[%2d ->] Init packet:", my.seq)
	}
	pr := my.newPktReader()

	my.info.prot_ver = pr.readByte()
	my.info.serv_ver = pr.readNTB()
	my.info.thr_id = pr.readU32()
	pr.readFull(my.info.scramble[0:8])
	pr.skipN(1)
	my.info.caps = pr.readU16()
	my.info.lang = pr.readByte()
	my.status = mysql.ConnStatus(pr.readU16())
	pr.skipN(13)
	if my.info.caps&_CLIENT_PROTOCOL_41 != 0 {
		pr.readFull(my.info.scramble[8:])
	}
	pr.skipAll() // Skip other information
	if my.Debug {
		log.Printf(tab8s+"ProtVer=%d, ServVer=\"%s\" Status=0x%x",
			my.info.prot_ver, my.info.serv_ver, my.status,
		)
	}
	if my.info.caps&_CLIENT_PROTOCOL_41 == 0 {
		panic(mysql.ErrOldProtocol)
	}
}
Beispiel #2
0
func (my *Conn) getEofPacket(pr *pktReader) (warn_count int, status mysql.ConnStatus) {
	if my.Debug {
		if pr.eof() {
			log.Printf("[%2d ->] EOF packet without body", my.seq-1)
		} else {
			log.Printf("[%2d ->] EOF packet:", my.seq-1)
		}
	}
	if pr.eof() {
		return
	}
	warn_count = int(pr.readU16())
	if pr.eof() {
		return
	}
	status = mysql.ConnStatus(pr.readU16())
	pr.checkEof()

	if my.Debug {
		log.Printf(tab8s+"WarningCount=%d Status=0x%x", warn_count, status)
	}
	return
}
Beispiel #3
0
func (my *Conn) getOkPacket(pr *pktReader) (res *Result) {
	if my.Debug {
		log.Printf("[%2d ->] OK packet:", my.seq-1)
	}
	res = new(Result)
	res.status_only = true
	res.my = my
	// First byte was readed by getResult
	res.affected_rows = pr.readLCB()
	res.insert_id = pr.readLCB()
	res.status = mysql.ConnStatus(pr.readU16())
	my.status = res.status
	res.warning_count = int(pr.readU16())
	res.message = pr.readAll()
	pr.checkEof()

	if my.Debug {
		log.Printf(tab8s+"AffectedRows=%d InsertId=0x%x Status=0x%x "+
			"WarningCount=%d Message=\"%s\"", res.affected_rows, res.insert_id,
			res.status, res.warning_count, res.message,
		)
	}
	return
}