mysql

package
v2.0.0-beta.1+incompat... Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2016 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package mysql wraps the C client library for MySQL.

Index

Constants

View Source
const (

	// TypeTiny specifies a TINYINT type.
	// Value is 1.
	TypeTiny = C.MYSQL_TYPE_TINY
	// TypeShort specifies a SMALLINT type.
	// Value is 2.
	TypeShort = C.MYSQL_TYPE_SHORT
	// TypeLong specifies a INTEGER type.
	// Value is 3.
	TypeLong = C.MYSQL_TYPE_LONG
	// TypeFloat specifies a FLOAT type.
	// Value is 4.
	TypeFloat = C.MYSQL_TYPE_FLOAT
	// TypeDouble specifies a DOUBLE or REAL type.
	// Value is 5.
	TypeDouble = C.MYSQL_TYPE_DOUBLE
	// TypeNull specifies a NULL type.
	// Value is 6.
	TypeNull = C.MYSQL_TYPE_NULL
	// TypeTimestamp specifies a TIMESTAMP type.
	// Value is 7. NOT SUPPORTED.
	TypeTimestamp = C.MYSQL_TYPE_TIMESTAMP
	// TypeLonglong specifies a BIGINT type.
	// Value is 8.
	TypeLonglong = C.MYSQL_TYPE_LONGLONG
	// TypeInt24 specifies a MEDIUMINT type.
	// Value is 9.
	TypeInt24 = C.MYSQL_TYPE_INT24
	// TypeDate specifies a DATE type.
	// Value is 10.
	TypeDate = C.MYSQL_TYPE_DATE
	// TypeTime specifies a TIME type.
	// Value is 11.
	TypeTime = C.MYSQL_TYPE_TIME
	// TypeDatetime specifies a DATETIME type.
	// Value is 12.
	TypeDatetime = C.MYSQL_TYPE_DATETIME
	// TypeYear specifies a YEAR type.
	// Value is 13.
	TypeYear = C.MYSQL_TYPE_YEAR
	// TypeBit specifies a BIT type.
	// Value is 16.
	TypeBit = C.MYSQL_TYPE_BIT
	// TypeNewDecimal specifies a DECIMAL or NUMERIC type.
	// Value is 246.
	TypeNewDecimal = C.MYSQL_TYPE_NEWDECIMAL
	// TypeBlob specifies a BLOB or TEXT type.
	// Value is 252.
	TypeBlob = C.MYSQL_TYPE_BLOB
	// TypeVarString specifies a VARCHAR or VARBINARY type.
	// Value is 253.
	TypeVarString = C.MYSQL_TYPE_VAR_STRING
	// TypeString specifies a CHAR or BINARY type.
	// Value is 254.
	TypeString = C.MYSQL_TYPE_STRING
	// TypeGeometry specifies a Spatial field.
	// Value is 255. NOT SUPPORTED.
	TypeGeometry = C.MYSQL_TYPE_GEOMETRY
)
View Source
const (
	// FlagUnsigned specifies if the value is an unsigned.
	// Value is 32 (0x20).
	FlagUnsigned = C.UNSIGNED_FLAG
	// FlagBinary specifies if the data is binary.
	// Value is 128 (0x80).
	FlagBinary = C.BINARY_FLAG
	// FlagEnum specifies if the value is an enum.
	// Value is 256 (0x100).
	FlagEnum = C.ENUM_FLAG
	// FlagSet specifies if the value is a set.
	// Value is 2048 (0x800).
	FlagSet = C.SET_FLAG

	// RelevantFlags is used to mask out irrelevant flags.
	RelevantFlags = FlagUnsigned |
		FlagBinary |
		FlagEnum |
		FlagSet
)
View Source
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

	// ErrDataTooLong is C.ER_DATA_TOO_LONG
	ErrDataTooLong = C.ER_DATA_TOO_LONG

	// ErrBadNullError is C.ER_BAD_NULL_ERROR
	ErrBadNullError = C.ER_BAD_NULL_ERROR

	// ErrDataOutOfRange is C.ER_WARN_DATA_OUT_OF_RANGE
	ErrDataOutOfRange = C.ER_WARN_DATA_OUT_OF_RANGE

	// ErrServerLost is C.CR_SERVER_LOST.
	// It's hard-coded for now because it causes problems on import.
	ErrServerLost = 2013

	// RedactedPassword is the password value used in redacted configs
	RedactedPassword = "****"
)

Variables

This section is empty.

Functions

func Connect

func Connect(params sqldb.ConnParams) (sqldb.Conn, error)

Connect uses the connection parameters to connect and returns the connection

func EnableSSL

func EnableSSL(connParams *sqldb.ConnParams)

EnableSSL will set the right flag on the parameters

func SslEnabled

func SslEnabled(connParams *sqldb.ConnParams) bool

SslEnabled returns if SSL is enabled

Types

type Connection

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

Connection encapsulates a C mysql library connection

func (*Connection) Close

func (conn *Connection) Close()

Close closes the mysql 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 *sqltypes.Result, 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 []*querypb.Field)

Fields returns the current fields description for the query

func (*Connection) GetCharset

func (conn *Connection) GetCharset() (*binlogdatapb.Charset, 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 *binlogdatapb.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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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