@@ -24,14 +24,31 @@ import (
2424const (
2525 SqlModeSessionVar = "SQL_MODE"
2626
27- ANSI = "ANSI"
28- ANSIQuotes = "ANSI_QUOTES"
29- OnlyFullGroupBy = "ONLY_FULL_GROUP_BY"
30- NoAutoValueOnZero = "NO_AUTO_VALUE_ON_ZERO"
31- NoEngineSubstitution = "NO_ENGINE_SUBSTITUTION"
32- StrictTransTables = "STRICT_TRANS_TABLES"
33- PipesAsConcat = "PIPES_AS_CONCAT"
34- DefaultSqlMode = "NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES"
27+ AllowInvalidDates = "ALLOW_INVALID_DATES"
28+ ANSIQuotes = "ANSI_QUOTES"
29+ ErrorForDivisionByZero = "ERROR_FOR_DIVISION_BY_ZERO"
30+ HighNotPrecedence = "HIGH_NOT_PRECEDENCE"
31+ IgnoreSpaces = "IGNORE_SPACE"
32+ NoAutoValueOnZero = "NO_AUTO_VALUE_ON_ZERO"
33+ NoBackslashEscapes = "NO_BACKSLASH_ESCAPES"
34+ NoDirInCreate = "NO_DIR_IN_CREATE"
35+ NoEngineSubstitution = "NO_ENGINE_SUBSTITUTION"
36+ NoUnsignedSubtraction = "NO_UNSIGNED_SUBTRACTION"
37+ NoZeroInDate = "NO_ZERO_IN_DATE"
38+ OnlyFullGroupBy = "ONLY_FULL_GROUP_BY"
39+ PadCharToFullLength = "PAD_CHAR_TO_FULL_LENGTH"
40+ PipesAsConcat = "PIPES_AS_CONCAT"
41+ RealAsFloat = "REAL_AS_FLOAT"
42+ StrictTransTables = "STRICT_TRANS_TABLES"
43+ StrictAllTables = "STRICT_ALL_TABLES"
44+ TimeTruncateFractional = "TIME_TRUNCATE_FRACTIONAL"
45+
46+ // ANSI mode includes REAL_AS_FLOAT, PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE, and ONLY_FULL_GROUP_BY
47+ ANSI = "ANSI"
48+ // Traditional mode includes STRICT_TRANS_TABLES, STRICT_ALL_TABLES, NO_ZERO_IN_DATE, ERROR_FOR_DIVISION_BY_ZERO,
49+ // and NO_ENGINE_SUBSTITUTION
50+ Traditional = "TRADITIONAL"
51+ DefaultSqlMode = "NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES"
3552)
3653
3754var defaultMode * SqlMode
@@ -74,7 +91,7 @@ func LoadSqlMode(ctx *Context) *SqlMode {
7491}
7592
7693// NewSqlModeFromString returns a new SqlMode instance, constructed from the specified |sqlModeString| that
77- // has a comma delimited list of SQL modes (e.g. "ONLY_FULLY_GROUP_BY,ANSI_QUOTES").
94+ // has a comma- delimited list of SQL modes (e.g. "ONLY_FULLY_GROUP_BY,ANSI_QUOTES").
7895func NewSqlModeFromString (sqlModeString string ) * SqlMode {
7996 if sqlModeString == DefaultSqlMode {
8097 return defaultMode
@@ -99,9 +116,36 @@ func (s *SqlMode) AnsiQuotes() bool {
99116 return s .ModeEnabled (ANSIQuotes ) || s .ModeEnabled (ANSI )
100117}
101118
102- // PipesAsConcat returns true if PIPES_AS_CONCAT SQL mode is enabled.
119+ // OnlyFullGroupBy returns true is ONLY_TRUE_GROUP_BY SQL mode is enabled. Note that ANSI mode is a compound mode that
120+ // includes ONLY_FULL_GROUP_BY and other options, so if ANSI or ONLY_TRUE_GROUP_BY is enabled, this function will
121+ // return true.
122+ func (s * SqlMode ) OnlyFullGroupBy () bool {
123+ return s .ModeEnabled (OnlyFullGroupBy ) || s .ModeEnabled (ANSI )
124+ }
125+
126+ // PipesAsConcat returns true if PIPES_AS_CONCAT SQL mode is enabled. Note that ANSI mode is a compound mode that
127+ // includes PIPES_AS_CONCAT and other options, so if ANSI or PIPES_AS_CONCAT is enabled, this function will return true.
103128func (s * SqlMode ) PipesAsConcat () bool {
104- return s .ModeEnabled (PipesAsConcat )
129+ return s .ModeEnabled (PipesAsConcat ) || s .ModeEnabled (ANSI )
130+ }
131+
132+ // StrictTransTables returns true if STRICT_TRANS_TABLES SQL mode is enabled. Note that TRADITIONAL mode is a compound
133+ // mode that includes STRICT_TRANS_TABLES and other options, so if TRADITIONAL or STRICT_TRANS_TABLES is enabled, this
134+ // function will return true.
135+ func (s * SqlMode ) StrictTransTables () bool {
136+ return s .ModeEnabled (StrictTransTables ) || s .ModeEnabled (Traditional )
137+ }
138+
139+ // StrictAllTables returns true if STRICT_ALL_TABLES SQL mode is enabled. Note that TRADITIONAL mode is a compound
140+ // mode that includes STRICT_ALL_TABLES and other options, so if TRADITIONAL or STRICT_ALL_TABLES is enabled, this
141+ // function will return true.
142+ func (s * SqlMode ) StrictAllTables () bool {
143+ return s .ModeEnabled (StrictAllTables ) || s .ModeEnabled (Traditional )
144+ }
145+
146+ // Strict mode is enabled when either STRICT_TRANS_TABLES or STRICT_ALL_TABLES is enabled.
147+ func (s * SqlMode ) Strict () bool {
148+ return s .StrictAllTables () || s .StrictTransTables ()
105149}
106150
107151// ModeEnabled returns true if |mode| was explicitly specified in the SQL_MODE string that was used to
@@ -126,12 +170,3 @@ func (s *SqlMode) ParserOptions() sqlparser.ParserOptions {
126170func (s * SqlMode ) String () string {
127171 return s .modeString
128172}
129-
130- // ValidateStrictMode returns true if either STRICT_TRANS_TABLES or STRICT_ALL_TABLES is enabled
131- func ValidateStrictMode (ctx * Context ) bool {
132- if ctx == nil {
133- return false
134- }
135- sqlMode := LoadSqlMode (ctx )
136- return sqlMode .ModeEnabled ("STRICT_TRANS_TABLES" ) || sqlMode .ModeEnabled ("STRICT_ALL_TABLES" )
137- }
0 commit comments