Skip to content

Commit 2e6c836

Browse files
author
Phil Bayfield
committed
completed changing errors over
1 parent d45a331 commit 2e6c836

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

error.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const (
2626
CR_PARAMS_NOT_BOUND Errno = 2031
2727
CR_DATA_TRUNCATED Errno = 2032
2828
CR_NO_RESULT_SET Errno = 2053
29+
CR_NOT_IMPLEMENTED Errno = 2054
2930
CR_ALREADY_CONNECTED Errno = 2058
3031
)
3132

@@ -48,6 +49,7 @@ const (
4849
CR_PARAMS_NOT_BOUND_STR Error = "No data supplied for parameters in prepared statement"
4950
CR_DATA_TRUNCATED_STR Error = "Data truncated"
5051
CR_NO_RESULT_SET_STR Error = "Attempt to read a row while there is no result set associated with the statement"
52+
CR_NOT_IMPLEMENTED_STR Error = "This feature is not implemented yet"
5153
CR_ALREADY_CONNECTED_STR Error = "This handle is already connected"
5254
)
5355

mysql.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ func (c *Client) reconnect() (err os.Error) {
701701
// Reset the client
702702
c.reset()
703703
// Attempt to reconnect
704-
for i := 0; i < 10; i ++ {
704+
for i := 0; i < 10; i++ {
705705
err = c.connect()
706706
if err == nil {
707707
c.connected = true
@@ -721,34 +721,34 @@ func (c *Client) command(command command, args ...interface{}) (err os.Error) {
721721
// No args
722722
case COM_QUIT, COM_STATISTICS, COM_PROCESS_INFO, COM_DEBUG, COM_PING:
723723
if len(args) != 0 {
724-
err = os.NewError(fmt.Sprintf("Invalid arg count, expected 0 but found %d", len(args)))
724+
return &ClientError{CR_UNKNOWN_ERROR, CR_UNKNOWN_ERROR_STR}
725725
}
726726
// 1 arg
727727
case COM_INIT_DB, COM_QUERY, COM_REFRESH, COM_SHUTDOWN, COM_PROCESS_KILL, COM_STMT_PREPARE, COM_STMT_CLOSE, COM_STMT_RESET:
728728
if len(args) != 1 {
729-
err = os.NewError(fmt.Sprintf("Invalid arg count, expected 1 but found %d", len(args)))
729+
return &ClientError{CR_UNKNOWN_ERROR, CR_UNKNOWN_ERROR_STR}
730730
}
731731
// 1 or 2 args
732732
case COM_FIELD_LIST:
733733
if len(args) != 1 && len(args) != 2 {
734-
err = os.NewError(fmt.Sprintf("Invalid arg count, expected 1 or 2 but found %d", len(args)))
734+
return &ClientError{CR_UNKNOWN_ERROR, CR_UNKNOWN_ERROR_STR}
735735
}
736736
// 2 args
737737
case COM_STMT_FETCH:
738738
if len(args) != 2 {
739-
err = os.NewError(fmt.Sprintf("Invalid arg count, expected 2 but found %d", len(args)))
739+
return &ClientError{CR_UNKNOWN_ERROR, CR_UNKNOWN_ERROR_STR}
740740
}
741741
// 4 args
742742
case COM_CHANGE_USER:
743743
if len(args) != 4 {
744-
err = os.NewError(fmt.Sprintf("Invalid arg count, expected 4 but found %d", len(args)))
744+
return &ClientError{CR_UNKNOWN_ERROR, CR_UNKNOWN_ERROR_STR}
745745
}
746746
// Commands with custom functions
747747
case COM_STMT_EXECUTE, COM_STMT_SEND_LONG_DATA:
748-
err = os.NewError("This command should not be used here")
748+
return &ClientError{CR_NOT_IMPLEMENTED, CR_NOT_IMPLEMENTED_STR}
749749
// Everything else e.g. replication unsupported
750750
default:
751-
err = os.NewError("This command is unsupported")
751+
return &ClientError{CR_NOT_IMPLEMENTED, CR_NOT_IMPLEMENTED_STR}
752752
}
753753
// Construct packet
754754
p := &packetCommand{
@@ -772,8 +772,7 @@ func (c *Client) command(command command, args ...interface{}) (err os.Error) {
772772
func (c *Client) getFields() (err os.Error) {
773773
// Check for a valid result
774774
if c.result == nil {
775-
err = os.NewError("Need a result set to read fields")
776-
return
775+
return &ClientError{CR_NO_RESULT_SET, CR_NO_RESULT_SET_STR}
777776
}
778777
// Read fields till EOF is returned
779778
for {
@@ -793,8 +792,7 @@ func (c *Client) getFields() (err os.Error) {
793792
func (c *Client) getRow() (eof bool, err os.Error) {
794793
// Check for a valid result
795794
if c.result == nil {
796-
err = os.NewError("Need a result set to read rows")
797-
return
795+
return false, &ClientError{CR_NO_RESULT_SET, CR_NO_RESULT_SET_STR}
798796
}
799797
// Read next row packet or EOF
800798
c.sequence++
@@ -828,7 +826,7 @@ func (c *Client) getResult(types packetType) (eof bool, err os.Error) {
828826
// Process result packet
829827
switch i := p.(type) {
830828
default:
831-
err = os.NewError("Unknown or unexpected packet or packet type")
829+
err = &ClientError{CR_UNKNOWN_ERROR, CR_UNKNOWN_ERROR_STR}
832830
case *packetOK:
833831
err = c.processOKResult(p.(*packetOK))
834832
case *packetError:

0 commit comments

Comments
 (0)