2024-02-18 10:42:21 +00:00
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
//
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// Copyright 2013 The Go-MySQL-Driver Authors. All rights reserved.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
//
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// This Source Code Form is subject to the terms of the Mozilla Public
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// You can obtain one at http://mozilla.org/MPL/2.0/.
package mysql
import (
"errors"
"fmt"
"log"
"os"
)
// Various errors the driver might return. Can change between driver versions.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
var (
2024-07-24 23:45:04 +00:00
ErrInvalidConn = errors . New ( "invalid connection" )
ErrMalformPkt = errors . New ( "malformed packet" )
ErrNoTLS = errors . New ( "TLS requested but server does not support TLS" )
2024-02-18 10:42:21 +00:00
ErrCleartextPassword = errors . New ( "this user requires clear text authentication. If you still want to use it, please add 'allowCleartextPasswords=1' to your DSN" )
2024-07-24 23:45:04 +00:00
ErrNativePassword = errors . New ( "this user requires mysql native password authentication." )
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" )
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" )
2024-02-18 10:42:21 +00:00
// errBadConnNoWrite is used for connection errors where nothing was sent to the database yet.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// If this happens first in a function starting a database interaction, it should be replaced by driver.ErrBadConn
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// to trigger a resend.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// See https://github.com/go-sql-driver/mysql/pull/302
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
errBadConnNoWrite = errors . New ( "bad connection" )
)
var errLog = Logger ( log . New ( os . Stderr , "[mysql] " , log . Ldate | log . Ltime | log . Lshortfile ) )
// Logger is used to log critical error messages.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
type Logger interface {
Print ( v ... interface { } )
}
// SetLogger is used to set the logger for critical errors.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
// The initial logger is os.Stderr.
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
func SetLogger ( logger Logger ) error {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
if logger == nil {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return errors . New ( "logger is nil" )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
errLog = logger
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return nil
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}
// MySQLError is an error type which represents a single MySQL error
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
type MySQLError struct {
2024-07-24 23:45:04 +00:00
Number uint16
2024-02-18 10:42:21 +00:00
Message string
}
func ( me * MySQLError ) Error ( ) string {
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
return fmt . Sprintf ( "Error %d: %s" , me . Number , me . Message )
2024-07-24 23:45:04 +00:00
2024-02-18 10:42:21 +00:00
}