Documentation ¶
Index ¶
- func DeregisterServerPubKey(name string)
- func RegisterServerPubKey(name string, pubKey *rsa.PublicKey)
- type BackendConnection
- func (conn *BackendConnection) Connect(ctx context.Context) error
- func (conn *BackendConnection) DataSourceName() string
- func (conn *BackendConnection) DrainResults() error
- func (conn *BackendConnection) Execute(query string, wantFields bool) (result *mysql.Result, err error)
- func (conn *BackendConnection) ExecuteMulti(query string, wantFields bool) (result *mysql.Result, more bool, err error)
- func (conn *BackendConnection) ExecuteWithWarningCount(query string, wantFields bool) (result *mysql.Result, warnings uint16, err error)
- func (conn *BackendConnection) Ping(ctx context.Context) (err error)
- func (conn *BackendConnection) PrepareExecute(query string, data []byte) (result *mysql.Result, warnings uint16, err error)
- func (conn *BackendConnection) PrepareExecuteArgs(query string, args []interface{}) (result *mysql.Result, warnings uint16, err error)
- func (conn *BackendConnection) PrepareQuery(query string, data []byte) (Result *mysql.Result, warnings uint16, err error)
- func (conn *BackendConnection) PrepareQueryArgs(query string, data []interface{}) (Result *mysql.Result, warnings uint16, err error)
- func (conn *BackendConnection) ReadColumnDefinition(field *mysql.Field, index int) error
- func (conn *BackendConnection) ReadColumnDefinitionType(field *mysql.Field, index int) error
- func (conn *BackendConnection) ReadColumnDefinitions() ([]*mysql.Field, error)
- func (conn *BackendConnection) ReadComQueryResponse() (affectedRows uint64, lastInsertID uint64, status int, more bool, ...)
- func (conn *BackendConnection) ReadQueryResult(wantFields bool) (result *mysql.Result, more bool, warnings uint16, err error)
- func (conn *BackendConnection) WriteComFieldList(table string, wildcard string) error
- func (conn *BackendConnection) WriteComInitDB(db string) error
- func (conn *BackendConnection) WriteComQuery(query string) error
- func (conn *BackendConnection) WriteComQuit() error
- func (conn *BackendConnection) WriteComSetOption(operation uint16) error
- func (conn *BackendConnection) WriteComStmtClose(statementID uint32) (err error)
- type BackendStatement
- type Config
- type Connector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeregisterServerPubKey ¶
func DeregisterServerPubKey(name string)
DeregisterServerPubKey removes the public key registered with the given name.
func RegisterServerPubKey ¶
RegisterServerPubKey registers a server RSA public key which can be used to send Content in a secure manner to the server without receiving the public key in a potentially insecure way from the server first. Registered keys can afterwards be used adding serverPubKey=<name> to the DSN.
Note: The provided rsa.PublicKey instance is exclusively owned by the driver after registering it and may not be modified.
Content, err := ioutil.ReadFile("mykey.pem") if err != nil { log.Fatal(err) } block, _ := pem.Decode(Content) if block == nil || block.Type != "PUBLIC KEY" { log.Fatal("failed to decode PEM block containing public key") } pub, err := x509.ParsePKIXPublicKey(block.Bytes) if err != nil { log.Fatal(err) } if rsaPubKey, ok := pub.(*rsa.PublicKey); ok { mysql.RegisterServerPubKey("mykey", rsaPubKey) } else { log.Fatal("not a RSA public key") }
Types ¶
type BackendConnection ¶
func (*BackendConnection) Connect ¶
func (conn *BackendConnection) Connect(ctx context.Context) error
func (*BackendConnection) DataSourceName ¶
func (conn *BackendConnection) DataSourceName() string
func (*BackendConnection) DrainResults ¶
func (conn *BackendConnection) DrainResults() error
DrainResults will read all packets for a result set and ignore them.
func (*BackendConnection) Execute ¶
func (conn *BackendConnection) Execute(query string, wantFields bool) (result *mysql.Result, err error)
Execute executes a query and returns the result. Returns a SQLError. Depending on the transport used, the error returned might be different for the same condition:
1. if the server closes the connection when no command is in flight:
1.1 unix: WriteComQuery will fail with a 'broken pipe', and we'll return CRServerGone(2006). 1.2 tcp: WriteComQuery will most likely work, but ReadComQueryResponse will fail, and we'll return CRServerLost(2013). This is because closing a TCP socket on the server side sends a FIN to the client (telling the client the server is done writing), but on most platforms doesn't send a RST. So the client has no idea it can't write. So it succeeds writing Content, which *then* triggers the server to send a RST back, received a bit later. By then, the client has already started waiting for the response, and will just return a CRServerLost(2013). So CRServerGone(2006) will almost never be seen with TCP.
- if the server closes the connection when a command is in flight, ReadComQueryResponse will fail, and we'll return CRServerLost(2013).
func (*BackendConnection) ExecuteMulti ¶
func (conn *BackendConnection) ExecuteMulti(query string, wantFields bool) (result *mysql.Result, more bool, err error)
ExecuteMulti is for fetching multiple results from a multi-statement result. It returns an additional 'more' flag. If it is set, you must fetch the additional results using ReadQueryResult.
func (*BackendConnection) ExecuteWithWarningCount ¶
func (conn *BackendConnection) ExecuteWithWarningCount(query string, wantFields bool) (result *mysql.Result, warnings uint16, err error)
ExecuteWithWarningCount is for fetching results and a warning count Note: In a future iteration this should be abolished and merged into the Execute API.
func (*BackendConnection) Ping ¶
func (conn *BackendConnection) Ping(ctx context.Context) (err error)
Ping implements driver.Pinger interface
func (*BackendConnection) PrepareExecute ¶
func (*BackendConnection) PrepareExecuteArgs ¶
func (*BackendConnection) PrepareQuery ¶
func (*BackendConnection) PrepareQueryArgs ¶
func (*BackendConnection) ReadColumnDefinition ¶
func (conn *BackendConnection) ReadColumnDefinition(field *mysql.Field, index int) error
ReadColumnDefinition reads the next Column Definition packet. Returns a SQLError.
func (*BackendConnection) ReadColumnDefinitionType ¶
func (conn *BackendConnection) ReadColumnDefinitionType(field *mysql.Field, index int) error
ReadColumnDefinitionType is a faster version of ReadColumnDefinition that only fills in the Type. Returns a SQLError.
func (*BackendConnection) ReadColumnDefinitions ¶
func (conn *BackendConnection) ReadColumnDefinitions() ([]*mysql.Field, error)
func (*BackendConnection) ReadComQueryResponse ¶
func (*BackendConnection) ReadQueryResult ¶
func (conn *BackendConnection) ReadQueryResult(wantFields bool) (result *mysql.Result, more bool, warnings uint16, err error)
ReadQueryResult gets the result from the last written query.
func (*BackendConnection) WriteComFieldList ¶
func (conn *BackendConnection) WriteComFieldList(table string, wildcard string) error
func (*BackendConnection) WriteComInitDB ¶
func (conn *BackendConnection) WriteComInitDB(db string) error
WriteComInitDB changes the default database to use. Client -> Server. Returns SQLError(CRServerGone) if it can't.
func (*BackendConnection) WriteComQuery ¶
func (conn *BackendConnection) WriteComQuery(query string) error
WriteComQuery writes a query for the server to execute. Client -> Server. Returns SQLError(CRServerGone) if it can't.
func (*BackendConnection) WriteComQuit ¶
func (conn *BackendConnection) WriteComQuit() error
WriteComQuit writes a Quit message for the server, to indicate we want to close the connection. Client -> Server. Returns SQLError(CRServerGone) if it can't.
func (*BackendConnection) WriteComSetOption ¶
func (conn *BackendConnection) WriteComSetOption(operation uint16) error
WriteComSetOption changes the connection's capability of executing multi statements. Returns SQLError(CRServerGone) if it can't.
func (*BackendConnection) WriteComStmtClose ¶
func (conn *BackendConnection) WriteComStmtClose(statementID uint32) (err error)
WriteComStmtClose close statement
type BackendStatement ¶
type BackendStatement struct {
// contains filtered or unexported fields
}
type Config ¶
type Config struct { User string // Username Passwd string // Password (requires User) Net string // Network type Addr string // Network address (requires Net) DBName string // Database name Params map[string]string // Connection parameters Collation string // Connection collation Loc *time.Location // Location for time.Time values MaxAllowedPacket int // Max packet size allowed ServerPubKey string // Server public key name TLSConfig string // TLS configuration name Timeout time.Duration // Dial timeout ReadTimeout time.Duration // I/O read timeout WriteTimeout time.Duration // I/O write timeout AllowAllFiles bool // Allow all files to be used with LOAD DATA LOCAL INFILE AllowCleartextPasswords bool // Allows the cleartext client side plugin AllowNativePasswords bool // Allows the native password authentication method AllowOldPasswords bool // Allows the old insecure password method CheckConnLiveness bool // Check connections for liveness before using them ClientFoundRows bool // Return number of matching rows instead of rows changed ColumnsWithAlias bool // Prepend table alias to column names InterpolateParams bool // Interpolate placeholders into query string MultiStatements bool // Allow multiple statements in one query ParseTime bool // Parse time values to time.Time RejectReadOnly bool // Reject read-only connections DisableClientDeprecateEOF bool // Disable client deprecate EOF // contains filtered or unexported fields }
func NewConfig ¶
func NewConfig() *Config
NewConfig creates a new ServerConfig and sets default values.