| 2569 | |
| 2570 | |
| 2571 | def finding_export_rows(connection: sqlite3.Connection, scan_id: str) -> sqlite3.Cursor: |
| 2572 | return connection.execute( |
| 2573 | """ |
| 2574 | SELECT |
| 2575 | occurrences.id AS occurrence_id, |
| 2576 | occurrences.finding_id, |
| 2577 | occurrences.title, |
| 2578 | occurrences.summary, |
| 2579 | occurrences.severity, |
| 2580 | occurrences.confidence, |
| 2581 | occurrences.remediation, |
| 2582 | COALESCE(triage.status, 'open') AS status, |
| 2583 | triage.close_reason, |
| 2584 | triage.note, |
| 2585 | locations.relative_path, |
| 2586 | locations.start_line, |
| 2587 | locations.end_line |
| 2588 | FROM finding_occurrences AS occurrences |
| 2589 | LEFT JOIN finding_triage AS triage ON triage.occurrence_id = occurrences.id |
| 2590 | LEFT JOIN finding_locations AS locations |
| 2591 | ON locations.occurrence_id = occurrences.id |
| 2592 | AND locations.sort_order = ( |
| 2593 | SELECT primary_location.sort_order |
| 2594 | FROM finding_locations AS primary_location |
| 2595 | WHERE primary_location.occurrence_id = occurrences.id |
| 2596 | ORDER BY |
| 2597 | CASE WHEN primary_location.role = 'root_control' THEN 0 ELSE 1 END, |
| 2598 | primary_location.sort_order |
| 2599 | LIMIT 1 |
| 2600 | ) |
| 2601 | WHERE occurrences.scan_id = ? |
| 2602 | ORDER BY occurrences.created_at, occurrences.id |
| 2603 | """, |
| 2604 | (scan_id,), |
| 2605 | ) |
| 2606 | |
| 2607 | |
| 2608 | def csv_cell(value: Any) -> Any: |