@@ -224,6 +224,7 @@ func (mc *mysqlConn) writeAuthPacket(cipher []byte) error {
224
224
clientTransactions |
225
225
clientLocalFiles |
226
226
clientPluginAuth |
227
+ clientMultiResults |
227
228
mc .flags & clientLongFlag
228
229
229
230
if mc .cfg .ClientFoundRows {
@@ -519,6 +520,10 @@ func (mc *mysqlConn) handleErrorPacket(data []byte) error {
519
520
}
520
521
}
521
522
523
+ func readStatus (b []byte ) statusFlag {
524
+ return statusFlag (b [0 ]) | statusFlag (b [1 ])<< 8
525
+ }
526
+
522
527
// Ok Packet
523
528
// http://dev.mysql.com/doc/internals/en/generic-response-packets.html#packet-OK_Packet
524
529
func (mc * mysqlConn ) handleOkPacket (data []byte ) error {
@@ -533,7 +538,7 @@ func (mc *mysqlConn) handleOkPacket(data []byte) error {
533
538
mc .insertId , _ , m = readLengthEncodedInteger (data [1 + n :])
534
539
535
540
// server_status [2 bytes]
536
- mc .status = statusFlag (data [1 + n + m ]) | statusFlag ( data [ 1 + n + m + 1 ]) << 8
541
+ mc .status = readStatus (data [1 + n + m : 1 + n + m + 2 ])
537
542
538
543
// warning count [2 bytes]
539
544
if ! mc .strict {
@@ -652,6 +657,11 @@ func (rows *textRows) readRow(dest []driver.Value) error {
652
657
653
658
// EOF Packet
654
659
if data [0 ] == iEOF && len (data ) == 5 {
660
+ // server_status [2 bytes]
661
+ rows .mc .status = readStatus (data [3 :])
662
+ if err := rows .mc .discardMoreResultsIfExists (); err != nil {
663
+ return err
664
+ }
655
665
rows .mc = nil
656
666
return io .EOF
657
667
}
@@ -709,6 +719,10 @@ func (mc *mysqlConn) readUntilEOF() error {
709
719
if err == nil && data [0 ] != iEOF {
710
720
continue
711
721
}
722
+ if err == nil && data [0 ] == iEOF && len (data ) == 5 {
723
+ mc .status = readStatus (data [3 :])
724
+ }
725
+
712
726
return err // Err or EOF
713
727
}
714
728
}
@@ -1013,6 +1027,28 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
1013
1027
return mc .writePacket (data )
1014
1028
}
1015
1029
1030
+ func (mc * mysqlConn ) discardMoreResultsIfExists () error {
1031
+ for mc .status & statusMoreResultsExists != 0 {
1032
+ resLen , err := mc .readResultSetHeaderPacket ()
1033
+ if err != nil {
1034
+ return err
1035
+ }
1036
+ if resLen > 0 {
1037
+ // columns
1038
+ if err := mc .readUntilEOF (); err != nil {
1039
+ return err
1040
+ }
1041
+ // rows
1042
+ if err := mc .readUntilEOF (); err != nil {
1043
+ return err
1044
+ }
1045
+ } else {
1046
+ mc .status &^= statusMoreResultsExists
1047
+ }
1048
+ }
1049
+ return nil
1050
+ }
1051
+
1016
1052
// http://dev.mysql.com/doc/internals/en/binary-protocol-resultset-row.html
1017
1053
func (rows * binaryRows ) readRow (dest []driver.Value ) error {
1018
1054
data , err := rows .mc .readPacket ()
@@ -1022,11 +1058,16 @@ func (rows *binaryRows) readRow(dest []driver.Value) error {
1022
1058
1023
1059
// packet indicator [1 byte]
1024
1060
if data [0 ] != iOK {
1025
- rows .mc = nil
1026
1061
// EOF Packet
1027
1062
if data [0 ] == iEOF && len (data ) == 5 {
1063
+ rows .mc .status = readStatus (data [3 :])
1064
+ if err := rows .mc .discardMoreResultsIfExists (); err != nil {
1065
+ return err
1066
+ }
1067
+ rows .mc = nil
1028
1068
return io .EOF
1029
1069
}
1070
+ rows .mc = nil
1030
1071
1031
1072
// Error otherwise
1032
1073
return rows .mc .handleErrorPacket (data )
0 commit comments