driver

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2022 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

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

func RegisterServerPubKey(name string, pubKey *rsa.PublicKey)

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

type BackendConnection struct {
	*mysql.Conn
	// contains filtered or unexported fields
}

func (*BackendConnection) Connect

func (conn *BackendConnection) Connect(ctx context.Context) error

func (*BackendConnection) DataSourceName

func (conn *BackendConnection) DataSourceName() string

func (*BackendConnection) Execute

func (conn *BackendConnection) Execute(ctx context.Context, 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.

 2. 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(ctx context.Context, 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(ctx context.Context, 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 (conn *BackendConnection) PrepareExecute(ctx context.Context, query string, data []byte) (result *mysql.Result, warnings uint16, err error)

func (*BackendConnection) PrepareExecuteArgs

func (conn *BackendConnection) PrepareExecuteArgs(ctx context.Context, query string, args []interface{}) (result *mysql.Result, warnings uint16, err error)

func (*BackendConnection) PrepareQuery

func (conn *BackendConnection) PrepareQuery(ctx context.Context, query string, data []byte) (Result *mysql.Result, warnings uint16, err error)

func (*BackendConnection) PrepareQueryArgs

func (conn *BackendConnection) PrepareQueryArgs(ctx context.Context, query string, args []interface{}) (Result *mysql.Result, warnings uint16, err error)

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 (conn *BackendConnection) ReadComQueryResponse() (affectedRows uint64, lastInsertID uint64, status int, more bool, warnings uint16, err error)

func (*BackendConnection) ReadQueryResult

func (conn *BackendConnection) ReadQueryResult(ctx context.Context, 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.

func ParseDSN

func ParseDSN(dsn string) (cfg *Config, err error)

ParseDSN parses the DSN string to a Config

func (*Config) Clone

func (cfg *Config) Clone() *Config

type Connector

type Connector struct {
	// contains filtered or unexported fields
}

func NewConnector

func NewConnector(dataSourceName, dsn string) (*Connector, error)

func (*Connector) NewBackendConnection

func (c *Connector) NewBackendConnection(ctx context.Context) (pools.Resource, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL