Skip to content

Commit 57d1bbb

Browse files
committed
Fix sql_mode detection in enum strict mode validation
Use ctx.GetSessionVariable() instead of ctx.Session.GetSessionVariable() to properly access session variables in the enum conversion context.
1 parent 049e017 commit 57d1bbb

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

sql/types/enum.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,14 @@ func (t EnumType) Convert(ctx context.Context, v interface{}) (interface{}, sql.
216216
// isStrictMode checks if STRICT_TRANS_TABLES or STRICT_ALL_TABLES is enabled
217217
func (t EnumType) isStrictMode(ctx context.Context) bool {
218218
if sqlCtx, ok := ctx.(*sql.Context); ok {
219-
if sqlCtx.Session != nil {
220-
sysVal, err := sqlCtx.Session.GetSessionVariable(sqlCtx, "sql_mode")
221-
if err == nil {
222-
if sqlMode, ok := sysVal.(string); ok {
223-
return strings.Contains(sqlMode, "STRICT_TRANS_TABLES") || strings.Contains(sqlMode, "STRICT_ALL_TABLES")
224-
}
219+
// Try the direct context method first
220+
sysVal, err := sqlCtx.GetSessionVariable(sqlCtx, "sql_mode")
221+
if err != nil {
222+
sysVal, err = sqlCtx.GetSessionVariable(sqlCtx, "SQL_MODE")
223+
}
224+
if err == nil {
225+
if sqlMode, ok := sysVal.(string); ok {
226+
return strings.Contains(sqlMode, "STRICT_TRANS_TABLES") || strings.Contains(sqlMode, "STRICT_ALL_TABLES")
225227
}
226228
}
227229
}

0 commit comments

Comments
 (0)