Skip to content

Commit

Permalink
Default sql mode for common path (#2520)
Browse files Browse the repository at this point in the history
* Default sql mode for common path

* jason comments

* upper case
  • Loading branch information
max-hoffman authored May 29, 2024
1 parent 5e36924 commit 6e2cb91
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
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"
)

var defaultMode *SqlMode

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

// 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
2 changes: 1 addition & 1 deletion sql/variables/system_variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -2407,7 +2407,7 @@ var systemVars = map[string]sql.SystemVariable{
Dynamic: true,
SetVarHintApplies: true,
Type: types.NewSystemSetType("sql_mode", "ALLOW_INVALID_DATES", "ANSI_QUOTES", "ERROR_FOR_DIVISION_BY_ZERO", "HIGH_NOT_PRECEDENCE", "IGNORE_SPACE", "NO_AUTO_VALUE_ON_ZERO", "NO_BACKSLASH_ESCAPES", "NO_DIR_IN_CREATE", "NO_ENGINE_SUBSTITUTION", "NO_UNSIGNED_SUBTRACTION", "NO_ZERO_DATE", "NO_ZERO_IN_DATE", "ONLY_FULL_GROUP_BY", "PAD_CHAR_TO_FULL_LENGTH", "PIPES_AS_CONCAT", "REAL_AS_FLOAT", "STRICT_ALL_TABLES", "STRICT_TRANS_TABLES", "TIME_TRUNCATE_FRACTIONAL", "TRADITIONAL", "ANSI"),
Default: "NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES",
Default: sql.DefaultSqlMode,
},
"sql_notes": &sql.MysqlSystemVariable{
Name: "sql_notes",
Expand Down

0 comments on commit 6e2cb91

Please sign in to comment.