Skip to content

Commit da20b43

Browse files
authored
Merge branch 'master' into gtid_tagged_log_event_serialized
2 parents 1558b91 + 5942cc6 commit da20b43

File tree

10 files changed

+266
-43
lines changed

10 files changed

+266
-43
lines changed

client/auth.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
const defaultAuthPluginName = mysql.AUTH_NATIVE_PASSWORD
1616

1717
// defines the supported auth plugins
18-
var supportedAuthPlugins = []string{mysql.AUTH_NATIVE_PASSWORD, mysql.AUTH_SHA256_PASSWORD, mysql.AUTH_CACHING_SHA2_PASSWORD}
18+
var supportedAuthPlugins = []string{mysql.AUTH_NATIVE_PASSWORD, mysql.AUTH_SHA256_PASSWORD, mysql.AUTH_CACHING_SHA2_PASSWORD, mysql.AUTH_MARIADB_ED25519}
1919

2020
// helper function to determine what auth methods are allowed by this client
2121
func authPluginAllowed(pluginName string) bool {
@@ -172,6 +172,15 @@ func (c *Conn) genAuthResponse(authData []byte) ([]byte, bool, error) {
172172
// see: https://dev.mysql.com/doc/internals/en/public-key-retrieval.html
173173
return []byte{1}, false, nil
174174
}
175+
case mysql.AUTH_MARIADB_ED25519:
176+
if len(authData) != 32 {
177+
return nil, false, mysql.ErrMalformPacket
178+
}
179+
res, err := mysql.CalcEd25519Password(authData, c.password)
180+
if err != nil {
181+
return nil, false, err
182+
}
183+
return res, false, nil
175184
default:
176185
// not reachable
177186
return nil, false, fmt.Errorf("auth plugin '%s' is not supported", c.authPluginName)
@@ -195,7 +204,7 @@ func (c *Conn) genAttributes() []byte {
195204
// See: http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::HandshakeResponse
196205
func (c *Conn) writeAuthHandshake() error {
197206
if !authPluginAllowed(c.authPluginName) {
198-
return fmt.Errorf("unknow auth plugin name '%s'", c.authPluginName)
207+
return fmt.Errorf("unknown auth plugin name '%s'", c.authPluginName)
199208
}
200209

201210
// Set default client capabilities that reflect the abilities of this library

client/conn.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"crypto/tls"
77
"fmt"
8+
"math/bits"
89
"net"
910
"runtime"
1011
"runtime/debug"
@@ -381,6 +382,21 @@ func (c *Conn) Begin() error {
381382
return errors.Trace(err)
382383
}
383384

385+
func (c *Conn) BeginTx(readOnly bool, txIsolation string) error {
386+
if txIsolation != "" {
387+
if _, err := c.exec("SET TRANSACTION ISOLATION LEVEL " + txIsolation); err != nil {
388+
return errors.Trace(err)
389+
}
390+
}
391+
var err error
392+
if readOnly {
393+
_, err = c.exec("START TRANSACTION READ ONLY")
394+
} else {
395+
_, err = c.exec("START TRANSACTION")
396+
}
397+
return errors.Trace(err)
398+
}
399+
384400
func (c *Conn) Commit() error {
385401
_, err := c.exec("COMMIT")
386402
return errors.Trace(err)
@@ -557,13 +573,10 @@ func (c *Conn) execSend(query string) error {
557573
// separated by "|". Examples of capability names are CLIENT_DEPRECATE_EOF and CLIENT_PROTOCOL_41.
558574
// These are defined as constants in the mysql package.
559575
func (c *Conn) CapabilityString() string {
560-
var caps []string
561576
capability := c.capability
562-
for i := 0; capability != 0; i++ {
563-
field := uint32(1 << i)
564-
if capability&field == 0 {
565-
continue
566-
}
577+
caps := make([]string, 0, bits.OnesCount32(capability))
578+
for capability != 0 {
579+
field := uint32(1 << bits.TrailingZeros32(capability))
567580
capability ^= field
568581

569582
switch field {
@@ -642,13 +655,10 @@ func (c *Conn) CapabilityString() string {
642655
// StatusString returns a "|" separated list of status fields. Example status values are SERVER_QUERY_WAS_SLOW and SERVER_STATUS_AUTOCOMMIT.
643656
// These are defined as constants in the mysql package.
644657
func (c *Conn) StatusString() string {
645-
var stats []string
646658
status := c.status
647-
for i := 0; status != 0; i++ {
648-
field := uint16(1 << i)
649-
if status&field == 0 {
650-
continue
651-
}
659+
stats := make([]string, 0, bits.OnesCount16(status))
660+
for status != 0 {
661+
field := uint16(1 << bits.TrailingZeros16(status))
652662
status ^= field
653663

654664
switch field {

0 commit comments

Comments
 (0)