Skip to content

Commit 093faa3

Browse files
committed
Add initial support for connection attributes.
This sets attribute _client_name with the value "Go MySQL Driver"
1 parent 0cc29e9 commit 093faa3

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

packets.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ func (mc *mysqlConn) writeAuthPacket(cipher []byte) error {
214214
clientLongPassword |
215215
clientTransactions |
216216
clientLocalFiles |
217+
clientConnectAttrs |
217218
mc.flags&clientLongFlag
218219

219220
if mc.cfg.clientFoundRows {
@@ -228,7 +229,12 @@ func (mc *mysqlConn) writeAuthPacket(cipher []byte) error {
228229
// User Password
229230
scrambleBuff := scramblePassword(cipher, []byte(mc.cfg.passwd))
230231

232+
attrname := []byte("_client_name")
233+
attrvalue := []byte("Go MySQL Driver")
234+
attrlen := len(attrname) + len(attrvalue) + 2
235+
231236
pktLen := 4 + 4 + 1 + 23 + len(mc.cfg.user) + 1 + 1 + len(scrambleBuff)
237+
pktLen += len(attrname) + len(attrvalue) + 3
232238

233239
// To specify a db name
234240
if n := len(mc.cfg.dbname); n > 0 {
@@ -295,6 +301,17 @@ func (mc *mysqlConn) writeAuthPacket(cipher []byte) error {
295301
pos += copy(data[pos:], mc.cfg.dbname)
296302
data[pos] = 0x00
297303
}
304+
pos++
305+
306+
// Connection attributes
307+
data[pos] = byte(attrlen)
308+
pos++
309+
310+
data[pos] = byte(len(attrname))
311+
pos += 1 + copy(data[pos+1:], attrname)
312+
313+
data[pos] = byte(len(attrvalue))
314+
pos += 1 + copy(data[pos+1:], attrvalue)
298315

299316
// Send Auth packet
300317
return mc.writePacket(data)

0 commit comments

Comments
 (0)