Version: v2.1.1+incompatible Latest Latest

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

Go to latest
Published: May 22, 2017 License: BSD-3-Clause Imports: 8 Imported by: 0



Package sqldb defines an interface for low level db connection.

Package sqldb defines an interface for low level db connection



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


This section is empty.


func ExecuteFetchMap

func ExecuteFetchMap(conn Conn, 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 GetCharset

func GetCharset(conn Conn) (*binlogdatapb.Charset, error)

GetCharset returns the current numerical values of the per-session character set variables.

func NewSQLErrorFromError

func NewSQLErrorFromError(err error) error

NewSQLErrorFromError returns a *SQLError from the provided error. If it's not the right type, it still tries to get it from a regexp.

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.

func SetCharset

func SetCharset(conn Conn, cs *binlogdatapb.Charset) error

SetCharset changes the per-session character set variables.


type Conn

type Conn interface {
	// ExecuteFetch executes the query on the connection
	ExecuteFetch(query string, maxrows int, wantfields bool) (*sqltypes.Result, 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
	// IsClosed returns if the connection was ever closed
	IsClosed() bool
	// CloseResult finishes the result set
	// 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)

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

func (*ConnParams) EnableSSL

func (cp *ConnParams) EnableSSL()

EnableSSL will set the right flag on the parameters.

func (*ConnParams) SslEnabled

func (cp *ConnParams) SslEnabled() bool

SslEnabled returns if SSL is enabled.

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