forked from sqlc-dev/sqlc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparam_ref.go
More file actions
37 lines (31 loc) · 796 Bytes
/
param_ref.go
File metadata and controls
37 lines (31 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
}