Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 2 additions & 10 deletions engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ 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.ShowWarnings, *plan.Set:
case *plan.Set:
case plan.ShowWarnings:
// ShowWarnings should not clear the warnings, but should still reset the warning count.
ctx.ClearWarningCount()
default:
Expand Down Expand Up @@ -410,15 +411,6 @@ func (e *Engine) QueryWithBindings(ctx *sql.Context, query string, parsed sqlpar
return nil, nil, nil, err
}

shouldLock, err := ctx.GetSessionVariable(ctx, "lock_warnings")
if err != nil {
return nil, nil, nil, err
}
if shouldLock.(int8) == 1 {
ctx.LockWarnings()
defer ctx.UnlockWarnings()
}

// planbuilding can produce warnings, so we need to preserve them
numPrevWarnings := len(ctx.Session.Warnings())
bound, qFlags, err := e.bindQuery(ctx, query, parsed, bindings, binder, qFlags)
Expand Down
30 changes: 30 additions & 0 deletions enginetest/queries/variable_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,20 @@ var VariableQueries = []ScriptTest{
{"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"},
},
},
},
},
{
Expand All @@ -605,6 +619,22 @@ var VariableQueries = []ScriptTest{
},
},
},
{
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
11 changes: 10 additions & 1 deletion sql/variables/system_variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -1255,11 +1255,20 @@ var systemVars = map[string]sql.SystemVariable{
},
"lock_warnings": &sql.MysqlSystemVariable{
Name: "lock_warnings",
Scope: sql.GetMysqlScope(sql.SystemVariableScope_Both),
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",
Expand Down
Loading