mymysql: github.com/ziutek/mymysql/native Index | Files

package native

import "github.com/ziutek/mymysql/native"

Package native is a thread unsafe engine for MyMySQL.

Index

Package Files

addons.go binding.go codecs.go command.go common.go consts.go init.go mysql.go packet.go paramvalue.go passwd.go prepared.go result.go

Constants

const (
    MYSQL_TYPE_DECIMAL     = 0x00
    MYSQL_TYPE_TINY        = 0x01 // int8, uint8, bool
    MYSQL_TYPE_SHORT       = 0x02 // int16, uint16
    MYSQL_TYPE_LONG        = 0x03 // int32, uint32
    MYSQL_TYPE_FLOAT       = 0x04 // float32
    MYSQL_TYPE_DOUBLE      = 0x05 // float64
    MYSQL_TYPE_NULL        = 0x06 // nil
    MYSQL_TYPE_TIMESTAMP   = 0x07 // Timestamp
    MYSQL_TYPE_LONGLONG    = 0x08 // int64, uint64
    MYSQL_TYPE_INT24       = 0x09
    MYSQL_TYPE_DATE        = 0x0a // Date
    MYSQL_TYPE_TIME        = 0x0b // Time
    MYSQL_TYPE_DATETIME    = 0x0c // time.Time
    MYSQL_TYPE_YEAR        = 0x0d
    MYSQL_TYPE_NEWDATE     = 0x0e
    MYSQL_TYPE_VARCHAR     = 0x0f
    MYSQL_TYPE_BIT         = 0x10
    MYSQL_TYPE_NEWDECIMAL  = 0xf6
    MYSQL_TYPE_ENUM        = 0xf7
    MYSQL_TYPE_SET         = 0xf8
    MYSQL_TYPE_TINY_BLOB   = 0xf9
    MYSQL_TYPE_MEDIUM_BLOB = 0xfa
    MYSQL_TYPE_LONG_BLOB   = 0xfb
    MYSQL_TYPE_BLOB        = 0xfc // Blob
    MYSQL_TYPE_VAR_STRING  = 0xfd // []byte
    MYSQL_TYPE_STRING      = 0xfe // string
    MYSQL_TYPE_GEOMETRY    = 0xff

    MYSQL_UNSIGNED_MASK = uint16(1 << 15)
)

MySQL protocol types.

mymysql uses only some of them for send data to the MySQL server. Used MySQL types are marked with a comment contains mymysql type that uses it.

const (
    // Client send and receive, mymysql representation for send / receive
    TINYINT   = MYSQL_TYPE_TINY      // int8 / int8
    SMALLINT  = MYSQL_TYPE_SHORT     // int16 / int16
    INT       = MYSQL_TYPE_LONG      // int32 / int32
    BIGINT    = MYSQL_TYPE_LONGLONG  // int64 / int64
    FLOAT     = MYSQL_TYPE_FLOAT     // float32 / float32
    DOUBLE    = MYSQL_TYPE_DOUBLE    // float64 / float32
    TIME      = MYSQL_TYPE_TIME      // Time / Time
    DATE      = MYSQL_TYPE_DATE      // Date / Date
    DATETIME  = MYSQL_TYPE_DATETIME  // time.Time / time.Time
    TIMESTAMP = MYSQL_TYPE_TIMESTAMP // Timestamp / time.Time
    CHAR      = MYSQL_TYPE_STRING    // string / []byte
    BLOB      = MYSQL_TYPE_BLOB      // Blob / []byte
    NULL      = MYSQL_TYPE_NULL      // nil

    // Client send only, mymysql representation for send
    OUT_TEXT      = MYSQL_TYPE_STRING // string
    OUT_VARCHAR   = MYSQL_TYPE_STRING // string
    OUT_BINARY    = MYSQL_TYPE_BLOB   // Blob
    OUT_VARBINARY = MYSQL_TYPE_BLOB   // Blob

    // Client receive only, mymysql representation for receive
    IN_MEDIUMINT  = MYSQL_TYPE_LONG        // int32
    IN_YEAR       = MYSQL_TYPE_SHORT       // int16
    IN_BINARY     = MYSQL_TYPE_STRING      // []byte
    IN_VARCHAR    = MYSQL_TYPE_VAR_STRING  // []byte
    IN_VARBINARY  = MYSQL_TYPE_VAR_STRING  // []byte
    IN_TINYBLOB   = MYSQL_TYPE_TINY_BLOB   // []byte
    IN_TINYTEXT   = MYSQL_TYPE_TINY_BLOB   // []byte
    IN_TEXT       = MYSQL_TYPE_BLOB        // []byte
    IN_MEDIUMBLOB = MYSQL_TYPE_MEDIUM_BLOB // []byte
    IN_MEDIUMTEXT = MYSQL_TYPE_MEDIUM_BLOB // []byte
    IN_LONGBLOB   = MYSQL_TYPE_LONG_BLOB   // []byte
    IN_LONGTEXT   = MYSQL_TYPE_LONG_BLOB   // []byte

    // MySQL 5.x specific
    IN_DECIMAL = MYSQL_TYPE_NEWDECIMAL // TODO
    IN_BIT     = MYSQL_TYPE_BIT        // []byte
)

Mapping of MySQL types to (prefered) protocol types. Use it if you create your own Raw value.

Comments contains corresponding types used by mymysql. string type may be replaced by []byte type and vice versa. []byte type is native for sending on a network, so any string is converted to it before sending. Than for better performance use []byte.

Variables

var DefaultDialer mysql.Dialer = func(proto, laddr, raddr string,
    timeout time.Duration) (net.Conn, error) {

    if proto == "" {
        proto = "unix"
        if strings.IndexRune(raddr, ':') != -1 {
            proto = "tcp"
        }
    }

    d := &net.Dialer{Timeout: timeout}
    if laddr != "" {
        var err error
        switch proto {
        case "tcp", "tcp4", "tcp6":
            d.LocalAddr, err = net.ResolveTCPAddr(proto, laddr)
        case "unix":
            d.LocalAddr, err = net.ResolveTCPAddr(proto, laddr)
        default:
            err = net.UnknownNetworkError(proto)
        }
        if err != nil {
            return nil, err
        }
    }
    return d.Dial(proto, raddr)
}

func DecodeU16 Uses

func DecodeU16(buf []byte) uint16

func DecodeU24 Uses

func DecodeU24(buf []byte) uint32

func DecodeU32 Uses

func DecodeU32(buf []byte) uint32

func DecodeU64 Uses

func DecodeU64(buf []byte) (rv uint64)

func EncodeDate Uses

func EncodeDate(buf []byte, d mysql.Date) int

func EncodeDuration Uses

func EncodeDuration(buf []byte, d time.Duration) int

func EncodeTime Uses

func EncodeTime(buf []byte, t time.Time) int

func EncodeU16 Uses

func EncodeU16(buf []byte, val uint16)

func EncodeU24 Uses

func EncodeU24(buf []byte, val uint32)

func EncodeU32 Uses

func EncodeU32(buf []byte, val uint32)

func EncodeU64 Uses

func EncodeU64(buf []byte, val uint64)

func NbinToNstr Uses

func NbinToNstr(nbin *[]byte) *string

func New Uses

func New(proto, laddr, raddr, user, passwd string, args ...string) mysql.Conn

New: Create new MySQL handler. The first three arguments are passed to net.Bind for create connection. user and passwd are for authentication. Optional db is database name (you may not specify it and use Use() method later).

func NstrToNbin Uses

func NstrToNbin(nstr *string) *[]byte

type Conn Uses

type Conn struct {

    // Debug logging. You may change it at any time.
    Debug bool
    // contains filtered or unexported fields
}

MySQL connection handler

func (*Conn) Begin Uses

func (my *Conn) Begin() (mysql.Transaction, error)

Begin starts a new transaction

func (*Conn) Clone Uses

func (my *Conn) Clone() mysql.Conn

Clone: Creates new (not connected) connection using configuration from current connection.

func (*Conn) Close Uses

func (my *Conn) Close() (err error)

Close connection to the server

func (*Conn) Connect Uses

func (my *Conn) Connect() (err error)

Connect: Establishes a connection with MySQL server version 4.1 or later.

func (*Conn) Credentials Uses

func (my *Conn) Credentials() (user, passwd string)

func (*Conn) Escape Uses

func (my *Conn) Escape(txt string) string

Escape: Escapes special characters in the txt, so it is safe to place returned string to Query method.

