Skip to content

Commit 93f69b8

Browse files
Nathan GabrielsonNathan Gabrielson
authored andcommitted
Fix requested changes
1 parent aa19071 commit 93f69b8

File tree

3 files changed

+42
-11
lines changed

3 files changed

+42
-11
lines changed

engine.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ 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, *plan.Set:
271+
case *plan.Set:
272+
case plan.ShowWarnings:
272273
// ShowWarnings should not clear the warnings, but should still reset the warning count.
273274
ctx.ClearWarningCount()
274275
default:
@@ -410,15 +411,6 @@ func (e *Engine) QueryWithBindings(ctx *sql.Context, query string, parsed sqlpar
410411
return nil, nil, nil, err
411412
}
412413

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

enginetest/queries/variable_queries.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,20 @@ var VariableQueries = []ScriptTest{
589589
{"Warning", 1365, "Division by 0"},
590590
{"Warning", 1365, "Division by 0"}},
591591
},
592+
{
593+
Query: "select 1/0",
594+
Expected: []sql.Row{
595+
{"NULL"},
596+
},
597+
},
598+
{
599+
Query: "show warnings",
600+
Expected: []sql.Row{
601+
{"Warning", 1365, "Division by 0"},
602+
{"Warning", 1365, "Division by 0"},
603+
{"Warning", 1365, "Division by 0"},
604+
},
605+
},
592606
},
593607
},
594608
{
@@ -605,6 +619,22 @@ var VariableQueries = []ScriptTest{
605619
},
606620
},
607621
},
622+
{
623+
Name: "warnings persist after locking between queries",
624+
SetUpScript: []string{
625+
"select 1/0",
626+
"set @@lock_warnings = 1",
627+
"select 1/1",
628+
},
629+
Assertions: []ScriptTestAssertion{
630+
{
631+
Query: "show warnings",
632+
Expected: []sql.Row{
633+
{"Warning", 1365, "Division by 0"},
634+
},
635+
},
636+
},
637+
},
608638
//TODO: do not override tables with user-var-like names...but why would you do this??
609639
//{
610640
// Name: "user var table name no conflict",

sql/variables/system_variables.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1255,11 +1255,20 @@ var systemVars = map[string]sql.SystemVariable{
12551255
},
12561256
"lock_warnings": &sql.MysqlSystemVariable{
12571257
Name: "lock_warnings",
1258-
Scope: sql.GetMysqlScope(sql.SystemVariableScope_Both),
1258+
Scope: sql.GetMysqlScope(sql.SystemVariableScope_Session),
12591259
Dynamic: true,
12601260
SetVarHintApplies: false,
12611261
Type: types.NewSystemBoolType("lock_warnings"),
12621262
Default: int8(0),
1263+
NotifyChanged: func(ctx *sql.Context, _ sql.SystemVariableScope, value sql.SystemVarValue) error {
1264+
switch value.Val.(int8) {
1265+
case 0:
1266+
ctx.UnlockWarnings()
1267+
case 1:
1268+
ctx.LockWarnings()
1269+
}
1270+
return nil
1271+
},
12631272
},
12641273
"log_bin": &sql.MysqlSystemVariable{
12651274
Name: "log_bin",

0 commit comments

Comments
 (0)