Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ func clearWarnings(ctx *sql.Context, node sql.Node) {
case *plan.Offset, *plan.Limit:
// `show warning limit x offset y` is valid, so we need to recurse
clearWarnings(ctx, n.Children()[0])
case *plan.Set:
case plan.ShowWarnings:
// ShowWarnings should not clear the warnings, but should still reset the warning count.
ctx.ClearWarningCount()
Expand Down
60 changes: 60 additions & 0 deletions enginetest/queries/variable_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,66 @@ var VariableQueries = []ScriptTest{
},
},
},
{
Name: "locked warnings stay after query",
SetUpScript: []string{
"set @@lock_warnings = 1",
"select 1/0,1/0",
"select 1/1",
},
Assertions: []ScriptTestAssertion{
{
Query: "show warnings",
Expected: []sql.Row{
{"Warning", 1365, "Division by 0"},
{"Warning", 1365, "Division by 0"}},
},
{
Query: "select 1/0",
Expected: []sql.Row{
{interface{}(nil)},
},
},
{
Query: "show warnings",
Expected: []sql.Row{
{"Warning", 1365, "Division by 0"},
{"Warning", 1365, "Division by 0"},
{"Warning", 1365, "Division by 0"},
},
},
},
},
{
Name: "unlocked warnings clear after query",
SetUpScript: []string{
"set @@lock_warnings = 0",
"select 1/0,1/0",
"select 1/1",
},
Assertions: []ScriptTestAssertion{
{
Query: "show warnings",
Expected: []sql.Row{},
},
},
},
{
Name: "warnings persist after locking between queries",
SetUpScript: []string{
"select 1/0",
"set @@lock_warnings = 1",
"select 1/1",
},
Assertions: []ScriptTestAssertion{
{
Query: "show warnings",
Expected: []sql.Row{
{"Warning", 1365, "Division by 0"},
},
},
},
},
//TODO: do not override tables with user-var-like names...but why would you do this??
//{
// Name: "user var table name no conflict",
Expand Down
17 changes: 17 additions & 0 deletions sql/variables/system_variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,23 @@ var systemVars = map[string]sql.SystemVariable{
Type: types.NewSystemIntType("lock_wait_timeout", 1, 31536000, false),
Default: int64(31536000),
},
"lock_warnings": &sql.MysqlSystemVariable{
Name: "lock_warnings",
Scope: sql.GetMysqlScope(sql.SystemVariableScope_Session),
Dynamic: true,
SetVarHintApplies: false,
Type: types.NewSystemBoolType("lock_warnings"),
Default: int8(0),
NotifyChanged: func(ctx *sql.Context, _ sql.SystemVariableScope, value sql.SystemVarValue) error {
switch value.Val.(int8) {
case 0:
ctx.UnlockWarnings()
case 1:
ctx.LockWarnings()
}
return nil
},
},
"log_bin": &sql.MysqlSystemVariable{
Name: "log_bin",
Scope: sql.GetMysqlScope(sql.SystemVariableScope_Persist),
Expand Down
Loading