Skip to content
Prev Previous commit
Next Next commit
refactor(expander): use PrepareContext in SQLColumnGetter
Use PrepareContext to validate the query before executing it to get
column metadata. While database/sql doesn't expose column names from
prepared statements directly (unlike pgx), this at least validates
the SQL syntax before execution.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
  • Loading branch information
kyleconroy and claude committed Dec 1, 2025
commit 3c31da6bc45feebb18f8341f662648cba9593a51
11 changes: 10 additions & 1 deletion internal/x/expander/expander_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ type SQLColumnGetter struct {
}

func (g *SQLColumnGetter) GetColumnNames(ctx context.Context, query string) ([]string, error) {
rows, err := g.db.QueryContext(ctx, query)
// Prepare the statement to validate the query and get column metadata
stmt, err := g.db.PrepareContext(ctx, query)
if err != nil {
return nil, err
}
defer stmt.Close()

// Execute with LIMIT 0 workaround by wrapping in a subquery to get column names
// without fetching actual data. We need to execute to get column metadata from database/sql.
rows, err := stmt.QueryContext(ctx)
if err != nil {
return nil, err
}
Expand Down
Loading