Skip to content

Commit 7dc8271

Browse files
dveedenlance6716
andauthored
mysql,client,driver: Add more docs/comments and update constants (#974)
* mysql,client: Add more docs/comments and update constants * Add comment to UseSslOption --------- Co-authored-by: lance6716 <[email protected]>
1 parent e270065 commit 7dc8271

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

client/conn.go

+9
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,12 @@ func (c *Conn) handshake() error {
194194
return nil
195195
}
196196

197+
// Close directly closes the connection. Use Quit() to first send COM_QUIT to the server and then close the connection.
197198
func (c *Conn) Close() error {
198199
return c.Conn.Close()
199200
}
200201

202+
// Quit sends COM_QUIT to the server and then closes the connection. Use Close() to directly close the connection.
201203
func (c *Conn) Quit() error {
202204
if err := c.writeCommand(COM_QUIT); err != nil {
203205
return err
@@ -375,6 +377,7 @@ func (c *Conn) Rollback() error {
375377
return errors.Trace(err)
376378
}
377379

380+
// SetAttributes sets connection attributes
378381
func (c *Conn) SetAttributes(attributes map[string]string) {
379382
for k, v := range attributes {
380383
c.attributes[k] = v
@@ -407,6 +410,7 @@ func (c *Conn) GetCollation() string {
407410
return c.collation
408411
}
409412

413+
// FieldList uses COM_FIELD_LIST to get a list of fields from a table
410414
func (c *Conn) FieldList(table string, wildcard string) ([]*Field, error) {
411415
if err := c.writeCommandStrStr(COM_FIELD_LIST, table, wildcard); err != nil {
412416
return nil, errors.Trace(err)
@@ -446,10 +450,12 @@ func (c *Conn) SetAutoCommit() error {
446450
return nil
447451
}
448452

453+
// IsAutoCommit returns true if SERVER_STATUS_AUTOCOMMIT is set
449454
func (c *Conn) IsAutoCommit() bool {
450455
return c.status&SERVER_STATUS_AUTOCOMMIT > 0
451456
}
452457

458+
// IsInTransaction returns true if SERVER_STATUS_IN_TRANS is set
453459
func (c *Conn) IsInTransaction() bool {
454460
return c.status&SERVER_STATUS_IN_TRANS > 0
455461
}
@@ -485,6 +491,7 @@ func (c *Conn) exec(query string) (*Result, error) {
485491

486492
// CapabilityString is returning a string with the names of capability flags
487493
// separated by "|". Examples of capability names are CLIENT_DEPRECATE_EOF and CLIENT_PROTOCOL_41.
494+
// These are defined as constants in the mysql package.
488495
func (c *Conn) CapabilityString() string {
489496
var caps []string
490497
capability := c.capability
@@ -568,6 +575,8 @@ func (c *Conn) CapabilityString() string {
568575
return strings.Join(caps, "|")
569576
}
570577

578+
// StatusString returns a "|" separated list of status fields. Example status values are SERVER_QUERY_WAS_SLOW and SERVER_STATUS_AUTOCOMMIT.
579+
// These are defined as constants in the mysql package.
571580
func (c *Conn) StatusString() string {
572581
var stats []string
573582
status := c.status

driver/driver_options.go

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
// The value represents the query string parameter value supplied by in the DNS.
1313
type DriverOption func(c *client.Conn, value string) error
1414

15+
// UseSslOption sets the connection to use a tls.Config with InsecureSkipVerify set to true.
16+
// Use SetTLSConfig() if you need a custom tls.Config
1517
func UseSslOption(c *client.Conn) error {
1618
c.UseSSL(true)
1719
return nil

mysql/const.go

+8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ const (
2626
AUTH_SHA256_PASSWORD = "sha256_password"
2727
)
2828

29+
// SERVER_STATUS_flags_enum
30+
// https://dev.mysql.com/doc/dev/mysql-server/latest/mysql__com_8h.html#a1d854e841086925be1883e4d7b4e8cad
31+
// https://github.com/mysql/mysql-server/blob/500c3117e6f638043c4fea8aacf17d63a8d07de6/include/mysql_com.h#L809-L864
2932
const (
3033
SERVER_STATUS_IN_TRANS uint16 = 0x0001
3134
SERVER_STATUS_AUTOCOMMIT uint16 = 0x0002
@@ -39,8 +42,11 @@ const (
3942
SERVER_STATUS_METADATA_CHANGED uint16 = 0x0400
4043
SERVER_QUERY_WAS_SLOW uint16 = 0x0800
4144
SERVER_PS_OUT_PARAMS uint16 = 0x1000
45+
SERVER_STATUS_IN_TRANS_READONLY uint16 = 0x2000
46+
SERVER_SESSION_STATE_CHANGED uint16 = 0x4000
4247
)
4348

49+
// https://github.com/mysql/mysql-server/blob/6b6d3ed3d5c6591b446276184642d7d0504ecc86/include/my_command.h#L48-L103
4450
const (
4551
COM_SLEEP byte = iota
4652
COM_QUIT
@@ -74,6 +80,8 @@ const (
7480
COM_DAEMON
7581
COM_BINLOG_DUMP_GTID
7682
COM_RESET_CONNECTION
83+
COM_CLONE
84+
COM_SUBSCRIBE_GROUP_REPLICATION_STREAM
7785
)
7886

7987
const (

0 commit comments

Comments
 (0)