sqldb

package
v2.0.0-rc.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2016 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package sqldb defines an interface for low level db connection.

Package sqldb defines an interface for low level db connection

Index

Constants

View Source
const (
	// SQLStateGeneral is the SQLSTATE value for "general error".
	SQLStateGeneral = "HY000"
)

Variables

This section is empty.

Functions

func Register

func Register(name string, fn NewConnFunc)

Register registers a db connection.

func RegisterDefault

func RegisterDefault(fn NewConnFunc)

RegisterDefault registers the default connection function. Only one default can be registered.

Types

type Conn

type Conn interface {
	// ExecuteFetch executes the query on the connection
	ExecuteFetch(query string, maxrows int, wantfields bool) (*sqltypes.Result, error)
	// ExecuteFetchMap returns a map from column names to cell data for a query
	// that should return exactly 1 row.
	ExecuteFetchMap(query string) (map[string]string, error)
	// ExecuteStreamFetch starts a streaming query to db server. Use FetchNext
	// on the Connection until it returns nil or error
	ExecuteStreamFetch(query string) error
	// Close closes the db connection
	Close()
	// IsClosed returns if the connection was ever closed
	IsClosed() bool
	// CloseResult finishes the result set
	CloseResult()
	// Shutdown invokes the low-level shutdown call on the socket associated with
	// a connection to stop ongoing communication.
	Shutdown()
	// Fields returns the current fields description for the query
	Fields() ([]*querypb.Field, error)
	// ID returns the connection id.
	ID() int64
	// FetchNext returns the next row for a query
	FetchNext() ([]sqltypes.Value, error)
	// ReadPacket reads a raw packet from the connection.
	ReadPacket() ([]byte, error)
	// SendCommand sends a raw command to the db server.
	SendCommand(command uint32, data []byte) error
	// GetCharset returns the current numerical values of the per-session character
	// set variables.
	GetCharset() (cs *binlogdatapb.Charset, err error)
	// SetCharset changes the per-session character set variables.
	SetCharset(cs *binlogdatapb.Charset) error
}

Conn defines the behavior for the low level db connection

func Connect

func Connect(params ConnParams) (Conn, error)

Connect returns a sqldb.Conn using the default connection creation function.

type ConnParams

type ConnParams struct {
	Engine     string `json:"engine"`
	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"`
}

ConnParams contains all the parameters to use to connect to mysql

type NewConnFunc

type NewConnFunc func(params ConnParams) (Conn, error)

NewConnFunc is a factory method that creates a Conn instance using given ConnParams.

type SQLError

type SQLError struct {
	Num     int
	State   string
	Message string
	Query   string
}

SQLError is the error structure returned from calling a db library function

func NewSQLError

func NewSQLError(number int, sqlState string, format string, args ...interface{}) *SQLError

NewSQLError creates a new SQLError. If sqlState is left empty, it will default to "HY000" (general error).

func (*SQLError) Error

func (se *SQLError) Error() string

Error implements the error interface

func (*SQLError) Number

func (se *SQLError) Number() int

Number returns the internal MySQL error code.

func (*SQLError) SQLState

func (se *SQLError) SQLState() string

SQLState returns the SQLSTATE value.

Jump to

Keyboard shortcuts

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