File tree 7 files changed +39
-29
lines changed 7 files changed +39
-29
lines changed Original file line number Diff line number Diff line change 22
22
import json
23
23
go = [
24
24
# Keep the most recent production release at the top
25
- '1.17 ',
25
+ '1.18 ',
26
26
# Older production releases
27
+ '1.17',
27
28
'1.16',
28
29
'1.15',
29
30
'1.14',
Original file line number Diff line number Diff line change @@ -110,6 +110,7 @@ Ziheng Lyu <zihenglv at gmail.com>
110
110
Barracuda Networks, Inc.
111
111
Counting Ltd.
112
112
DigitalOcean Inc.
113
+ dyves labs AG
113
114
Facebook Inc.
114
115
GitHub Inc.
115
116
Google Inc.
Original file line number Diff line number Diff line change @@ -56,11 +56,16 @@ func SetLogger(logger Logger) error {
56
56
57
57
// MySQLError is an error type which represents a single MySQL error
58
58
type MySQLError struct {
59
- Number uint16
60
- Message string
59
+ Number uint16
60
+ SQLState [5 ]byte
61
+ Message string
61
62
}
62
63
63
64
func (me * MySQLError ) Error () string {
65
+ if me .SQLState != [5 ]byte {} {
66
+ return fmt .Sprintf ("Error %d (%s): %s" , me .Number , me .SQLState , me .Message )
67
+ }
68
+
64
69
return fmt .Sprintf ("Error %d: %s" , me .Number , me .Message )
65
70
}
66
71
Original file line number Diff line number Diff line change @@ -43,13 +43,13 @@ func TestErrorsStrictIgnoreNotes(t *testing.T) {
43
43
}
44
44
45
45
func TestMySQLErrIs (t * testing.T ) {
46
- infraErr := & MySQLError {1234 , "the server is on fire" }
47
- otherInfraErr := & MySQLError {1234 , "the datacenter is flooded" }
46
+ infraErr := & MySQLError {Number : 1234 , Message : "the server is on fire" }
47
+ otherInfraErr := & MySQLError {Number : 1234 , Message : "the datacenter is flooded" }
48
48
if ! errors .Is (infraErr , otherInfraErr ) {
49
49
t .Errorf ("expected errors to be the same: %+v %+v" , infraErr , otherInfraErr )
50
50
}
51
51
52
- differentCodeErr := & MySQLError {5678 , "the server is on fire" }
52
+ differentCodeErr := & MySQLError {Number : 5678 , Message : "the server is on fire" }
53
53
if errors .Is (infraErr , differentCodeErr ) {
54
54
t .Fatalf ("expected errors to be different: %+v %+v" , infraErr , differentCodeErr )
55
55
}
Original file line number Diff line number Diff line change @@ -93,10 +93,12 @@ func deferredClose(err *error, closer io.Closer) {
93
93
}
94
94
}
95
95
96
+ const defaultPacketSize = 16 * 1024 // 16KB is small enough for disk readahead and large enough for TCP
97
+
96
98
func (mc * okHandler ) handleInFileRequest (name string ) (err error ) {
97
99
var rdr io.Reader
98
100
var data []byte
99
- packetSize := 16 * 1024 // 16KB is small enough for disk readahead and large enough for TCP
101
+ packetSize := defaultPacketSize
100
102
if mc .maxWriteSize < packetSize {
101
103
packetSize = mc .maxWriteSize
102
104
}
Original file line number Diff line number Diff line change @@ -593,19 +593,20 @@ func (mc *mysqlConn) handleErrorPacket(data []byte) error {
593
593
return driver .ErrBadConn
594
594
}
595
595
596
+ me := & MySQLError {Number : errno }
597
+
596
598
pos := 3
597
599
598
600
// SQL State [optional: # + 5bytes string]
599
601
if data [3 ] == 0x23 {
600
- //sqlstate := string( data[4 : 4+5])
602
+ copy ( me . SQLState [:], data [4 : 4 + 5 ])
601
603
pos = 9
602
604
}
603
605
604
606
// Error Message [string]
605
- return & MySQLError {
606
- Number : errno ,
607
- Message : string (data [pos :]),
608
- }
607
+ me .Message = string (data [pos :])
608
+
609
+ return me
609
610
}
610
611
611
612
func readStatus (b []byte ) statusFlag {
Original file line number Diff line number Diff line change @@ -542,7 +542,7 @@ func stringToInt(b []byte) int {
542
542
return val
543
543
}
544
544
545
- // returns the string read as a bytes slice, wheter the value is NULL,
545
+ // returns the string read as a bytes slice, whether the value is NULL,
546
546
// the number of bytes read and an error, in case the string is longer than
547
547
// the input slice
548
548
func readLengthEncodedString (b []byte ) ([]byte , bool , int , error ) {
@@ -652,32 +652,32 @@ func escapeBytesBackslash(buf, v []byte) []byte {
652
652
for _ , c := range v {
653
653
switch c {
654
654
case '\x00' :
655
- buf [pos ] = '\\'
656
655
buf [pos + 1 ] = '0'
656
+ buf [pos ] = '\\'
657
657
pos += 2
658
658
case '\n' :
659
- buf [pos ] = '\\'
660
659
buf [pos + 1 ] = 'n'
660
+ buf [pos ] = '\\'
661
661
pos += 2
662
662
case '\r' :
663
- buf [pos ] = '\\'
664
663
buf [pos + 1 ] = 'r'
664
+ buf [pos ] = '\\'
665
665
pos += 2
666
666
case '\x1a' :
667
- buf [pos ] = '\\'
668
667
buf [pos + 1 ] = 'Z'
668
+ buf [pos ] = '\\'
669
669
pos += 2
670
670
case '\'' :
671
- buf [pos ] = '\\'
672
671
buf [pos + 1 ] = '\''
672
+ buf [pos ] = '\\'
673
673
pos += 2
674
674
case '"' :
675
- buf [pos ] = '\\'
676
675
buf [pos + 1 ] = '"'
676
+ buf [pos ] = '\\'
677
677
pos += 2
678
678
case '\\' :
679
- buf [pos ] = '\\'
680
679
buf [pos + 1 ] = '\\'
680
+ buf [pos ] = '\\'
681
681
pos += 2
682
682
default :
683
683
buf [pos ] = c
@@ -697,32 +697,32 @@ func escapeStringBackslash(buf []byte, v string) []byte {
697
697
c := v [i ]
698
698
switch c {
699
699
case '\x00' :
700
- buf [pos ] = '\\'
701
700
buf [pos + 1 ] = '0'
701
+ buf [pos ] = '\\'
702
702
pos += 2
703
703
case '\n' :
704
- buf [pos ] = '\\'
705
704
buf [pos + 1 ] = 'n'
705
+ buf [pos ] = '\\'
706
706
pos += 2
707
707
case '\r' :
708
- buf [pos ] = '\\'
709
708
buf [pos + 1 ] = 'r'
709
+ buf [pos ] = '\\'
710
710
pos += 2
711
711
case '\x1a' :
712
- buf [pos ] = '\\'
713
712
buf [pos + 1 ] = 'Z'
713
+ buf [pos ] = '\\'
714
714
pos += 2
715
715
case '\'' :
716
- buf [pos ] = '\\'
717
716
buf [pos + 1 ] = '\''
717
+ buf [pos ] = '\\'
718
718
pos += 2
719
719
case '"' :
720
- buf [pos ] = '\\'
721
720
buf [pos + 1 ] = '"'
721
+ buf [pos ] = '\\'
722
722
pos += 2
723
723
case '\\' :
724
- buf [pos ] = '\\'
725
724
buf [pos + 1 ] = '\\'
725
+ buf [pos ] = '\\'
726
726
pos += 2
727
727
default :
728
728
buf [pos ] = c
@@ -744,8 +744,8 @@ func escapeBytesQuotes(buf, v []byte) []byte {
744
744
745
745
for _ , c := range v {
746
746
if c == '\'' {
747
- buf [pos ] = '\''
748
747
buf [pos + 1 ] = '\''
748
+ buf [pos ] = '\''
749
749
pos += 2
750
750
} else {
751
751
buf [pos ] = c
@@ -764,8 +764,8 @@ func escapeStringQuotes(buf []byte, v string) []byte {
764
764
for i := 0 ; i < len (v ); i ++ {
765
765
c := v [i ]
766
766
if c == '\'' {
767
- buf [pos ] = '\''
768
767
buf [pos + 1 ] = '\''
768
+ buf [pos ] = '\''
769
769
pos += 2
770
770
} else {
771
771
buf [pos ] = c
You can’t perform that action at this time.
0 commit comments