func (*Conn) FullFieldInfo Uses

func (my *Conn) FullFieldInfo(full bool)

func (*Conn) IsConnected Uses

func (my *Conn) IsConnected() bool

IsConnected checks if connection is established

func (*Conn) NarrowTypeSet Uses

func (my *Conn) NarrowTypeSet(narrow bool)

func (*Conn) NetConn Uses

func (my *Conn) NetConn() net.Conn

NetConn return internall net.Conn

func (*Conn) Ping Uses

func (my *Conn) Ping() (err error)

Ping: Send MySQL PING to the server.

func (*Conn) Prepare Uses

func (my *Conn) Prepare(sql string) (mysql.Stmt, error)

Prepare server side statement. Return statement handler.

func (*Conn) Query Uses

func (my *Conn) Query(sql string, params ...interface{}) ([]mysql.Row, mysql.Result, error)

Query: See mysql.Query

func (*Conn) QueryFirst Uses

func (my *Conn) QueryFirst(sql string, params ...interface{}) (mysql.Row, mysql.Result, error)

QueryFirst: See mysql.QueryFirst

func (*Conn) QueryLast Uses

func (my *Conn) QueryLast(sql string, params ...interface{}) (mysql.Row, mysql.Result, error)

QueryLast: See mysql.QueryLast

func (*Conn) Reconnect Uses

func (my *Conn) Reconnect() (err error)

Reconnect: Close and reopen connection. Ignore unreaded rows, reprepare all prepared statements.

func (*Conn) Register Uses

func (my *Conn) Register(sql string)

Register MySQL command/query to be executed immediately after connecting to the server. You may register multiple commands. They will be executed in the order of registration. Yhis method is mainly useful for reconnect.

func (*Conn) SetDialer Uses

func (my *Conn) SetDialer(d mysql.Dialer)

func (*Conn) SetMaxPktSize Uses

func (my *Conn) SetMaxPktSize(new_size int) int

SetMaxPktSize: If new_size > 0 sets maximum packet size. Returns old size.

func (*Conn) SetTimeout Uses

func (my *Conn) SetTimeout(timeout time.Duration)

SetTimeout sets timeout for Connect and Reconnect

func (*Conn) Start Uses

func (my *Conn) Start(sql string, params ...interface{}) (res mysql.Result, err error)

Start new query.

If you specify the parameters, the SQL string will be a result of fmt.Sprintf(sql, params...). You must get all result rows (if they exists) before next query.

func (*Conn) Status Uses

func (my *Conn) Status() mysql.ConnStatus

func (*Conn) ThreadId Uses

func (my *Conn) ThreadId() uint32

ThreadId returns the thread ID of the current connection.

func (*Conn) Use Uses

func (my *Conn) Use(dbname string) (err error)

Use: Change database

type Result Uses

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

func (*Result) AffectedRows Uses

func (res *Result) AffectedRows() uint64

func (*Result) End Uses

func (res *Result) End() error

End: See mysql.End

func (*Result) Fields Uses

func (res *Result) Fields() []*mysql.Field

Fields returns a table containing descriptions of the columns

func (*Result) GetFirstRow Uses

func (res *Result) GetFirstRow() (mysql.Row, error)

GetFirstRow: See mysql.GetFirstRow

func (*Result) GetLastRow Uses

func (res *Result) GetLastRow() (mysql.Row, error)

GetLastRow: See mysql.GetLastRow

func (*Result) GetRow Uses

func (res *Result) GetRow() (mysql.Row, error)

GetRow: Like ScanRow but allocates memory for every row. Returns nil row insted of io.EOF error.

func (*Result) GetRows Uses

func (res *Result) GetRows() ([]mysql.Row, error)

GetRows: See mysql.GetRows

func (*Result) InsertId Uses

func (res *Result) InsertId() uint64

func (*Result) MakeRow Uses

func (res *Result) MakeRow() mysql.Row

func (*Result) Map Uses

func (res *Result) Map(field_name string) int

Map returns index for given name or -1 if field of that name doesn't exist

func (*Result) Message Uses

func (res *Result) Message() string

func (*Result) MoreResults Uses

func (res *Result) MoreResults() bool

MoreResults returns true if more results exixts. You don't have to call it before NextResult method (NextResult returns nil if there is no more results).

func (*Result) NextResult Uses

