diff --git a/go/vt/vterrors/code.go b/go/vt/vterrors/code.go index e095bb4e885..9bfb7747c09 100644 --- a/go/vt/vterrors/code.go +++ b/go/vt/vterrors/code.go @@ -48,6 +48,7 @@ var ( VT03023 = errorWithoutState("VT03023", vtrpcpb.Code_INVALID_ARGUMENT, "INSERT not supported when targeting a key range: %s", "When targeting a range of shards, Vitess does not know which shard to send the INSERT to.") VT03024 = errorWithoutState("VT03024", vtrpcpb.Code_INVALID_ARGUMENT, "'%s' user defined variable does not exists", "The query cannot be prepared using the user defined variable as it does not exists for this session.") VT03025 = errorWithState("VT03025", vtrpcpb.Code_INVALID_ARGUMENT, WrongArguments, "Incorrect arguments to %s", "The execute statement have wrong number of arguments") + VT03026 = errorWithoutState("VT03024", vtrpcpb.Code_INVALID_ARGUMENT, "'%s' bind variable does not exists", "The query cannot be executed as missing the bind variable.") VT05001 = errorWithState("VT05001", vtrpcpb.Code_NOT_FOUND, DbDropExists, "cannot drop database '%s'; database does not exists", "The given database does not exist; Vitess cannot drop it.") VT05002 = errorWithState("VT05002", vtrpcpb.Code_NOT_FOUND, BadDb, "cannot alter database '%s'; unknown database", "The given database does not exist; Vitess cannot alter it.") @@ -121,6 +122,7 @@ var ( VT03023, VT03024, VT03025, + VT03026, VT05001, VT05002, VT05003, diff --git a/go/vt/vtgate/engine/insert.go b/go/vt/vtgate/engine/insert.go index cbe2dfc9eb8..c3021cb46a0 100644 --- a/go/vt/vtgate/engine/insert.go +++ b/go/vt/vtgate/engine/insert.go @@ -766,12 +766,19 @@ func (ins *Insert) getInsertShardedRoute( if keyspaceIDs[index] != nil { mids = append(mids, sqlparser.String(ins.Mid[index])) for _, expr := range ins.Mid[index] { - _ = sqlparser.Walk(func(node sqlparser.SQLNode) (kontinue bool, err error) { + err = sqlparser.Walk(func(node sqlparser.SQLNode) (kontinue bool, err error) { if arg, ok := node.(*sqlparser.Argument); ok { - shardBindVars[arg.Name] = bindVars[arg.Name] + bv, exists := bindVars[arg.Name] + if !exists { + return false, vterrors.VT03026(arg.Name) + } + shardBindVars[arg.Name] = bv } return true, nil }, expr, nil) + if err != nil { + return nil, nil, err + } } } }