Skip to content

Commit

Permalink
Added parameters for compression (go-sql-driver#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
eqinox76 committed Nov 21, 2020
1 parent cf72fd2 commit b0aee65
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type mysqlConn struct {
sequence uint8
parseTime bool
reset bool // set when the Go SQL package calls ResetSession
compressed bool

// for context support (Go 1.8+)
watching bool
Expand Down
5 changes: 5 additions & 0 deletions connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ func (c *connector) Connect(ctx context.Context) (driver.Conn, error) {
return nil, err
}

// #24 compression requested by client and supported by server
if mc.flags&clientCompress > 0 && mc.cfg.Compress {
mc.compressed = true
}

return mc, nil
}

Expand Down
7 changes: 6 additions & 1 deletion dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type Config struct {
CheckConnLiveness bool // Check connections for liveness before using them
ClientFoundRows bool // Return number of matching rows instead of rows changed
ColumnsWithAlias bool // Prepend table alias to column names
Compress bool // #24 use compression protocol
InterpolateParams bool // Interpolate placeholders into query string
MultiStatements bool // Allow multiple statements in one query
ParseTime bool // Parse time values to time.Time
Expand Down Expand Up @@ -437,7 +438,11 @@ func parseDSNParams(cfg *Config, params string) (err error) {

// Compression
case "compress":
return errors.New("compression not implemented yet")
var isBool bool
cfg.Compress, isBool = readBool(value)
if !isBool {
return errors.New("invalid bool value: " + value)
}

// Enable client side placeholder substitution
case "interpolateParams":
Expand Down
5 changes: 5 additions & 0 deletions packets.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ func (mc *mysqlConn) writeHandshakeResponsePacket(authResp []byte, plugin string
clientFlags |= clientMultiStatements
}

// To enable compression
if mc.cfg.Compress {
clientFlags |= clientCompress
}

// encode length of the auth plugin data
var authRespLEIBuf [9]byte
authRespLen := len(authResp)
Expand Down

0 comments on commit b0aee65

Please sign in to comment.