Skip to content

Commit 4324b1c

Browse files
Ajit Pratap Singhclaude
authored andcommitted
fix: populate Query field in AnalysisReport to fix test failures
Fixed TestSQLAnalyzer_MixedStatements by implementing buildQueryInfo() method that populates the Query field with: - StatementCount: number of SQL statements in AST - StatementTypes: types of statements (SELECT, INSERT, UPDATE, etc.) This was a pre-existing bug where the Query field was never populated in the AnalysisReport, causing StatementCount to always be 0. Fixes all build failures across Go 1.19, 1.20, and 1.21. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0f76c1b commit 4324b1c

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

cmd/gosqlx/cmd/sql_analyzer.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,13 @@ func (a *SQLAnalyzer) Analyze(astObj *ast.AST) (*AnalysisReport, error) {
6464
securityScore := a.calculateSecurityScore()
6565
overallScore := a.calculateOverallScore()
6666

67+
// Build query metadata
68+
queryInfo := a.buildQueryInfo(astObj)
69+
6770
return &AnalysisReport{
6871
Timestamp: time.Now(),
6972
Version: "2.0.0-unified",
73+
Query: queryInfo,
7074
Issues: a.Issues,
7175
ComplexityMetrics: a.ComplexityMetrics,
7276
SecurityScore: securityScore,
@@ -471,6 +475,37 @@ func (a *SQLAnalyzer) generateRecommendations() []string {
471475
return recommendations
472476
}
473477

478+
// buildQueryInfo constructs query metadata from the AST
479+
func (a *SQLAnalyzer) buildQueryInfo(astObj *ast.AST) QueryInfo {
480+
stmtTypes := make([]string, 0, len(astObj.Statements))
481+
482+
for _, stmt := range astObj.Statements {
483+
switch stmt.(type) {
484+
case *ast.SelectStatement:
485+
stmtTypes = append(stmtTypes, "SELECT")
486+
case *ast.InsertStatement:
487+
stmtTypes = append(stmtTypes, "INSERT")
488+
case *ast.UpdateStatement:
489+
stmtTypes = append(stmtTypes, "UPDATE")
490+
case *ast.DeleteStatement:
491+
stmtTypes = append(stmtTypes, "DELETE")
492+
case *ast.CreateTableStatement:
493+
stmtTypes = append(stmtTypes, "CREATE TABLE")
494+
case *ast.CreateIndexStatement:
495+
stmtTypes = append(stmtTypes, "CREATE INDEX")
496+
case *ast.AlterTableStatement:
497+
stmtTypes = append(stmtTypes, "ALTER TABLE")
498+
default:
499+
stmtTypes = append(stmtTypes, "OTHER")
500+
}
501+
}
502+
503+
return QueryInfo{
504+
StatementCount: len(astObj.Statements),
505+
StatementTypes: stmtTypes,
506+
}
507+
}
508+
474509
// reset resets analyzer state for new analysis
475510
func (a *SQLAnalyzer) reset() {
476511
a.Issues = a.Issues[:0]

0 commit comments

Comments
 (0)