Julien Schmidt пре 10 година
родитељ
комит
a059889267
5 измењених фајлова са 43 додато и 43 уклоњено
  1. 16 16
      dsn.go
  2. 13 13
      errors.go
  3. 2 2
      infile.go
  4. 7 7
      packets.go
  5. 5 5
      utils.go

+ 16 - 16
dsn.go

@@ -19,10 +19,10 @@ import (
 )
 
 var (
-	errInvalidDSNUnescaped       = errors.New("Invalid DSN: Did you forget to escape a param value?")
-	errInvalidDSNAddr            = errors.New("Invalid DSN: Network Address not terminated (missing closing brace)")
-	errInvalidDSNNoSlash         = errors.New("Invalid DSN: Missing the slash separating the database name")
-	errInvalidDSNUnsafeCollation = errors.New("Invalid DSN: interpolateParams can be used with ascii, latin1, utf8 and utf8mb4 charset")
+	errInvalidDSNUnescaped       = errors.New("invalid DSN: did you forget to escape a param value?")
+	errInvalidDSNAddr            = errors.New("invalid DSN: network address not terminated (missing closing brace)")
+	errInvalidDSNNoSlash         = errors.New("invalid DSN: missing the slash separating the database name")
+	errInvalidDSNUnsafeCollation = errors.New("invalid DSN: interpolateParams can not be used with unsafe collations")
 )
 
 // Config is a configuration parsed from a DSN string
@@ -141,7 +141,7 @@ func ParseDSN(dsn string) (cfg *Config, err error) {
 		case "unix":
 			cfg.Addr = "/tmp/mysql.sock"
 		default:
-			return nil, errors.New("Default addr for network '" + cfg.Net + "' unknown")
+			return nil, errors.New("default addr for network '" + cfg.Net + "' unknown")
 		}
 
 	}