func (res *Result) NextResult() (mysql.Result, error)

NextResult is used when last query was the multi result query or procedure call. Returns the next result or nil if no more resuts exists.

Statements within the procedure may produce unknown number of result sets. The final result from the procedure is a status result that includes no result set (Result.StatusOnly() == true) .

func (*Result) ScanRow Uses

func (res *Result) ScanRow(row mysql.Row) error

ScanRow gets the data row from server. This method reads one row of result set directly from network connection (without rows buffering on client side). Returns io.EOF if there is no more rows in current result set.

func (*Result) StatusOnly Uses

func (res *Result) StatusOnly() bool

StatusOnly returns true if this is status result that includes no result set

func (*Result) WarnCount Uses

func (res *Result) WarnCount() int

type Stmt Uses

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

func (*Stmt) Bind Uses

func (stmt *Stmt) Bind(params ...interface{})

Bind input data for the parameter markers in the SQL statement that was passed to Prepare.

params may be a parameter list (slice), a struct or a pointer to the struct. A struct field can by value or pointer to value. A parameter (slice element) can be value, pointer to value or pointer to pointer to value. Values may be of the folowind types: intXX, uintXX, floatXX, bool, []byte, Blob, string, Time, Date, Time, Timestamp, Raw.

func (*Stmt) Delete Uses

func (stmt *Stmt) Delete() (err error)

Delete: Destroy statement on server side. Client side handler is invalid after this command.

func (*Stmt) Exec Uses

func (stmt *Stmt) Exec(params ...interface{}) ([]mysql.Row, mysql.Result, error)

Exec: See mysql.Exec

func (*Stmt) ExecFirst Uses

func (stmt *Stmt) ExecFirst(params ...interface{}) (mysql.Row, mysql.Result, error)

ExecFirst: See mysql.ExecFirst

func (*Stmt) ExecLast Uses

func (stmt *Stmt) ExecLast(params ...interface{}) (mysql.Row, mysql.Result, error)

ExecLast: See mysql.ExecLast

func (*Stmt) Fields Uses

func (stmt *Stmt) Fields() []*mysql.Field

func (*Stmt) NumParam Uses

func (stmt *Stmt) NumParam() int

func (*Stmt) Reset Uses

func (stmt *Stmt) Reset() (err error)

Reset: Resets a prepared statement on server: data sent to the server, unbuffered result sets and current errors.

func (*Stmt) Run Uses

func (stmt *Stmt) Run(params ...interface{}) (res mysql.Result, err error)

Run executes prepared statement. If statement requires parameters you may bind them first or specify directly. After this command you may use GetRow to retrieve data.

func (*Stmt) SendLongData Uses

func (stmt *Stmt) SendLongData(pnum int, data interface{}, pkt_size int) (err error)

SendLongData: Send long data to MySQL server in chunks. You can call this method after Bind and before Exec. It can be called multiple times for one parameter to send TEXT or BLOB data in chunks.

pnum - Parameter number to associate the data with.

data - Data source string, []byte or io.Reader.

pkt_size - It must be must be greater than 6 and less or equal to MySQL max_allowed_packet variable. You can obtain value of this variable using such query: SHOW variables WHERE Variable_name = 'max_allowed_packet' If data source is io.Reader then (pkt_size - 6) is size of a buffer that will be allocated for reading.

If you have data source of type string or []byte in one piece you may properly set pkt_size and call this method once. If you have data in multiple pieces you can call this method multiple times. If data source is io.Reader you should properly set pkt_size. Data will be readed from io.Reader and send in pieces to the server until EOF.

func (*Stmt) WarnCount Uses

func (stmt *Stmt) WarnCount() int

type Transaction Uses

type Transaction struct {
    *Conn
}

func (Transaction) Commit Uses

func (tr Transaction) Commit() error

Commit a transaction

func (Transaction) Do Uses

func (tr Transaction) Do(st mysql.Stmt) mysql.Stmt

Do: Binds statement to the context of transaction. For native engine this is identity function.

func (Transaction) IsValid Uses

func (tr Transaction) IsValid() bool

func (Transaction) Rollback Uses

func (tr Transaction) Rollback() error

Rollback a transaction

Package native imports 21 packages (graph) and is imported by 88 packages. Updated 2019-02-20. Refresh now. Tools for package owners.