Skip to content

Commit

Permalink
intercept use statements
Browse files Browse the repository at this point in the history
  • Loading branch information
demmer committed Nov 3, 2023
1 parent 4d29ed1 commit 82258ab
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions go/vt/vtgateproxy/vtgateproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ import (
"context"
"flag"
"io"
"strings"
"sync"
"time"

"google.golang.org/grpc"
"vitess.io/vitess/go/sqlescape"
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/vt/grpcclient"
querypb "vitess.io/vitess/go/vt/proto/query"
Expand Down Expand Up @@ -117,6 +119,14 @@ func (proxy *VTGateProxy) Prepare(ctx context.Context, session *vtgateconn.VTGat
}

func (proxy *VTGateProxy) Execute(ctx context.Context, session *vtgateconn.VTGateSession, sql string, bindVariables map[string]*querypb.BindVariable) (qr *sqltypes.Result, err error) {

// Intercept "use" statements since they just have to update the local session
if strings.HasPrefix(sql, "use ") {
targetString := sqlescape.UnescapeID(sql[4:])
session.SessionPb().TargetString = targetString
return &sqltypes.Result{}, nil
}

return session.Execute(ctx, sql, bindVariables)
}

Expand Down

0 comments on commit 82258ab

Please sign in to comment.