From 1ddc9e8427753e7e8869300be7a9bde35ef583c6 Mon Sep 17 00:00:00 2001 From: Phil Date: Mon, 12 Apr 2010 18:22:36 +0100 Subject: [PATCH] added int field to command packet for greater flexibility/usage --- mysql.go | 2 +- mysql_packet.go | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/mysql.go b/mysql.go index 9e7389b..4445bc8 100644 --- a/mysql.go +++ b/mysql.go @@ -573,7 +573,7 @@ func (mysql *MySQL) command(command byte, arg string) { case COM_QUIT, COM_INIT_DB, COM_QUERY, COM_PING, COM_STMT_PREPARE: pkt := new(packetCommand) pkt.command = command - pkt.arg = arg + pkt.argStr = arg err = pkt.write(mysql.writer) } if err != nil { diff --git a/mysql_packet.go b/mysql_packet.go index 6d3657e..a4b595e 100644 --- a/mysql_packet.go +++ b/mysql_packet.go @@ -301,12 +301,14 @@ func (pkt *packetError) read(reader *bufio.Reader) (err os.Error) { } /** - * Standard command packet (tells the server to do something defined by arg) + * Standard command packet (tells the server to do something defined by args) */ type packetCommand struct { header *packetHeader command byte - arg string + argInt uint64 + argIntLen uint8 + argStr string } /** @@ -315,16 +317,21 @@ type packetCommand struct { func (pkt *packetCommand) write(writer *bufio.Writer) (err os.Error) { // Construct packet header pkt.header = new(packetHeader) - pkt.header.length = 1 + uint32(len(pkt.arg)) + pkt.header.length = 1 + uint32(pkt.argIntLen) + uint32(len(pkt.argStr)) pkt.header.sequence = 0 err = pkt.header.write(writer) if err != nil { return err } // Write command err = writer.WriteByte(byte(pkt.command)) if err != nil { return err } - // Write arg - if len(pkt.arg) > 0 { - _, err = writer.WriteString(pkt.arg) + // Write argInt + if pkt.argIntLen > 0 { + err = writeNumber(writer, pkt.argInt, pkt.argIntLen) + if err != nil { return err } + } + // Write argStr + if len(pkt.argStr) > 0 { + _, err = writer.WriteString(pkt.argStr) if err != nil { return err } } // Flush