github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/error_if_rows.go (about) 1 // Copyright 2019 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package sql 12 13 import ( 14 "context" 15 16 "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" 17 ) 18 19 // errorIfRowsNode wraps another planNode and returns an error if the wrapped 20 // node produces any rows. 21 type errorIfRowsNode struct { 22 plan planNode 23 24 // mkErr creates the error message, given the values of the first row 25 // produced. 26 mkErr func(values tree.Datums) error 27 28 nexted bool 29 } 30 31 func (n *errorIfRowsNode) startExec(params runParams) error { 32 return nil 33 } 34 35 func (n *errorIfRowsNode) Next(params runParams) (bool, error) { 36 if n.nexted { 37 return false, nil 38 } 39 n.nexted = true 40 41 ok, err := n.plan.Next(params) 42 if err != nil { 43 return false, err 44 } 45 if ok { 46 return false, n.mkErr(n.plan.Values()) 47 } 48 return false, nil 49 } 50 51 func (n *errorIfRowsNode) Values() tree.Datums { 52 return nil 53 } 54 55 func (n *errorIfRowsNode) Close(ctx context.Context) { 56 n.plan.Close(ctx) 57 }