@@ -214,6 +214,7 @@ func (mc *mysqlConn) writeAuthPacket(cipher []byte) error {
214
214
clientLongPassword |
215
215
clientTransactions |
216
216
clientLocalFiles |
217
+ clientMultiResults |
217
218
mc .flags & clientLongFlag
218
219
219
220
if mc .cfg .clientFoundRows {
@@ -470,6 +471,10 @@ func (mc *mysqlConn) handleErrorPacket(data []byte) error {
470
471
}
471
472
}
472
473
474
+ func readStatus (b []byte ) statusFlag {
475
+ return statusFlag (b [0 ]) | statusFlag (b [1 ])<< 8
476
+ }
477
+
473
478
// Ok Packet
474
479
// http://dev.mysql.com/doc/internals/en/generic-response-packets.html#packet-OK_Packet
475
480
func (mc * mysqlConn ) handleOkPacket (data []byte ) error {
@@ -484,7 +489,7 @@ func (mc *mysqlConn) handleOkPacket(data []byte) error {
484
489
mc .insertId , _ , m = readLengthEncodedInteger (data [1 + n :])
485
490
486
491
// server_status [2 bytes]
487
- mc .status = statusFlag (data [1 + n + m ]) | statusFlag ( data [ 1 + n + m + 1 ]) << 8
492
+ mc .status = readStatus (data [1 + n + m : 1 + n + m + 2 ])
488
493
489
494
// warning count [2 bytes]
490
495
if ! mc .strict {
@@ -603,6 +608,11 @@ func (rows *textRows) readRow(dest []driver.Value) error {
603
608
604
609
// EOF Packet
605
610
if data [0 ] == iEOF && len (data ) == 5 {
611
+ // server_status [2 bytes]
612
+ rows .mc .status = readStatus (data [3 :])
613
+ if err := rows .mc .discardMoreResultsIfExists (); err != nil {
614
+ return err
615
+ }
606
616
rows .mc = nil
607
617
return io .EOF
608
618
}
@@ -660,6 +670,10 @@ func (mc *mysqlConn) readUntilEOF() error {
660
670
if err == nil && data [0 ] != iEOF {
661
671
continue
662
672
}
673
+ if err == nil && data [0 ] == iEOF && len (data ) == 5 {
674
+ mc .status = readStatus (data [3 :])
675
+ }
676
+
663
677
return err // Err or EOF
664
678
}
665
679
}
@@ -964,6 +978,28 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
964
978
return mc .writePacket (data )
965
979
}
966
980
981
+ func (mc * mysqlConn ) discardMoreResultsIfExists () error {
982
+ for mc .status & statusMoreResultsExists != 0 {
983
+ resLen , err := mc .readResultSetHeaderPacket ()
984
+ if err != nil {
985
+ return err
986
+ }
987
+ if resLen > 0 {
988
+ // columns
989
+ if err := mc .readUntilEOF (); err != nil {
990
+ return err
991
+ }
992
+ // rows
993
+ if err := mc .readUntilEOF (); err != nil {
994
+ return err
995
+ }
996
+ } else {
997
+ mc .status &^= statusMoreResultsExists
998
+ }
999
+ }
1000
+ return nil
1001
+ }
1002
+
967
1003
// http://dev.mysql.com/doc/internals/en/binary-protocol-resultset-row.html
968
1004
func (rows * binaryRows ) readRow (dest []driver.Value ) error {
969
1005
data , err := rows .mc .readPacket ()
@@ -973,11 +1009,16 @@ func (rows *binaryRows) readRow(dest []driver.Value) error {
973
1009
974
1010
// packet indicator [1 byte]
975
1011
if data [0 ] != iOK {
976
- rows .mc = nil
977
1012
// EOF Packet
978
1013
if data [0 ] == iEOF && len (data ) == 5 {
1014
+ rows .mc .status = readStatus (data [3 :])
1015
+ if err := rows .mc .discardMoreResultsIfExists (); err != nil {
1016
+ return err
1017
+ }
1018
+ rows .mc = nil
979
1019
return io .EOF
980
1020
}
1021
+ rows .mc = nil
981
1022
982
1023
// Error otherwise
983
1024
return rows .mc .handleErrorPacket (data )
0 commit comments