Skip to content

Conversation

@dveeden
Copy link
Contributor

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
ContributorAuthor

@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

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

@julienschmidt What work remains before this can be merged?

@dgryski
Copy link

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

packets.go Outdated
}

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?

@dveedendveedenforce-pushed the connattrs_v4 branch 2 times, most recently from 510077a to c8528afCompareMarch 6, 2016 22:09
@dveeden
Copy link
ContributorAuthor

cc @sjmudd

@dveeden
Copy link
ContributorAuthor

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
ContributorAuthor

Is there anything preventing this from getting merged?

@methane
Copy link
Member

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

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

LGTM, sorry for the long wait


varpidstring
varos_userstring
varos_user_fullstring
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

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

MultiStatementsbool// Allow multiple statements in one query
ParseTimebool// Parse time values to time.Time
Strictbool// Return warnings as errors
ConnAttrsmap[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
ContributorAuthor

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
ContributorAuthor

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++

forattrname, attrvalue:=rangeattrs{
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
ContributorAuthor

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).

@julienschmidtjulienschmidt modified the milestones: v1.3, v1.4Mar 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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@dveeden@julienschmidt@dgryski@arnehormann@methane