Skip to content

errors: Export MySQLWarning #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 9, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var (
errPktTooLarge = errors.New("Packet for query is too large. You can change this value on the server by adjusting the 'max_allowed_packet' variable.")
)

// error type which represents a single MySQL error
// MySQLError is an error type which represents a single MySQL error
type MySQLError struct {
Number uint16
Message string
Expand All @@ -36,22 +36,29 @@ func (me *MySQLError) Error() string {
return fmt.Sprintf("Error %d: %s", me.Number, me.Message)
}

// error type which represents a group of one or more MySQL warnings
type MySQLWarnings []mysqlWarning
// MySQLWarnings is an error type which represents a group of one or more MySQL
// warnings
type MySQLWarnings []MysqlWarning

func (mws MySQLWarnings) Error() string {
var msg string
for i, warning := range mws {
if i > 0 {
msg += "\r\n"
}
msg += fmt.Sprintf("%s %s: %s", warning.Level, warning.Code, warning.Message)
msg += fmt.Sprintf(
"%s %s: %s",
warning.Level,
warning.Code,
warning.Message,
)
}
return msg
}

// error type which represents a single MySQL warning
type mysqlWarning struct {
// MysqlWarning is an error type which represents a single MySQL warning.
// Warnings are returned in groups only. See MySQLWarnings
type MysqlWarning struct {
Level string
Code string
Message string
Expand All @@ -66,15 +73,15 @@ func (mc *mysqlConn) getWarnings() (err error) {
var warnings = MySQLWarnings{}
var values = make([]driver.Value, 3)

var warning mysqlWarning
var warning MysqlWarning
var raw []byte
var ok bool

for {
err = rows.Next(values)
switch err {
case nil:
warning = mysqlWarning{}
warning = MysqlWarning{}

if raw, ok = values[0].([]byte); ok {
warning.Level = string(raw)
Expand Down