Documentation ¶
Overview ¶
Package mysql wraps the C client library for MySQL.
Index ¶
- Constants
- func BuildValue(bytes []byte, fieldType uint32) sqltypes.Value
- type Connection
- func (conn *Connection) Close()
- func (conn *Connection) CloseResult()
- func (conn *Connection) ExecuteFetch(query string, maxrows int, wantfields bool) (qr *proto.QueryResult, err error)
- func (conn *Connection) ExecuteFetchMap(query string) (map[string]string, error)
- func (conn *Connection) ExecuteStreamFetch(query string) (err error)
- func (conn *Connection) FetchNext() (row []sqltypes.Value, err error)
- func (conn *Connection) Fields() (fields []proto.Field)
- func (conn *Connection) GetCharset() (cs proto.Charset, err error)
- func (conn *Connection) ID() int64
- func (conn *Connection) IsClosed() bool
- func (conn *Connection) ReadPacket() ([]byte, error)
- func (conn *Connection) SendCommand(command uint32, data []byte) error
- func (conn *Connection) SetCharset(cs proto.Charset) error
- func (conn *Connection) Shutdown()
- type ConnectionParams
- type SqlError
Constants ¶
const ( // ErrDupEntry is C.ER_DUP_ENTRY ErrDupEntry = C.ER_DUP_ENTRY // ErrLockWaitTimeout is C.ER_LOCK_WAIT_TIMEOUT ErrLockWaitTimeout = C.ER_LOCK_WAIT_TIMEOUT // ErrLockDeadlock is C.ER_LOCK_DEADLOCK ErrLockDeadlock = C.ER_LOCK_DEADLOCK // ErrOptionPreventsStatement is C.ER_OPTION_PREVENTS_STATEMENT ErrOptionPreventsStatement = C.ER_OPTION_PREVENTS_STATEMENT // RedactedPassword is the password value used in redacted configs RedactedPassword = "****" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection encapsulates a C mysql library connection
func Connect ¶
func Connect(params ConnectionParams) (conn *Connection, err error)
Connect uses the connection parameters to connect and returns the connection
func (*Connection) CloseResult ¶
func (conn *Connection) CloseResult()
CloseResult finishes the result set
func (*Connection) ExecuteFetch ¶
func (conn *Connection) ExecuteFetch(query string, maxrows int, wantfields bool) (qr *proto.QueryResult, err error)
ExecuteFetch executes the query on the connection
func (*Connection) ExecuteFetchMap ¶
func (conn *Connection) ExecuteFetchMap(query string) (map[string]string, error)
ExecuteFetchMap returns a map from column names to cell data for a query that should return exactly 1 row.
func (*Connection) ExecuteStreamFetch ¶
func (conn *Connection) ExecuteStreamFetch(query string) (err error)
ExecuteStreamFetch starts a streaming query to mysql. Use FetchNext on the Connection until it returns nil or error
func (*Connection) FetchNext ¶
func (conn *Connection) FetchNext() (row []sqltypes.Value, err error)
FetchNext returns the next row for a query
func (*Connection) Fields ¶
func (conn *Connection) Fields() (fields []proto.Field)
Fields returns the current fields description for the query
func (*Connection) GetCharset ¶
func (conn *Connection) GetCharset() (cs proto.Charset, err error)
GetCharset returns the current numerical values of the per-session character set variables.
func (*Connection) ID ¶
func (conn *Connection) ID() int64
ID returns the MySQL thread_id of the connection.
func (*Connection) IsClosed ¶
func (conn *Connection) IsClosed() bool
IsClosed returns if the connection was ever closed
func (*Connection) ReadPacket ¶
func (conn *Connection) ReadPacket() ([]byte, error)
ReadPacket reads a raw packet from the MySQL connection.
A MySQL packet is "a single SQL statement sent to the MySQL server, a single row that is sent to the client, or a binary log event sent from a master replication server to a slave." -MySQL 5.1 Reference Manual
func (*Connection) SendCommand ¶
func (conn *Connection) SendCommand(command uint32, data []byte) error
SendCommand sends a raw command to the MySQL server.
func (*Connection) SetCharset ¶
func (conn *Connection) SetCharset(cs proto.Charset) error
SetCharset changes the per-session character set variables.
func (*Connection) Shutdown ¶
func (conn *Connection) Shutdown()
Shutdown invokes the low-level shutdown call on the socket associated with a MySQL connection to stop ongoing communication. This is necessary when a thread is blocked in a MySQL I/O call, such as ReadPacket(), and another thread wants to cancel the operation. We can't use mysql_close() because it isn't thread-safe.
type ConnectionParams ¶
type ConnectionParams struct { Host string `json:"host"` Port int `json:"port"` Uname string `json:"uname"` Pass string `json:"pass"` DbName string `json:"dbname"` UnixSocket string `json:"unix_socket"` Charset string `json:"charset"` Flags uint64 `json:"flags"` // the following flags are only used for 'Change Master' command // for now (along with flags |= 2048 for CLIENT_SSL) SslCa string `json:"ssl_ca"` SslCaPath string `json:"ssl_ca_path"` SslCert string `json:"ssl_cert"` SslKey string `json:"ssl_key"` }
ConnectionParams contains all the parameters to use to connect to mysql
func (*ConnectionParams) EnableMultiStatements ¶
func (c *ConnectionParams) EnableMultiStatements()
EnableMultiStatements will set the right flag on the parameters
func (*ConnectionParams) EnableSSL ¶
func (c *ConnectionParams) EnableSSL()
EnableSSL will set the right flag on the parameters
func (*ConnectionParams) Redact ¶
func (c *ConnectionParams) Redact()
Redact will alter the ConnectionParams so they can be displayed
func (*ConnectionParams) SslEnabled ¶
func (c *ConnectionParams) SslEnabled() bool
SslEnabled returns if SSL is enabled
type SqlError ¶
SqlError is the error structure returned from calling a mysql library function
func NewSqlError ¶
NewSqlError returns a new SqlError