Skip to content

Commit

Permalink
Merge pull request #6495 from planetscale/allowmulti-in-executorset
Browse files Browse the repository at this point in the history
HandleSet in executor to handle multiple settings in single set statement
  • Loading branch information
systay committed Jul 30, 2020
2 parents 1a9ab85 + e0466dd commit 808c7b7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions go/vt/vtgate/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ func (e *Executor) handleSet(ctx context.Context, safeSession *SafeSession, sql
logStats.ExecuteTime = time.Since(execStart)
}()

var value interface{}
for _, expr := range set.Exprs {
// This is what correctly allows us to handle queries such as "set @@session.`autocommit`=1"
// it will remove backticks and double quotes that might surround the part after the first period
Expand All @@ -384,25 +385,28 @@ func (e *Executor) handleSet(ctx context.Context, safeSession *SafeSession, sql
case sqlparser.GlobalStr:
return nil, vterrors.New(vtrpcpb.Code_INVALID_ARGUMENT, "unsupported in set: global")
case sqlparser.SessionStr:
value, err := getValueFor(expr)
value, err = getValueFor(expr)
if err != nil {
return nil, err
}
return &sqltypes.Result{}, handleSessionSetting(ctx, name, safeSession, value, e.txConn, sql)
err = handleSessionSetting(ctx, name, safeSession, value, e.txConn, sql)
case sqlparser.VitessMetadataStr:
value, err := getValueFor(expr)
value, err = getValueFor(expr)
if err != nil {
return nil, err
}
val, ok := value.(string)
if !ok {
return nil, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "unexpected value type for charset: %v", value)
}
return e.handleSetVitessMetadata(ctx, name, val)
_, err = e.handleSetVitessMetadata(ctx, name, val)
case "": // we should only get here with UDVs
return nil, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "should have been handled by planning")

}
if err != nil {
return nil, err
}
}

return &sqltypes.Result{}, nil
Expand Down
4 changes: 2 additions & 2 deletions go/vt/vtgate/executor_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func TestExecutorSet(t *testing.T) {
out *vtgatepb.Session
err string
}{{
in: "set autocommit = 1",
out: &vtgatepb.Session{Autocommit: true},
in: "set autocommit = 1, client_found_rows = 1",
out: &vtgatepb.Session{Autocommit: true, Options: &querypb.ExecuteOptions{ClientFoundRows: true}},
}, {
in: "set @@autocommit = true",
out: &vtgatepb.Session{Autocommit: true},
Expand Down

0 comments on commit 808c7b7

Please sign in to comment.