@@ -34,6 +34,17 @@ var ErrFailedChecks = errors.New("failed checks")
3434const RuleDbPrepare = "sqlc/db-prepare"
3535const QueryFlagSqlcVetDisable = "@sqlc-vet-disable"
3636
37+ type emptyProgram struct {
38+ }
39+
40+ func (e * emptyProgram ) Eval (any ) (ref.Val , * cel.EvalDetails , error ) {
41+ return nil , nil , fmt .Errorf ("unimplemented" )
42+ }
43+
44+ func (e * emptyProgram ) ContextEval (ctx context.Context , a any ) (ref.Val , * cel.EvalDetails , error ) {
45+ return e .Eval (a )
46+ }
47+
3748func NewCmdVet () * cobra.Command {
3849 return & cobra.Command {
3950 Use : "vet" ,
@@ -53,17 +64,6 @@ func NewCmdVet() *cobra.Command {
5364 }
5465}
5566
56- type emptyProgram struct {
57- }
58-
59- func (e * emptyProgram ) Eval (any ) (ref.Val , * cel.EvalDetails , error ) {
60- return nil , nil , fmt .Errorf ("unimplemented" )
61- }
62-
63- func (e * emptyProgram ) ContextEval (ctx context.Context , a any ) (ref.Val , * cel.EvalDetails , error ) {
64- return e .Eval (a )
65- }
66-
6767func Vet (ctx context.Context , e Env , dir , filename string , stderr io.Writer ) error {
6868 configPath , conf , err := readConfig (stderr , dir , filename )
6969 if err != nil {
@@ -100,7 +100,7 @@ func Vet(ctx context.Context, e Env, dir, filename string, stderr io.Writer) err
100100 }
101101
102102 checks := map [string ]cel.Program {
103- RuleDbPrepare : & emptyProgram {},
103+ RuleDbPrepare : & emptyProgram {}, // Keep this to trigger the name conflict error below
104104 }
105105 msgs := map [string ]string {}
106106
@@ -198,7 +198,8 @@ type dbPreparer struct {
198198}
199199
200200func (p * dbPreparer ) Prepare (ctx context.Context , name , query string ) error {
201- _ , err := p .db .PrepareContext (ctx , query )
201+ s , err := p .db .PrepareContext (ctx , query )
202+ s .Close ()
202203 return err
203204}
204205
@@ -316,12 +317,15 @@ func (c *checker) checkSQL(ctx context.Context, s config.SQL) error {
316317 continue
317318 }
318319 original := result .Queries [i ]
319- if prepareable (s , original .RawStmt ) {
320- name := fmt .Sprintf ("sqlc_vet_%d_%d" , time .Now ().Unix (), i )
321- if err := prep .Prepare (ctx , name , query .Text ); err != nil {
322- fmt .Fprintf (c .Stderr , "%s: %s: %s: error preparing query: %s\n " , query .Filename , q .Name , name , err )
323- errored = true
324- }
320+ if ! prepareable (s , original .RawStmt ) {
321+ fmt .Fprintf (c .Stderr , "%s: %s: %s: error preparing query: %s\n " , query .Filename , q .Name , name , "query type is unpreparable" )
322+ errored = true
323+ continue
324+ }
325+ name := fmt .Sprintf ("sqlc_vet_%d_%d" , time .Now ().Unix (), i )
326+ if err := prep .Prepare (ctx , name , query .Text ); err != nil {
327+ fmt .Fprintf (c .Stderr , "%s: %s: %s: error preparing query: %s\n " , query .Filename , q .Name , name , err )
328+ errored = true
325329 }
326330 continue
327331 }
0 commit comments