File tree Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -24,16 +24,26 @@ var (
2424 errPktTooLarge = errors .New ("Packet for query is too large. You can change this value on the server by adjusting the 'max_allowed_packet' variable." )
2525)
2626
27- // error type which represents one or more MySQL warnings
27+ // error type which represents a single MySQL error
28+ type MySQLError struct {
29+ Number uint16
30+ Message string
31+ }
32+
33+ func (me * MySQLError ) Error () string {
34+ return fmt .Sprintf ("Error %d: %s" , me .Number , me .Message )
35+ }
36+
37+ // error type which represents a group (one ore more) MySQL warnings
2838type MySQLWarnings []mysqlWarning
2939
30- func (mws MySQLWarnings ) Error () string {
40+ func (mws * MySQLWarnings ) Error () string {
3141 var msg string
32- for i := range mws {
42+ for i , warning := range * mws {
3343 if i > 0 {
3444 msg += "\r \n "
3545 }
36- msg += fmt .Sprintf ("%s %s: %s" , mws [ i ] .Level , mws [ i ] .Code , mws [ i ] .Message )
46+ msg += fmt .Sprintf ("%s %s: %s" , warning .Level , warning .Code , warning .Message )
3747 }
3848 return msg
3949}
@@ -83,7 +93,7 @@ func (mc *mysqlConn) getWarnings() (err error) {
8393 warnings = append (warnings , warning )
8494
8595 case io .EOF :
86- return warnings
96+ return & warnings
8797
8898 default :
8999 rows .Close ()
Original file line number Diff line number Diff line change @@ -413,7 +413,10 @@ func (mc *mysqlConn) handleErrorPacket(data []byte) error {
413413 }
414414
415415 // Error Message [string]
416- return fmt .Errorf ("Error %d: %s" , errno , string (data [pos :]))
416+ return & MySQLError {
417+ Number : errno ,
418+ Message : string (data [pos :]),
419+ }
417420}
418421
419422// Ok Packet
You can’t perform that action at this time.
0 commit comments