Skip to content

Commit 9865fd5

Browse files
committed
Update based on review
1 parent 25f3bae commit 9865fd5

File tree

4 files changed

+17
-18
lines changed

4 files changed

+17
-18
lines changed

client/conn.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -508,19 +508,20 @@ func (c *Conn) exec(query string) (*Result, error) {
508508
// https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_com_query.html
509509
func (c *Conn) execSend(query string) error {
510510
var buf bytes.Buffer
511+
defer clear(c.queryAttributes)
511512

512-
if c.includeLine >= 0 {
513-
_, file, line, ok := runtime.Caller(c.includeLine)
514-
if ok {
515-
lineAttr := QueryAttribute{
516-
Name: "_line",
517-
Value: fmt.Sprintf("%s:%d", file, line),
513+
if c.capability&CLIENT_QUERY_ATTRIBUTES > 0 {
514+
if c.includeLine >= 0 {
515+
_, file, line, ok := runtime.Caller(c.includeLine)
516+
if ok {
517+
lineAttr := QueryAttribute{
518+
Name: "_line",
519+
Value: fmt.Sprintf("%s:%d", file, line),
520+
}
521+
c.queryAttributes = append(c.queryAttributes, lineAttr)
518522
}
519-
c.queryAttributes = append(c.queryAttributes, lineAttr)
520523
}
521-
}
522524

523-
if c.capability&CLIENT_QUERY_ATTRIBUTES > 0 {
524525
numParams := len(c.queryAttributes)
525526
buf.Write(PutLengthEncodedInt(uint64(numParams)))
526527
buf.WriteByte(0x1) // parameter_set_count, unused
@@ -548,7 +549,6 @@ func (c *Conn) execSend(query string) error {
548549
if err := c.writeCommandBuf(COM_QUERY, buf.Bytes()); err != nil {
549550
return errors.Trace(err)
550551
}
551-
c.queryAttributes = nil
552552

553553
return nil
554554
}

client/stmt.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,14 @@ func (s *Stmt) Close() error {
5959

6060
// https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_com_stmt_execute.html
6161
func (s *Stmt) write(args ...interface{}) error {
62+
defer clear(s.conn.queryAttributes)
6263
paramsNum := s.params
6364

6465
if len(args) != paramsNum {
6566
return fmt.Errorf("argument mismatch, need %d but got %d", s.params, len(args))
6667
}
6768

68-
if s.conn.includeLine >= 0 {
69+
if (s.conn.capability&CLIENT_QUERY_ATTRIBUTES > 0) && (s.conn.includeLine >= 0) {
6970
_, file, line, ok := runtime.Caller(s.conn.includeLine)
7071
if ok {
7172
lineAttr := QueryAttribute{
@@ -227,7 +228,6 @@ func (s *Stmt) write(args ...interface{}) error {
227228
}
228229

229230
s.conn.ResetSequence()
230-
s.conn.queryAttributes = nil
231231

232232
return s.conn.WritePacket(data.Bytes())
233233
}

mysql/queryattributes.go

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88

99
// Query Attributes in MySQL are key/value pairs passed along with COM_QUERY or COM_STMT_EXECUTE
1010
//
11+
// Supported Value types: string, uint64
12+
//
1113
// Resources:
1214
// - https://dev.mysql.com/doc/refman/8.4/en/query-attributes.html
1315
// - https://github.com/mysql/mysql-server/blob/trunk/include/mysql/components/services/mysql_query_attributes.h

server/stmt.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,13 @@ func (c *Conn) handleStmtExecute(data []byte) (*Result, error) {
118118

119119
// Test for unsupported flags in the remaining 4 bits.
120120
if flag&CURSOR_TYPE_READ_ONLY > 0 {
121-
return nil, NewError(ER_UNKNOWN_ERROR,
122-
fmt.Sprintf("unsupported flag %s", "CURSOR_TYPE_READ_ONLY"))
121+
return nil, NewError(ER_UNKNOWN_ERROR, "unsupported flag CURSOR_TYPE_READ_ONLY")
123122
}
124123
if flag&CURSOR_TYPE_FOR_UPDATE > 0 {
125-
return nil, NewError(ER_UNKNOWN_ERROR,
126-
fmt.Sprintf("unsupported flag %s", "CURSOR_TYPE_FOR_UPDATE"))
124+
return nil, NewError(ER_UNKNOWN_ERROR, "unsupported flag CURSOR_TYPE_FOR_UPDATE")
127125
}
128126
if flag&CURSOR_TYPE_SCROLLABLE > 0 {
129-
return nil, NewError(ER_UNKNOWN_ERROR,
130-
fmt.Sprintf("unsupported flag %s", "CURSOR_TYPE_SCROLLABLE"))
127+
return nil, NewError(ER_UNKNOWN_ERROR, "unsupported flag CURSOR_TYPE_SCROLLABLE")
131128
}
132129

133130
//skip iteration-count, always 1

0 commit comments

Comments
 (0)