2
2
//
3
3
// Copyright 2012 Julien Schmidt. All rights reserved.
4
4
// http://www.julienschmidt.com
5
- //
5
+ //
6
6
// This Source Code Form is subject to the terms of the Mozilla Public
7
7
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
8
8
// You can obtain one at http://mozilla.org/MPL/2.0/.
@@ -41,7 +41,11 @@ func (mc *mysqlConn) readPacket() ([]byte, error) {
41
41
42
42
// Check Packet Sync
43
43
if uint8 (pktSeq ) != mc .sequence {
44
- e = errors .New ("Commands out of sync; you can't run this command now" )
44
+ if uint8 (pktSeq ) > mc .sequence {
45
+ e = errors .New ("Commands out of sync. Did you run multiple statements at once?" )
46
+ } else {
47
+ e = errors .New ("Commands out of sync; you can't run this command now" )
48
+ }
45
49
return nil , e
46
50
}
47
51
mc .sequence ++
@@ -113,7 +117,7 @@ func (mc *mysqlConn) writePacket(data *[]byte) error {
113
117
* Initialisation Process *
114
118
******************************************************************************/
115
119
116
- /* Handshake Initialization Packet
120
+ /* Handshake Initialization Packet
117
121
Bytes Name
118
122
----- ----
119
123
1 protocol_version
@@ -127,7 +131,7 @@ func (mc *mysqlConn) writePacket(data *[]byte) error {
127
131
2 server capabilities (two upper bytes)
128
132
1 length of the scramble
129
133
10 (filler) always 0
130
- n rest of the plugin provided data (at least 12 bytes)
134
+ n rest of the plugin provided data (at least 12 bytes)
131
135
1 \0 byte, terminating the second part of a scramble
132
136
*/
133
137
func (mc * mysqlConn ) readInitPacket () (e error ) {
@@ -187,7 +191,7 @@ func (mc *mysqlConn) readInitPacket() (e error) {
187
191
return
188
192
}
189
193
190
- /* Client Authentication Packet
194
+ /* Client Authentication Packet
191
195
Bytes Name
192
196
----- ----
193
197
4 client_flags
@@ -355,7 +359,7 @@ func (mc *mysqlConn) readResultOK() (e error) {
355
359
return
356
360
}
357
361
358
- /* Error Packet
362
+ /* Error Packet
359
363
Bytes Name
360
364
----- ----
361
365
1 field_count, always = 0xff
@@ -387,7 +391,7 @@ func (mc *mysqlConn) handleErrorPacket(data []byte) (e error) {
387
391
return
388
392
}
389
393
390
- /* Ok Packet
394
+ /* Ok Packet
391
395
Bytes Name
392
396
----- ----
393
397
1 (Length Coded Binary) field_count, always = 0
@@ -427,13 +431,13 @@ func (mc *mysqlConn) handleOkPacket(data []byte) (e error) {
427
431
return
428
432
}
429
433
430
- /* Result Set Header Packet
434
+ /* Result Set Header Packet
431
435
Bytes Name
432
436
----- ----
433
437
1-9 (Length-Coded-Binary) field_count
434
438
1-9 (Length-Coded-Binary) extra
435
439
436
- The order of packets for a result set is:
440
+ The order of packets for a result set is:
437
441
(Result Set Header Packet) the number of columns
438
442
(Field Packets) column descriptors
439
443
(EOF Packet) marker: end of Field Packets
@@ -630,14 +634,14 @@ func (mc *mysqlConn) readUntilEOF() (count uint64, e error) {
630
634
* Prepared Statements *
631
635
******************************************************************************/
632
636
633
- /* Prepare Result Packets
637
+ /* Prepare Result Packets
634
638
Type Of Result Packet Hexadecimal Value Of First Byte (field_count)
635
639
--------------------- ---------------------------------------------
636
640
637
641
Prepare OK Packet 00
638
642
Error Packet ff
639
643
640
- Prepare OK Packet
644
+ Prepare OK Packet
641
645
Bytes Name
642
646
----- ----
643
647
1 0 - marker for OK packet
@@ -652,10 +656,10 @@ Prepare OK Packet
652
656
a PREPARE_OK packet
653
657
if "number of parameters" > 0
654
658
(field packets) as in a Result Set Header Packet
655
- (EOF packet)
659
+ (EOF packet)
656
660
if "number of columns" > 0
657
661
(field packets) as in a Result Set Header Packet
658
- (EOF packet)
662
+ (EOF packet)
659
663
660
664
*/
661
665
func (stmt mysqlStmt ) readPrepareResultPacket () (columnCount uint16 , e error ) {
@@ -702,7 +706,7 @@ Bytes Name
702
706
1 new_parameter_bound_flag
703
707
if new_params_bound == 1:
704
708
n*2 type of parameters
705
- n values for the parameters
709
+ n values for the parameters
706
710
*/
707
711
func (stmt mysqlStmt ) buildExecutePacket (args * []driver.Value ) (e error ) {
708
712
argsLen := len (* args )
@@ -723,7 +727,7 @@ func (stmt mysqlStmt) buildExecutePacket(args *[]driver.Value) (e error) {
723
727
var i , valLen int
724
728
var pv reflect.Value
725
729
for i = 0 ; i < stmt .paramCount ; i ++ {
726
- // build nullBitMap
730
+ // build nullBitMap
727
731
if (* args )[i ] == nil {
728
732
bitMask += 1 << uint (i )
729
733
}
0 commit comments