Skip to content

Commit

Permalink
fix usage of invalid SQL queries
Browse files Browse the repository at this point in the history
  • Loading branch information
neoaggelos committed Feb 20, 2024
1 parent fb7236b commit 65b361d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pkg/kine/drivers/generic/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ type Generic struct {
ListRevisionStartSQL string
GetRevisionAfterSQL string
CountCurrentSQL string
countCurrentSQLPrepared *sql.Stmt
CountRevisionSQL string
countSQLPrepared *sql.Stmt
countRevisionSQLPrepared *sql.Stmt
AfterSQLPrefix string
afterSQLPrefixPrepared *sql.Stmt
AfterSQL string
Expand Down Expand Up @@ -260,7 +261,12 @@ func (d *Generic) Prepare() error {
return err
}

d.countSQLPrepared, err = d.DB.Prepare(d.CountCurrentSQL)
d.countCurrentSQLPrepared, err = d.DB.Prepare(d.CountCurrentSQL)
if err != nil {
return err
}

d.countRevisionSQLPrepared, err = d.DB.Prepare(d.CountRevisionSQL)
if err != nil {
return err
}
Expand Down Expand Up @@ -376,7 +382,7 @@ func (d *Generic) CountCurrent(ctx context.Context, prefix string) (int64, int64
id int64
)

row := d.queryRow(ctx, d.CountCurrentSQL, prefix, false)
row := d.queryRowPrepared(ctx, "count_current", d.CountCurrentSQL, d.countCurrentSQLPrepared, prefix, false)
err := row.Scan(&rev, &id)
return rev.Int64, id, err
}
Expand All @@ -387,7 +393,7 @@ func (d *Generic) Count(ctx context.Context, prefix string, revision int64) (int
id int64
)

row := d.queryRow(ctx, d.CountRevisionSQL, prefix, revision, false)
row := d.queryRowPrepared(ctx, "count_revision", d.CountRevisionSQL, d.countRevisionSQLPrepared, prefix, revision, false)
err := row.Scan(&rev, &id)
return rev.Int64, id, err
}
Expand Down

0 comments on commit 65b361d

Please sign in to comment.