Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Xiangyu Hu <xiangyu.hu at outlook.com>
Xiaobing Jiang <s7v7nislands at gmail.com>
Xiuming Chen <cc at cxm.cc>
Xuehong Chan <chanxuehong at gmail.com>
Zhang Xiang <angwerzx at 126.com>
Zhenye Xie <xiezhenye at gmail.com>
Zhixin Wen <john.wenzhixin at gmail.com>
Ziheng Lyu <zihenglv at gmail.com>
Expand All @@ -126,6 +127,7 @@ InfoSum Ltd.
Keybase Inc.
Multiplay Ltd.
Percona LLC
PingCAP Inc.
Pivotal Inc.
Stripe Inc.
Zendesk Inc.
Expand Down
20 changes: 17 additions & 3 deletions driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3367,9 +3367,12 @@ func TestConnectionAttributes(t *testing.T) {

attr1 := "attr1"
value1 := "value1"
attr2 := "foo"
value2 := "boo"
dsn += fmt.Sprintf("&connectionAttributes=%s:%s,%s:%s", attr1, value1, attr2, value2)
attr2 := "fo/o"
value2 := "bo/o"
dsn += fmt.Sprintf(
"&connectionAttributes=%s:%s,%s:%s",
attr1, value1, url.QueryEscape(attr2), url.QueryEscape(value2),
)

var db *sql.DB
if _, err := ParseDSN(dsn); err != errInvalidDSNUnsafeCollation {
Expand All @@ -3395,6 +3398,17 @@ func TestConnectionAttributes(t *testing.T) {
}
rows.Close()

rows = dbt.mustQuery(queryString, attr1)
if rows.Next() {
rows.Scan(&attrValue)
if attrValue != value1 {
dbt.Errorf("expected %q, got %q", value1, attrValue)
}
} else {
dbt.Errorf("no data")
}
rows.Close()

rows = dbt.mustQuery(queryString, attr2)
if rows.Next() {
rows.Scan(&attrValue)
Expand Down
6 changes: 5 additions & 1 deletion dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,11 @@ func parseDSNParams(cfg *Config, params string) (err error) {

// Connection attributes
case "connectionAttributes":
cfg.ConnectionAttributes = value
connectionAttributes, err := url.QueryUnescape(value)
if err != nil {
return fmt.Errorf("invalid connectionAttributes value: %v", err)
}
cfg.ConnectionAttributes = connectionAttributes

default:
// lazy init
Expand Down