@@ -166,7 +166,7 @@ func parseDSNParams(cfg *Config, params string) (err error) {
 			var isBool bool
 			cfg.AllowAllFiles, isBool = readBool(value)
 			if !isBool {
-				return fmt.Errorf("Invalid Bool value: %s", value)
+				return errors.New("invalid bool value: " + value)
 			}
 
 		// Use cleartext authentication mode (MySQL 5.5.10+)
@@ -174,7 +174,7 @@ func parseDSNParams(cfg *Config, params string) (err error) {
 			var isBool bool
 			cfg.AllowCleartextPasswords, isBool = readBool(value)
 			if !isBool {
-				return fmt.Errorf("Invalid Bool value: %s", value)
+				return errors.New("invalid bool value: " + value)
 			}
 
 		// Use old authentication mode (pre MySQL 4.1)
@@ -182,7 +182,7 @@ func parseDSNParams(cfg *Config, params string) (err error) {
 			var isBool bool
 			cfg.AllowOldPasswords, isBool = readBool(value)
 			if !isBool {
-				return fmt.Errorf("Invalid Bool value: %s", value)
+				return errors.New("invalid bool value: " + value)
 			}
 
 		// Switch "rowsAffected" mode
@@ -190,7 +190,7 @@ func parseDSNParams(cfg *Config, params string) (err error) {
 			var isBool bool
 			cfg.ClientFoundRows, isBool = readBool(value)
 			if !isBool {
-				return fmt.Errorf("Invalid Bool value: %s", value)
+				return errors.New("invalid bool value: " + value)
 			}
 
 		// Collation
@@ -210,19 +210,19 @@ func parseDSNParams(cfg *Config, params string) (err error) {
 			var isBool bool
 			cfg.ColumnsWithAlias, isBool = readBool(value)
 			if !isBool {
-				return fmt.Errorf("Invalid Bool value: %s", value)
+				return errors.New("invalid bool value: " + value)
 			}
 
 		// Compression
 		case "compress":
-			return errors.New("Compression not implemented yet")
+			return errors.New("compression not implemented yet")
 
 		// Enable client side placeholder substitution
 		case "interpolateParams":
 			var isBool bool
 			cfg.InterpolateParams, isBool = readBool(value)
 			if !isBool {
-				return fmt.Errorf("Invalid Bool value: %s", value)
+				return errors.New("invalid bool value: " + value)
 			}
 
 		// Time Location
@@ -240,7 +240,7 @@ func parseDSNParams(cfg *Config, params string) (err error) {
 			var isBool bool
 			cfg.ParseTime, isBool = readBool(value)
 			if !isBool {
-				return errors.New("Invalid Bool value: " + value)
+				return errors.New("invalid bool value: " + value)
 			}
 
 		// I/O read Timeout
@@ -255,7 +255,7 @@ func parseDSNParams(cfg *Config, params string) (err error) {
 			var isBool bool
 			cfg.Strict, isBool = readBool(value)
 			if !isBool {
-				return errors.New("Invalid Bool value: " + value)
+				return errors.New("invalid bool value: " + value)
 			}
 
 		// Dial Timeout
@@ -273,7 +273,7 @@ func parseDSNParams(cfg *Config, params string) (err error) {
 					cfg.TLS = &tls.Config{}
 				}
 			} else if value, err := url.QueryUnescape(value); err != nil {
-				return fmt.Errorf("Invalid value for tls config name: %v", err)
+				return fmt.Errorf("invalid value for TLS config name: %v", err)
 			} else {
 				if strings.ToLower(value) == "skip-verify" {
 					cfg.TLS = &tls.Config{InsecureSkipVerify: true}
@@ -287,7 +287,7 @@ func parseDSNParams(cfg *Config, params string) (err error) {
 
 					cfg.TLS = tlsConfig
 				} else {
-					return fmt.Errorf("Invalid value / unknown config name: %s", value)
+					return errors.New("invalid value / unknown config name: " + value)
 				}
 			}
 

+ 13 - 13
errors.go

@@ -19,20 +19,20 @@ import (
 
 // Various errors the driver might return. Can change between driver versions.
 var (
-	ErrInvalidConn       = errors.New("Invalid Connection")
-	ErrMalformPkt        = errors.New("Malformed Packet")
-	ErrNoTLS             = errors.New("TLS encryption requested but server does not support TLS")
-	ErrOldPassword       = errors.New("This user requires old password authentication. If you still want to use it, please add 'allowOldPasswords=1' to your DSN. See also https://github.com/go-sql-driver/mysql/wiki/old_passwords")
-	ErrCleartextPassword = errors.New("This user requires clear text authentication. If you still want to use it, please add 'allowCleartextPasswords=1' to your DSN.")
-	ErrUnknownPlugin     = errors.New("The authentication plugin is not supported.")
-	ErrOldProtocol       = errors.New("MySQL-Server does not support required Protocol 41+")
-	ErrPktSync           = errors.New("Commands out of sync. You can't run this command now")
-	ErrPktSyncMul        = errors.New("Commands out of sync. Did you run multiple statements at once?")
-	ErrPktTooLarge       = errors.New("Packet for query is too large. You can change this value on the server by adjusting the 'max_allowed_packet' variable.")
-	ErrBusyBuffer        = errors.New("Busy buffer")
+	ErrInvalidConn       = errors.New("invalid connection")
+	ErrMalformPkt        = errors.New("malformed packet")
+	ErrNoTLS             = errors.New("TLS requested but server does not support TLS")
+	ErrOldPassword       = errors.New("this user requires old password authentication. If you still want to use it, please add 'allowOldPasswords=1' to your DSN. See also https://github.com/go-sql-driver/mysql/wiki/old_passwords")
+	ErrCleartextPassword = errors.New("this user requires clear text authentication. If you still want to use it, please add 'allowCleartextPasswords=1' to your DSN")
+	ErrUnknownPlugin     = errors.New("this authentication plugin is not supported")
+	ErrOldProtocol       = errors.New("MySQL server does not support required protocol 41+")
+	ErrPktSync           = errors.New("commands out of sync. You can't run this command now")
+	ErrPktSyncMul        = errors.New("commands out of sync. Did you run multiple statements at once?")
+	ErrPktTooLarge       = errors.New("packet for query is too large. Try adjusting the 'max_allowed_packet' variable on the server")
+	ErrBusyBuffer        = errors.New("busy buffer")
 )
 
-var errLog = Logger(log.New(os.Stderr, "[MySQL] ", log.Ldate|log.Ltime|log.Lshortfile))
+var errLog = Logger(log.New(os.Stderr, "[mysql] ", log.Ldate|log.Ltime|log.Lshortfile))
 
 // Logger is used to log critical error messages.
 type Logger interface {
@@ -56,7 +56,7 @@ type MySQLError struct {
 }
 
 func (me *MySQLError) Error() string {
-	return fmt.Sprintf("Error %d: %s", me.Number, me.Message)
+	return fmt.Sprintf("error %d: %s", me.Number, me.Message)
 }
 
 // MySQLWarnings is an error type which represents a group of one or more MySQL

+ 2 - 2
infile.go

@@ -139,12 +139,12 @@ func (mc *mysqlConn) handleInFileRequest(name string) (err error) {
 					} else if fileSize <= mc.maxPacketAllowed {
 						data = make([]byte, 4+mc.maxWriteSize)
 					} else {
-						err = fmt.Errorf("Local File '%s' too large: Size: %d, Max: %d", name, fileSize, mc.maxPacketAllowed)
+						err = fmt.Errorf("local file '%s' too large: size: %d, max: %d", name, fileSize, mc.maxPacketAllowed)
 					}
 				}
 			}
 		} else {
-			err = fmt.Errorf("Local File '%s' is not registered. Use the DSN parameter 'allowAllFiles=true' to allow all files", name)
+			err = fmt.Errorf("local file '%s' is not registered", name)
 		}
 	}
 

+ 7 - 7
packets.go

@@ -145,7 +145,7 @@ func (mc *mysqlConn) readInitPacket() ([]byte, error) {
 	// protocol version [1 byte]
 	if data[0] < minProtocolVersion {
 		return nil, fmt.Errorf(
-			"Unsupported MySQL Protocol Version %d. Protocol Version %d or higher is required",
+			"unsupported protocol version %d. Version %d or higher is required",
 			data[0],
 			minProtocolVersion,
 		)
@@ -563,7 +563,7 @@ func (mc *mysqlConn) readColumns(count int) ([]mysqlField, error) {
 			if i == count {
 				return columns, nil
 			}
-			return nil, fmt.Errorf("ColumnsCount mismatch n:%d len:%d", count, len(columns))
+			return nil, fmt.Errorf("columns count mismatch n:%d len:%d", count, len(columns))
 		}
 
 		// Catalog
@@ -809,7 +809,7 @@ func (stmt *mysqlStmt) writeCommandLongData(paramID int, arg []byte) error {
 func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
 	if len(args) != stmt.paramCount {
 		return fmt.Errorf(
-			"Arguments count mismatch (Got: %d Has: %d)",
+			"arguments count mismatch (got: %d; has: %d)",
 			len(args),
 			stmt.paramCount,
 		)
@@ -995,7 +995,7 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
 				paramValues = append(paramValues, val...)
 
 			default:
-				return fmt.Errorf("Can't convert type: %T", arg)
+				return fmt.Errorf("can not convert type: %T", arg)
 			}
 		}
 
@@ -1143,7 +1143,7 @@ func (rows *binaryRows) readRow(dest []driver.Value) error {
 					dstlen = 8 + 1 + decimals
 				default:
 					return fmt.Errorf(
-						"MySQL protocol error, illegal decimals value %d",
+						"protocol error, illegal decimals value %d",
 						rows.columns[i].decimals,
 					)
 				}
@@ -1162,7 +1162,7 @@ func (rows *binaryRows) readRow(dest []driver.Value) error {
 						dstlen = 19 + 1 + decimals
 					default:
 						return fmt.Errorf(
-							"MySQL protocol error, illegal decimals value %d",
+							"protocol error, illegal decimals value %d",
 							rows.columns[i].decimals,
 						)
 					}
@@ -1179,7 +1179,7 @@ func (rows *binaryRows) readRow(dest []driver.Value) error {
 
 		// Please report if this happens!
 		default:
-			return fmt.Errorf("Unknown FieldType %d", rows.columns[i].fieldType)
+			return fmt.Errorf("unknown field type %d", rows.columns[i].fieldType)
 		}
 	}
 

+ 5 - 5
utils.go

@@ -48,7 +48,7 @@ var (
 //
 func RegisterTLSConfig(key string, config *tls.Config) error {
 	if _, isBool := readBool(key); isBool || strings.ToLower(key) == "skip-verify" {
-		return fmt.Errorf("Key '%s' is reserved", key)
+		return fmt.Errorf("key '%s' is reserved", key)
 	}
 
 	if tlsConfigRegister == nil {
@@ -260,7 +260,7 @@ func parseDateTime(str string, loc *time.Location) (t time.Time, err error) {
 		}
 		t, err = time.Parse(timeFormat[:len(str)], str)
 	default:
-		err = fmt.Errorf("Invalid Time-String: %s", str)
+		err = fmt.Errorf("invalid time string: %s", str)
 		return
 	}
 
@@ -309,7 +309,7 @@ func parseBinaryDateTime(num uint64, data []byte, loc *time.Location) (driver.Va
 			loc,
 		), nil
 	}
-	return nil, fmt.Errorf("Invalid DATETIME-packet length %d", num)
+	return nil, fmt.Errorf("invalid DATETIME packet length %d", num)
 }
 
 // zeroDateTime is used in formatBinaryDateTime to avoid an allocation
@@ -344,7 +344,7 @@ func formatBinaryDateTime(src []byte, length uint8, justTime bool) (driver.Value
 		switch len(src) {
 		case 8, 12:
 		default:
-			return nil, fmt.Errorf("Invalid TIME-packet length %d", len(src))
+			return nil, fmt.Errorf("invalid TIME packet length %d", len(src))
 		}
 		// +2 to enable negative time and 100+ hours
 		dst = make([]byte, 0, length+2)
@@ -378,7 +378,7 @@ func formatBinaryDateTime(src []byte, length uint8, justTime bool) (driver.Value
 			if length > 10 {
 				t += "TIME"
 			}
-			return nil, fmt.Errorf("illegal %s-packet length %d", t, len(src))
+			return nil, fmt.Errorf("illegal %s packet length %d", t, len(src))
 		}
 		dst = make([]byte, 0, length)
 		// start with the date