-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathfunc_call.go
More file actions
76 lines (67 loc) · 1.7 KB
/
Copy pathfunc_call.go
File metadata and controls
76 lines (67 loc) · 1.7 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package validate
import (
"errors"
"github.com/sqlc-dev/sqlc/internal/config"
"github.com/sqlc-dev/sqlc/internal/sql/ast"
"github.com/sqlc-dev/sqlc/internal/sql/astutils"
"github.com/sqlc-dev/sqlc/internal/sql/catalog"
"github.com/sqlc-dev/sqlc/internal/sql/sqlerr"
)
type funcCallVisitor struct {
catalog *catalog.Catalog
settings config.CombinedSettings
err error
}
func (v *funcCallVisitor) Visit(node ast.Node) astutils.Visitor {
if v.err != nil {
return nil
}
// PostgreSQL CALL: resolve against all callable parameters (IN + OUT)
// because CALL requires placeholder values for OUT parameters in their
// declared positions. Returning nil here prevents Walk from descending
// into the inner FuncCall, which would otherwise be re-validated using
// the stricter IN-only matching path.
if cs, ok := node.(*ast.CallStmt); ok {
if cs.FuncCall == nil {
return nil
}
fn := cs.FuncCall.Func
if fn == nil || fn.Schema == "sqlc" {
return nil
}
fun, err := v.catalog.ResolveCallStmt(cs.FuncCall)
if fun != nil {
return nil
}
if errors.Is(err, sqlerr.NotFound) && !v.settings.Package.StrictFunctionChecks {
return nil
}
v.err = err
return nil
}
call, ok := node.(*ast.FuncCall)
if !ok {
return v
}
fn := call.Func
if fn == nil {
return v
}
if fn.Schema == "sqlc" {
return nil
}
fun, err := v.catalog.ResolveFuncCall(call)
if fun != nil {
return v
}
if errors.Is(err, sqlerr.NotFound) && !v.settings.Package.StrictFunctionChecks {
return v
}
v.err = err
return nil
}
func FuncCall(c *catalog.Catalog, cs config.CombinedSettings, n ast.Node) error {
visitor := funcCallVisitor{catalog: c, settings: cs}
astutils.Walk(&visitor, n)
return visitor.err
}