@@ -12,7 +12,6 @@ import (
1212 "github.com/sqlc-dev/sqlc/internal/source"
1313 "github.com/sqlc-dev/sqlc/internal/sql/ast"
1414 "github.com/sqlc-dev/sqlc/internal/sql/astutils"
15- "github.com/sqlc-dev/sqlc/internal/sql/named"
1615 "github.com/sqlc-dev/sqlc/internal/sql/validate"
1716)
1817
@@ -52,43 +51,36 @@ func (c *Compiler) parseQuery(stmt ast.Node, src string, o opts.Parser) (*Query,
5251 return nil , err
5352 }
5453
55- var analysis * analysis
54+ var anlys * analysis
5655 if c .analyzer != nil {
57- // We expect inference to fail sometimes
5856 // TODO: Handle panics
5957 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
7063 }
7164
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 )
7366 if err != nil {
7467 return nil , err
7568 }
7669
77- // FOOTGUN: Careful, combine mutates inference
78- analysis = combineAnalysis (inference , result )
70+ // FOOTGUN: combineAnalysis mutates inference
71+ anlys = combineAnalysis (inference , result )
7972 } else {
80- analysis , err = c .analyzeQuery (raw , rawSQL )
73+ anlys , err = c .analyzeQuery (raw , rawSQL )
8174 if err != nil {
8275 return nil , err
8376 }
8477 }
8578
86- expanded := analysis .Query
79+ expanded := anlys .Query
8780
8881 // If the query string was edited, make sure the syntax is valid
8982 if expanded != rawSQL {
9083 if _ , err := c .parser .Parse (strings .NewReader (expanded )); err != nil {
91- fmt .Println (expanded )
9284 return nil , fmt .Errorf ("edited query syntax is invalid: %w" , err )
9385 }
9486 }
@@ -109,10 +101,10 @@ func (c *Compiler) parseQuery(stmt ast.Node, src string, o opts.Parser) (*Query,
109101 Comments : comments ,
110102 Name : name ,
111103 Flags : flags ,
112- Params : analysis .Parameters ,
113- Columns : analysis .Columns ,
104+ Params : anlys .Parameters ,
105+ Columns : anlys .Columns ,
114106 SQL : trimmed ,
115- InsertIntoTable : analysis .Table ,
107+ InsertIntoTable : anlys .Table ,
116108 }, nil
117109}
118110
0 commit comments