Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make sure to add necessary bindvars when preparing queries #7493

Merged
merged 1 commit into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 16 additions & 0 deletions go/test/endtoend/preparestmt/stmt_methods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ func TestSelect(t *testing.T) {
selectWhere(t, dbo, "")
}

func TestSelectDatabase(t *testing.T) {
defer cluster.PanicHandler(t)
dbo := Connect(t)
defer dbo.Close()
prepare, err := dbo.Prepare("select database()")
require.NoError(t, err)
rows, err := prepare.Query()
require.NoError(t, err)
defer rows.Close()
var resultBytes sql.RawBytes
require.True(t, rows.Next(), "no rows found")
err = rows.Scan(&resultBytes)
require.NoError(t, err)
assert.Equal(t, string(resultBytes), "test_keyspace")
}

// TestInsertUpdateDelete validates all insert, update and
// delete method on prepared statements.
func TestInsertUpdateDelete(t *testing.T) {
Expand Down
6 changes: 6 additions & 0 deletions go/vt/vtgate/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,12 @@ func (e *Executor) handlePrepare(ctx context.Context, safeSession *SafeSession,
return nil, err
}

err = e.addNeededBindVars(plan.BindVarNeeds, bindVars, safeSession)
if err != nil {
logStats.Error = err
return nil, err
}

qr, err := plan.Instructions.GetFields(vcursor, bindVars)
logStats.ExecuteTime = time.Since(execStart)
var errCount uint64
Expand Down
11 changes: 11 additions & 0 deletions go/vt/vtgate/executor_select_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2178,6 +2178,17 @@ func TestSelectBindvarswithPrepare(t *testing.T) {
}
}

func TestSelectDatabasePrepare(t *testing.T) {
executor, _, _, _ := createExecutorEnv()
executor.normalize = true
logChan := QueryLogger.Subscribe("Test")
defer QueryLogger.Unsubscribe(logChan)

sql := "select database()"
_, err := executorPrepare(executor, sql, map[string]*querypb.BindVariable{})
require.NoError(t, err)
}

Comment on lines +2187 to +2191
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could assert that the bindvars were added.

func TestSelectWithUnionAll(t *testing.T) {
executor, sbc1, sbc2, _ := createLegacyExecutorEnv()
executor.normalize = true
Expand Down