12345678910111213141516171819202122232425262728293031323334353637 |
- package validate
- import (
- "fmt"
- "github.com/kyleconroy/sqlc/internal/sql/ast"
- "github.com/kyleconroy/sqlc/internal/sql/ast/pg"
- "github.com/kyleconroy/sqlc/internal/sql/astutils"
- "github.com/kyleconroy/sqlc/internal/sql/sqlerr"
- )
- func ParamRef(n ast.Node) error {
- var allrefs []*pg.ParamRef
- // Find all parameter references
- astutils.Walk(astutils.VisitorFunc(func(node ast.Node) {
- switch n := node.(type) {
- case *pg.ParamRef:
- allrefs = append(allrefs, n)
- }
- }), n)
- seen := map[int]struct{}{}
- for _, r := range allrefs {
- seen[r.Number] = struct{}{}
- }
- for i := 1; i <= len(seen); i += 1 {
- if _, ok := seen[i]; !ok {
- return &sqlerr.Error{
- Code: "42P18",
- Message: fmt.Sprintf("could not determine data type of parameter $%d", i),
- }
- }
- }
- return nil
- }
|