Browse Source

Bloat the API a bit less

Since MySQL warnings only appear in groups in the wild, we don't need to
export the struct for a single warning.
The details are still accessible:
if mws, ok := err.(mysql.MySQLWarnings); ok {
_ = mws[0].Code
}
Julien Schmidt 12 years ago
parent
commit
c4a6e95e42
1 changed files with 5 additions and 9 deletions
  1. 5 9
      errors.go

+ 5 - 9
errors.go

@@ -25,7 +25,7 @@ var (
 )
 
 // error type which represents one or more MySQL warnings
-type MySQLWarnings []MySQLWarning
+type MySQLWarnings []mysqlWarning
 
 func (mws MySQLWarnings) Error() string {
 	var msg string
@@ -33,22 +33,18 @@ func (mws MySQLWarnings) Error() string {
 		if i > 0 {
 			msg += "\r\n"
 		}
-		msg += mws[i].Error()
+		msg += fmt.Sprintf("%s %s: %s", mws[i].Level, mws[i].Code, mws[i].Message)
 	}
 	return msg
 }
 
 // error type which represents a single MySQL warning
-type MySQLWarning struct {
+type mysqlWarning struct {
 	Level   string
 	Code    string
 	Message string
 }
 
-func (mw MySQLWarning) Error() string {
-	return fmt.Sprintf("%s %s: %s", mw.Level, mw.Code, mw.Message)
-}
-
 func (mc *mysqlConn) getWarnings() (err error) {
 	rows, err := mc.Query("SHOW WARNINGS", []driver.Value{})
 	if err != nil {
@@ -58,7 +54,7 @@ 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
 
@@ -66,7 +62,7 @@ func (mc *mysqlConn) getWarnings() (err error) {
 		err = rows.Next(values)
 		switch err {
 		case nil:
-			warning = MySQLWarning{}
+			warning = mysqlWarning{}
 
 			if raw, ok = values[0].([]byte); ok {
 				warning.Level = string(raw)