Skip to content

Conversation

@dveeden
Copy link
Collaborator

@dveeden dveeden commented Dec 9, 2025

Response to: #1074 (comment)

Example code

package main

import (
	"fmt"

	"github.com/go-mysql-org/go-mysql/client"
	"github.com/go-mysql-org/go-mysql/mysql"
)

func main() {
	conn, err := client.Connect("127.0.0.1:3306", "root", "", "", func(conn *client.Conn) error {
		return conn.SetCapability(mysql.CLIENT_SESSION_TRACK)
	})
	if err != nil {
		panic(err)
	}
	defer conn.Quit()

	res, _ := conn.Execute("SELECT VERSION() AS ver")
	version, _ := res.GetStringByName(0, "ver")
	res.Close()
	fmt.Println(version)
}

Output:

panic: unsupported or unknown capability

goroutine 1 [running]:
main.main()
	/home/dvaneeden/dev/go-mysql-client/main.go:15 +0x1af
exit status 2

Note that we could:

  • extract the capability-to-name stuff from CapabilityString() (This is in the other PR, mysql,client: add log for caps we can't set #1074 )
  • add the capability name to the error message
  • Use slog for structured logging
  • Have UnsetCapability() also return an error. But without any real checking for now. Just to keep the signature similar
  • Have SetCapability(mysql.CLIENT_PROTOCOL_41) and other base capabilities (opposed to optional capabilities) be accepted without error. Or have an error like "can not set capability that is already set".
  • Have SetCapability() return errors when setting optional capabilities that are already set.

@dveeden dveeden requested a review from lance6716 December 9, 2025 12:10
@lance6716
Copy link
Collaborator

Note that we could:
...

lgtm for current code

@lance6716 lance6716 merged commit 75277c8 into go-mysql-org:master Dec 11, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants