@@ -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
509509func (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}
0 commit comments