-
Notifications
You must be signed in to change notification settings - Fork 2.3k
allow unknown collation name #1604
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,45 +67,20 @@ func (mc *mysqlConn) handleParams() (err error) { | |
var cmdSet strings.Builder | ||
|
||
for param, val := range mc.cfg.Params { | ||
switch param { | ||
// Charset: character_set_connection, character_set_client, character_set_results | ||
case "charset": | ||
charsets := strings.Split(val, ",") | ||
for _, cs := range charsets { | ||
// ignore errors here - a charset may not exist | ||
if mc.cfg.Collation != "" { | ||
err = mc.exec("SET NAMES " + cs + " COLLATE " + mc.cfg.Collation) | ||
} else { | ||
err = mc.exec("SET NAMES " + cs) | ||
} | ||
if err == nil { | ||
break | ||
} | ||
} | ||
if err != nil { | ||
return | ||
} | ||
|
||
// Other system vars accumulated in a single SET command | ||
default: | ||
if cmdSet.Len() == 0 { | ||
// Heuristic: 29 chars for each other key=value to reduce reallocations | ||
cmdSet.Grow(4 + len(param) + 3 + len(val) + 30*(len(mc.cfg.Params)-1)) | ||
cmdSet.WriteString("SET ") | ||
} else { | ||
cmdSet.WriteString(", ") | ||
} | ||
cmdSet.WriteString(param) | ||
cmdSet.WriteString(" = ") | ||
cmdSet.WriteString(val) | ||
if cmdSet.Len() == 0 { | ||
// Heuristic: 29 chars for each other key=value to reduce reallocations | ||
cmdSet.Grow(4 + len(param) + 3 + len(val) + 30*(len(mc.cfg.Params)-1)) | ||
cmdSet.WriteString("SET ") | ||
} else { | ||
cmdSet.WriteString(", ") | ||
} | ||
cmdSet.WriteString(param) | ||
cmdSet.WriteString(" = ") | ||
cmdSet.WriteString(val) | ||
} | ||
|
||
if cmdSet.Len() > 0 { | ||
err = mc.exec(cmdSet.String()) | ||
if err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if there's an expected reviewer set who will look this PR over, but to me this is the only thing in the PR I have reservations on. It might be worth mentioning the behavioral impact of not returning an error during connection param setting? I'm guessing this is to avoid errors where we're "falling through" different charsets or collations and multiple have been specified, but I'm not sure if it's worth still throwing an error if we're dealing with a problem like someone adding a param for a variable that should be a global var. Ex:
type situation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function uses named return value. So this line returns the errorr. |
||
return | ||
} | ||
} | ||
|
||
return | ||
|
Uh oh!
There was an error while loading. Please reload this page.