Skip to content

Commit 1a12b85

Browse files
Nathan GabrielsonNathan Gabrielson
authored andcommitted
Add session variable for locking warnings
1 parent 5d12b6a commit 1a12b85

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

engine.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ func clearWarnings(ctx *sql.Context, node sql.Node) {
268268
case *plan.Offset, *plan.Limit:
269269
// `show warning limit x offset y` is valid, so we need to recurse
270270
clearWarnings(ctx, n.Children()[0])
271-
case plan.ShowWarnings:
271+
case plan.ShowWarnings, *plan.Set:
272272
// ShowWarnings should not clear the warnings, but should still reset the warning count.
273273
ctx.ClearWarningCount()
274274
default:
@@ -410,6 +410,15 @@ func (e *Engine) QueryWithBindings(ctx *sql.Context, query string, parsed sqlpar
410410
return nil, nil, nil, err
411411
}
412412

413+
shouldLock, err := ctx.GetSessionVariable(ctx, "lock_warnings")
414+
if err != nil {
415+
return nil, nil, nil, err
416+
}
417+
if shouldLock == true {
418+
ctx.LockWarnings()
419+
defer ctx.UnlockWarnings()
420+
}
421+
413422
// planbuilding can produce warnings, so we need to preserve them
414423
numPrevWarnings := len(ctx.Session.Warnings())
415424
bound, qFlags, err := e.bindQuery(ctx, query, parsed, bindings, binder, qFlags)

sql/variables/system_variables.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,14 @@ var systemVars = map[string]sql.SystemVariable{
12531253
Type: types.NewSystemIntType("lock_wait_timeout", 1, 31536000, false),
12541254
Default: int64(31536000),
12551255
},
1256+
"lock_warnings": &sql.MysqlSystemVariable{
1257+
Name: "lock_warnings",
1258+
Scope: sql.GetMysqlScope(sql.SystemVariableScope_Both),
1259+
Dynamic: true,
1260+
SetVarHintApplies: false,
1261+
Type: types.NewSystemBoolType("lock_warnings"),
1262+
Default: int8(0),
1263+
},
12561264
"log_bin": &sql.MysqlSystemVariable{
12571265
Name: "log_bin",
12581266
Scope: sql.GetMysqlScope(sql.SystemVariableScope_Persist),

0 commit comments

Comments
 (0)