Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for connection attributes #350

Merged
merged 1 commit into from
Mar 29, 2016

Conversation

dveeden
Copy link
Contributor

@dveeden dveeden commented Jun 21, 2015

This supersedes #343.

This is to support connection attributes. A number of connection attributes like _pid, _client_name are sent by default and it is possible to send custom attributes.

I noticed that user.Current() doesn't work on Fedora 22 with golang, but it does work with gccgo. If this doesn't work then it won't send this attribute to the server.

Edit (js): List of required fixes: #350 (comment)

@dveeden
Copy link
Contributor Author

dveeden commented Jun 21, 2015

@julienschmidt I tried to fix everything you suggested in #343

@julienschmidt
Copy link
Member

ProTip™: You can update existing pull-requests by adding commits to the respective branch in your fork

@julienschmidt julienschmidt added this to the v1.3 milestone Jul 24, 2015
@julienschmidt julienschmidt modified the milestones: v1.4, v1.3 Jan 13, 2016
@dgryski
Copy link

dgryski commented Feb 25, 2016

@julienschmidt What work remains before this can be merged?

@dgryski
Copy link

dgryski commented Feb 26, 2016

I am planning on rebasing this against master and to fix the merge conflicts and then will squash all the commits.

pktLen := 4 + 4 + 1 + 23 + len(mc.cfg.user) + 1 + 1 + len(scrambleBuff) + 21 + 1
pktLen += attrlen + 1 // one byte to store the total length of attrs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skip all this when clientConnectAttrs is missing in server capabilities

@arnehormann
Copy link
Member

@julienschmidt any blockers?

@dveeden dveeden force-pushed the connattrs_v4 branch 2 times, most recently from 510077a to c8528af Compare March 6, 2016 22:09
@dveeden
Copy link
Contributor Author

dveeden commented Mar 15, 2016

cc @sjmudd

@dveeden
Copy link
Contributor Author

dveeden commented Mar 15, 2016

Pushed a new version to get rid of the merge conflict in AUTHORS

This sets attribute _client_name with the value "Go MySQL Driver"
Also sets _os, _platform, _pid and program_name by default.

This also decodes the uppper two bytes of the capability flags.

The dsn_test.go only tests for one attribute because there is no
guaranteed sort order for a map and Printf %+v as used by
TestDSNParser().
@dveeden
Copy link
Contributor Author

dveeden commented Mar 29, 2016

Is there anything preventing this from getting merged?

@methane
Copy link
Member

methane commented Mar 29, 2016

Are default attrs same to libmysqclient?
If so, LGTM.

@arnehormann arnehormann merged commit 2625e19 into go-sql-driver:master Mar 29, 2016
@arnehormann
Copy link
Member

LGTM, sorry for the long wait

@@ -30,6 +33,10 @@ type MySQLDriver struct{}
// Custom dial functions must be registered with RegisterDial
type DialFunc func(addr string) (net.Conn, error)

var pid string
var os_user string
var os_user_full string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong naming convention

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed #442 for this lint issue.

@julienschmidt
Copy link
Member

Tests are also missing (parser tests are not sufficient). I'm tempted to revert this merge

MultiStatements bool // Allow multiple statements in one query
ParseTime bool // Parse time values to time.Time
Strict bool // Return warnings as errors
ConnAttrs map[string]string // Connection Attributes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A map[string]string is rather heavy. This could be pre-packed into 1 string

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forget what I said, this should stay user-friendly. The Config struct is now exported

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we move this to a string than we would have to parse it every time we make a connection. So there is a trade-off.

@arnehormann
Copy link
Member

OK. Let's summerize: to get this remerged or fixed we need

  • an additional test (finding the connection attrs in a query)
  • a paren-less syntax - comma separated?
  • conforming names
  • cached attributes

julienschmidt added a commit that referenced this pull request Mar 29, 2016
This reverts commit 2625e19, reversing
changes made to 66312f7.
@julienschmidt
Copy link
Member

Reverted for now.

I think 99% of the users don't care about connections attributes. Should they maybe only be sent when a DSN param is set?
cannAttrs=true to set defaults, connAttrs=whatever to add custom ones?

@arnehormann
Copy link
Member

I can see their value, but requiring a DSN arg is fine by me.

Do you have a preference for a whatever flavor?

  1. separator connAttrs=key1=value1,key2=value2
  2. multiple params connAttrs=key1=value1&connAttrs=key2=value2

@dveeden
Copy link
Contributor Author

dveeden commented Mar 29, 2016

Instead of connattrs=(foo=bar,foo2=bar2) we could do connattrs=foo:bar,foo2:bar2
Would that be ok?

@arnehormann
Copy link
Member

= is ok - as long as there's no &. Just split on , and then on =.

@julienschmidt
Copy link
Member

= is ok - as long as there's no &.

Is it? RFC study time 😄

data[pos] = byte(attrlen)
pos++

for attrname, attrvalue := range attrs {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dveeden That is what I meant. You could directly pack this into one byte sequence / string when the params are parsed.

But forget that, the Config is exported for a reason now.

@dveeden
Copy link
Contributor Author

dveeden commented Mar 29, 2016

What would you want in addition to the parser tests I added?

@julienschmidt
Copy link
Member

A functional test

@julienschmidt
Copy link
Member

And is this backwards-compatible?
It seems like connection attributes were only added in MySQL 5.6

@arnehormann
Copy link
Member

@julienschmidt I leave this in your opinionated and very capable hands.

RE RFC: I can't find docs saying we have to adhere to an RFC (though we are inspired by one). The unescaped pwd, and tcp(...) would also be a problem for a URL.

RE backwards compatibility: comparison with server flags https://github.com/go-sql-driver/mysql/pull/350/files#diff-2357b8494bbd2f27c09e61fc8ef5f092R260

@julienschmidt
Copy link
Member

I think it's clear that our DSNs are no URLs (unfortunately, that is one historic mistake. Should we CC the letsencrypt guys again?).
But let's adhere to URI RFCs as much as possible and don't reinvent the wheel (any further).

@julienschmidt julienschmidt modified the milestones: v1.3, v1.4 Mar 29, 2016
@arnehormann
Copy link
Member

RE DSN format - here's what Google does for webfonts:
key1:value1|key2:value1,value2
https://fonts.googleapis.com/css?family=Open+Sans:400,600italic,700italic|Roboto:400,500

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants