MCPcopy Index your code
hub / github.com/sqlc-dev/sqlc / GetColumnNames

Method GetColumnNames

internal/engine/sqlite/analyzer/analyze.go:236–257  ·  view source on GitHub ↗

GetColumnNames implements the expander.ColumnGetter interface. It prepares a query and returns the column names from the result set description.

(ctx context.Context, query string)

Source from the content-addressed store, hash-verified

234// GetColumnNames implements the expander.ColumnGetter interface.
235// It prepares a query and returns the column names from the result set description.
236func (a *Analyzer) GetColumnNames(ctx context.Context, query string) ([]string, error) {
237 a.mu.Lock()
238 defer a.mu.Unlock()
239
240 if a.conn == nil {
241 return nil, fmt.Errorf("database connection not initialized")
242 }
243
244 stmt, _, err := a.conn.Prepare(query)
245 if err != nil {
246 return nil, err
247 }
248 defer stmt.Close()
249
250 colCount := stmt.ColumnCount()
251 columns := make([]string, colCount)
252 for i := 0; i < colCount; i++ {
253 columns[i] = stmt.ColumnName(i)
254 }
255
256 return columns, nil
257}
258
259// IntrospectSchema queries the database to build a catalog containing
260// tables and columns for the database.

Callers

nothing calls this directly

Implementers 3

CachedAnalyzerinternal/analyzer/analyzer.go
Analyzerinternal/engine/postgresql/analyzer/an
Analyzerinternal/engine/sqlite/analyzer/analyz

Calls 2

PrepareMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected