File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -211,8 +211,15 @@ func (c *Conn) writeAuthHandshake() error {
211211 capability := mysql .CLIENT_PROTOCOL_41 | mysql .CLIENT_SECURE_CONNECTION |
212212 mysql .CLIENT_LONG_PASSWORD | mysql .CLIENT_TRANSACTIONS | mysql .CLIENT_PLUGIN_AUTH
213213 // Adjust client capability flags based on server support
214- capability |= c .capability & mysql .CLIENT_LONG_FLAG
215- capability |= c .capability & mysql .CLIENT_QUERY_ATTRIBUTES
214+ // ---- Inherit capabilities that the server has and the user has NOT explicitly denied ----
215+ inherit := c .capability & ^ c .dcaps // Server-side capabilities minus explicit denies
216+ capability |= inherit & mysql .CLIENT_LONG_FLAG // Existing
217+ // ---- Handling of CLIENT_QUERY_ATTRIBUTES ----
218+ if c .ccaps & mysql .CLIENT_QUERY_ATTRIBUTES != 0 { // Explicitly ON
219+ capability |= mysql .CLIENT_QUERY_ATTRIBUTES
220+ } else if inherit & mysql .CLIENT_QUERY_ATTRIBUTES != 0 { // Server has it and no denial
221+ capability |= mysql .CLIENT_QUERY_ATTRIBUTES
222+ }
216223 // Adjust client capability flags on specific client requests
217224 // Only flags that would make any sense setting and aren't handled elsewhere
218225 // in the library are supported here
@@ -361,5 +368,7 @@ func (c *Conn) writeAuthHandshake() error {
361368 data [pos ] = 0x03
362369 }
363370
371+ c .capability = capability // update capability to the one we sent
372+
364373 return c .WritePacket (data )
365374}
Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ type Conn struct {
4545 capability uint32
4646 // client-set capabilities only
4747 ccaps uint32
48+ dcaps uint32 // disabled capabilities
4849
4950 attributes map [string ]string
5051
@@ -236,12 +237,14 @@ func (c *Conn) Ping() error {
236237
237238// SetCapability enables the use of a specific capability
238239func (c * Conn ) SetCapability (cap uint32 ) {
240+ c .dcaps &^= cap
239241 c .ccaps |= cap
240242}
241243
242244// UnsetCapability disables the use of a specific capability
243245func (c * Conn ) UnsetCapability (cap uint32 ) {
244- c .ccaps &= ^ cap
246+ c .ccaps &^= cap
247+ c .dcaps |= cap
245248}
246249
247250// HasCapability returns true if the connection has the specific capability
You can’t perform that action at this time.
0 commit comments