@@ -12,7 +12,6 @@ import (
12
12
"github.com/sqlc-dev/sqlc/internal/source"
13
13
"github.com/sqlc-dev/sqlc/internal/sql/ast"
14
14
"github.com/sqlc-dev/sqlc/internal/sql/astutils"
15
- "github.com/sqlc-dev/sqlc/internal/sql/named"
16
15
"github.com/sqlc-dev/sqlc/internal/sql/validate"
17
16
)
18
17
@@ -52,43 +51,36 @@ func (c *Compiler) parseQuery(stmt ast.Node, src string, o opts.Parser) (*Query,
52
51
return nil , err
53
52
}
54
53
55
- var analysis * analysis
54
+ var anlys * analysis
56
55
if c .analyzer != nil {
57
- // We expect inference to fail sometimes
58
56
// TODO: Handle panics
59
57
inference , _ := c .inferQuery (raw , rawSQL )
60
-
61
- query := rawSQL
62
- var ps * named.ParamSet
63
- if inference != nil {
64
- if inference .Query != "" {
65
- query = inference .Query
66
- }
67
- if inference .Named != nil {
68
- ps = inference .Named
69
- }
58
+ if inference == nil {
59
+ inference = & analysis {}
60
+ }
61
+ if inference .Query == "" {
62
+ inference .Query = rawSQL
70
63
}
71
64
72
- result , err := c .analyzer .Analyze (ctx , raw , query , c .schema , ps )
65
+ result , err := c .analyzer .Analyze (ctx , raw , inference . Query , c .schema , inference . Named )
73
66
if err != nil {
74
67
return nil , err
75
68
}
76
69
77
- // FOOTGUN: Careful, combine mutates inference
78
- analysis = combineAnalysis (inference , result )
70
+ // FOOTGUN: combineAnalysis mutates inference
71
+ anlys = combineAnalysis (inference , result )
79
72
} else {
80
- analysis , err = c .analyzeQuery (raw , rawSQL )
73
+ anlys , err = c .analyzeQuery (raw , rawSQL )
81
74
if err != nil {
82
75
return nil , err
83
76
}
84
77
}
85
78
86
- expanded := analysis .Query
79
+ expanded := anlys .Query
87
80
88
81
// If the query string was edited, make sure the syntax is valid
89
82
if expanded != rawSQL {
90
83
if _ , err := c .parser .Parse (strings .NewReader (expanded )); err != nil {
91
- fmt .Println (expanded )
92
84
return nil , fmt .Errorf ("edited query syntax is invalid: %w" , err )
93
85
}
94
86
}
@@ -109,10 +101,10 @@ func (c *Compiler) parseQuery(stmt ast.Node, src string, o opts.Parser) (*Query,
109
101
Comments : comments ,
110
102
Name : name ,
111
103
Flags : flags ,
112
- Params : analysis .Parameters ,
113
- Columns : analysis .Columns ,
104
+ Params : anlys .Parameters ,
105
+ Columns : anlys .Columns ,
114
106
SQL : trimmed ,
115
- InsertIntoTable : analysis .Table ,
107
+ InsertIntoTable : anlys .Table ,
116
108
}, nil
117
109
}
118
110
0 commit comments