Skip to content

Commit a86fb49

Browse files
committed
wip
1 parent be57666 commit a86fb49

File tree

2 files changed

+35
-24
lines changed

2 files changed

+35
-24
lines changed

client/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func (c *Conn) writeAuthHandshake() error {
220220
c.ccaps&mysql.CLIENT_MULTI_STATEMENTS | c.ccaps&mysql.CLIENT_MULTI_RESULTS |
221221
c.ccaps&mysql.CLIENT_PS_MULTI_RESULTS | c.ccaps&mysql.CLIENT_CONNECT_ATTRS |
222222
c.ccaps&mysql.CLIENT_COMPRESS | c.ccaps&mysql.CLIENT_ZSTD_COMPRESSION_ALGORITHM |
223-
c.ccaps&mysql.CLIENT_LOCAL_FILES
223+
c.ccaps&mysql.CLIENT_LOCAL_FILES | c.ccaps&mysql.CLIENT_DEPRECATE_EOF
224224

225225
capability &^= c.clientExplicitOffCaps
226226

client/resp.go

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -336,33 +336,16 @@ func (c *Conn) readResultsetStreaming(data []byte, binary bool, result *mysql.Re
336336
}
337337

338338
func (c *Conn) readResultColumns(result *mysql.Result) (err error) {
339-
i := 0
340339
var data []byte
341340

342-
for {
341+
for i := range len(result.Fields) {
343342
rawPkgLen := len(result.RawPkg)
344343
result.RawPkg, err = c.ReadPacketReuseMem(result.RawPkg)
345344
if err != nil {
346345
return err
347346
}
348347
data = result.RawPkg[rawPkgLen:]
349348

350-
// EOF Packet
351-
if c.isEOFPacket(data) {
352-
if c.capability&mysql.CLIENT_PROTOCOL_41 > 0 {
353-
result.Warnings = binary.LittleEndian.Uint16(data[1:])
354-
// todo add strict_mode, warning will be treat as error
355-
result.Status = binary.LittleEndian.Uint16(data[3:])
356-
c.status = result.Status
357-
}
358-
359-
if i != len(result.Fields) {
360-
err = mysql.ErrMalformPacket
361-
}
362-
363-
return err
364-
}
365-
366349
if result.Fields[i] == nil {
367350
result.Fields[i] = &mysql.Field{}
368351
}
@@ -372,8 +355,30 @@ func (c *Conn) readResultColumns(result *mysql.Result) (err error) {
372355
}
373356

374357
result.FieldNames[utils.ByteSliceToString(result.Fields[i].Name)] = i
358+
}
359+
360+
if !c.HasCapability(mysql.CLIENT_DEPRECATE_EOF) {
361+
// EOF Packet
362+
rawPkgLen := len(result.RawPkg)
363+
result.RawPkg, err = c.ReadPacketReuseMem(result.RawPkg)
364+
if err != nil {
365+
return err
366+
}
367+
data = result.RawPkg[rawPkgLen:]
375368

376-
i++
369+
if c.isEOFPacket(data) {
370+
if c.capability&mysql.CLIENT_PROTOCOL_41 > 0 {
371+
result.Warnings = binary.LittleEndian.Uint16(data[1:])
372+
// todo add strict_mode, warning will be treat as error
373+
result.Status = binary.LittleEndian.Uint16(data[3:])
374+
c.status = result.Status
375+
}
376+
return nil
377+
} else {
378+
return mysql.ErrMalformPacket
379+
}
380+
} else {
381+
return nil
377382
}
378383
}
379384

@@ -388,15 +393,21 @@ func (c *Conn) readResultRows(result *mysql.Result, isBinary bool) (err error) {
388393
}
389394
data = result.RawPkg[rawPkgLen:]
390395

391-
// EOF Packet
392-
if c.isEOFPacket(data) {
393-
if c.capability&mysql.CLIENT_PROTOCOL_41 > 0 {
396+
if data[0] == mysql.EOF_HEADER && len(data) <= 0xffffff {
397+
if c.HasCapability(mysql.CLIENT_DEPRECATE_EOF) {
398+
// Treat like OK
399+
affectedRows, _, n := mysql.LengthEncodedInt(data[1:])
400+
insertId, _, m := mysql.LengthEncodedInt(data[1+n:])
401+
result.Status = binary.LittleEndian.Uint16(data[1+n+m:])
402+
result.AffectedRows = affectedRows
403+
result.InsertId = insertId
404+
c.status = result.Status
405+
} else if c.capability&mysql.CLIENT_PROTOCOL_41 > 0 {
394406
result.Warnings = binary.LittleEndian.Uint16(data[1:])
395407
// todo add strict_mode, warning will be treat as error
396408
result.Status = binary.LittleEndian.Uint16(data[3:])
397409
c.status = result.Status
398410
}
399-
400411
break
401412
}
402413

0 commit comments

Comments
 (0)