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

Default sql mode for common path #2520

Merged
merged 3 commits into from
May 29, 2024
Merged
Changes from 1 commit
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
19 changes: 19 additions & 0 deletions sql/sql_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,24 @@ const (
NoAutoValueOnZero = "NO_AUTO_VALUE_ON_ZERO"
NoEngineSubstitution = "NO_ENGINE_SUBSTITUTION"
StrictTransTables = "STRICT_TRANS_TABLES"
defaultSqlMode = "no_engine_substitution,only_full_group_by,strict_trans_tables"
Copy link
Contributor

Choose a reason for hiding this comment

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

(minor) You might consider exposing this constant (and uppercasing?) – then you could reference this default from system_variables.go instead of relying on those to match up. That way, if someone does change system_variables.go to change that value in the future, they'd have to come change it here and make sure this code gets updated, too. (you could also just reuse defaultSqlMode on line 47 if you want to avoid that extra strings.Join call.)

)

var defaultMode *SqlMode

func init() {
elements := strings.Split(defaultSqlMode, ",")
sort.Strings(elements)
modes := map[string]struct{}{}
for _, element := range elements {
modes[element] = struct{}{}
}
defaultMode = &SqlMode{
modes: modes,
modeString: strings.ToUpper(strings.Join(elements, ",")),
}
}

// SqlMode encodes the SQL mode string and provides methods for querying the enabled modes.
type SqlMode struct {
modes map[string]struct{}
Expand Down Expand Up @@ -59,6 +75,9 @@ func LoadSqlMode(ctx *Context) *SqlMode {
// NewSqlModeFromString returns a new SqlMode instance, constructed from the specified |sqlModeString| that
// has a comma delimited list of SQL modes (e.g. "ONLY_FULLY_GROUP_BY,ANSI_QUOTES").
func NewSqlModeFromString(sqlModeString string) *SqlMode {
if strings.EqualFold(sqlModeString, defaultSqlMode) {
return defaultMode
}
sqlModeString = strings.ToLower(sqlModeString)
elements := strings.Split(sqlModeString, ",")
sort.Strings(elements)
Expand Down
Loading