@@ -416,11 +416,9 @@ func (r *SQLiteRepository) ListHLSAnalyses(ctx context.Context, userID *uuid.UUI
416416 baseQuery := `FROM hls_analyses h JOIN analyses a ON h.analysis_id = a.id`
417417 whereClause := ""
418418 args := []interface {}{}
419- argCount := 0
420419
421420 if userID != nil {
422- argCount ++
423- whereClause = fmt .Sprintf (" WHERE a.user_id = $%d" , argCount )
421+ whereClause = " WHERE a.user_id = ?"
424422 args = append (args , * userID )
425423 }
426424
@@ -431,24 +429,19 @@ func (r *SQLiteRepository) ListHLSAnalyses(ctx context.Context, userID *uuid.UUI
431429 return nil , 0 , err
432430 }
433431
434- // Get paginated results
435- argCount ++
436- limitArg := argCount
437- args = append (args , limit )
438- argCount ++
439- offsetArg := argCount
440- args = append (args , offset )
432+ // Get paginated results - SQLite uses ? placeholders
433+ paginatedArgs := append (args , limit , offset )
441434
442435 query := fmt .Sprintf (`
443436 SELECT h.id, h.analysis_id, h.manifest_path, h.manifest_type, h.manifest_data,
444437 h.segment_count, h.total_duration, h.bitrate_variants, h.segment_duration,
445438 h.playlist_version, h.status, h.processing_time, h.created_at, h.completed_at, h.error_msg
446439 %s %s
447440 ORDER BY h.created_at DESC
448- LIMIT $%d OFFSET $%d
449- ` , baseQuery , whereClause , limitArg , offsetArg )
441+ LIMIT ? OFFSET ?
442+ ` , baseQuery , whereClause )
450443
451- err = r .db .DB .SelectContext (ctx , & analyses , query , args ... )
444+ err = r .db .DB .SelectContext (ctx , & analyses , query , paginatedArgs ... )
452445 if err != nil {
453446 return nil , 0 , err
454447 }
@@ -575,31 +568,26 @@ func (r *SQLiteRepository) ListReports(ctx context.Context, userID *uuid.UUID, a
575568 baseQuery := "FROM reports"
576569 whereConditions := []string {}
577570 args := []interface {}{}
578- argCount := 0
579571
580572 if userID != nil {
581- argCount ++
582- whereConditions = append (whereConditions , fmt .Sprintf ("user_id = $%d" , argCount ))
573+ whereConditions = append (whereConditions , "user_id = ?" )
583574 args = append (args , * userID )
584575 }
585576
586577 if analysisID != "" {
587578 if analysisUUID , err := uuid .Parse (analysisID ); err == nil {
588- argCount ++
589- whereConditions = append (whereConditions , fmt .Sprintf ("analysis_id = $%d" , argCount ))
579+ whereConditions = append (whereConditions , "analysis_id = ?" )
590580 args = append (args , analysisUUID )
591581 }
592582 }
593583
594584 if reportType != "" {
595- argCount ++
596- whereConditions = append (whereConditions , fmt .Sprintf ("report_type = $%d" , argCount ))
585+ whereConditions = append (whereConditions , "report_type = ?" )
597586 args = append (args , reportType )
598587 }
599588
600589 if format != "" {
601- argCount ++
602- whereConditions = append (whereConditions , fmt .Sprintf ("format = $%d" , argCount ))
590+ whereConditions = append (whereConditions , "format = ?" )
603591 args = append (args , format )
604592 }
605593
@@ -615,23 +603,18 @@ func (r *SQLiteRepository) ListReports(ctx context.Context, userID *uuid.UUID, a
615603 return nil , 0 , err
616604 }
617605
618- // Get paginated results
619- argCount ++
620- limitArg := argCount
621- args = append (args , limit )
622- argCount ++
623- offsetArg := argCount
624- args = append (args , offset )
606+ // Get paginated results - SQLite uses ? placeholders
607+ paginatedArgs := append (args , limit , offset )
625608
626609 query := fmt .Sprintf (`
627610 SELECT id, analysis_id, user_id, report_type, format, title, description,
628611 file_path, file_size, download_count, is_public, expires_at, created_at, last_download
629612 %s %s
630613 ORDER BY created_at DESC
631- LIMIT $%d OFFSET $%d
632- ` , baseQuery , whereClause , limitArg , offsetArg )
614+ LIMIT ? OFFSET ?
615+ ` , baseQuery , whereClause )
633616
634- err = r .db .DB .SelectContext (ctx , & reports , query , args ... )
617+ err = r .db .DB .SelectContext (ctx , & reports , query , paginatedArgs ... )
635618 if err != nil {
636619 return nil , 0 , err
637620 }
@@ -701,54 +684,50 @@ func (r *SQLiteRepository) UpdateQualityComparison(ctx context.Context, comparis
701684
702685 _ , err := r .db .DB .ExecContext (
703686 ctx , query ,
704- comparison .ID , comparison . Status , comparison .ResultSummary , comparison .ProcessingTime ,
705- comparison .CompletedAt , comparison .ErrorMsg ,
687+ comparison .Status , comparison .ResultSummary , comparison .ProcessingTime ,
688+ comparison .CompletedAt , comparison .ErrorMsg , comparison . ID ,
706689 )
707690 return err
708691}
709692
710693func (r * SQLiteRepository ) UpdateQualityComparisonStatus (ctx context.Context , id uuid.UUID , status models.AnalysisStatus ) error {
711694 query := "UPDATE quality_comparisons SET status = ?, updated_at = datetime('now') WHERE id = ?"
712- _ , err := r .db .DB .ExecContext (ctx , query , id , status )
695+ _ , err := r .db .DB .ExecContext (ctx , query , status , id )
713696 return err
714697}
715698
716699func (r * SQLiteRepository ) ListQualityComparisons (ctx context.Context , userID * uuid.UUID , referenceID , distortedID , status string , limit , offset int ) ([]* models.QualityComparison , int , error ) {
717700 var comparisons []* models.QualityComparison
718701 var total int
719702
720- baseQuery := `FROM quality_comparisons qc
703+ baseQuery := `FROM quality_comparisons qc
721704 LEFT JOIN analyses ref ON qc.reference_id = ref.id
722705 LEFT JOIN analyses dist ON qc.distorted_id = dist.id`
723706 whereConditions := []string {}
724707 args := []interface {}{}
725- argCount := 0
726708
727709 if userID != nil {
728- argCount ++
729- whereConditions = append (whereConditions , fmt . Sprintf ( "(ref.user_id = $%d OR dist.user_id = $%d)" , argCount , argCount ) )
730- args = append (args , * userID )
710+ // SQLite uses ? placeholders - need to add the same arg twice for OR condition
711+ whereConditions = append (whereConditions , "(ref.user_id = ? OR dist.user_id = ?)" )
712+ args = append (args , * userID , * userID )
731713 }
732714
733715 if referenceID != "" {
734716 if refUUID , err := uuid .Parse (referenceID ); err == nil {
735- argCount ++
736- whereConditions = append (whereConditions , fmt .Sprintf ("qc.reference_id = $%d" , argCount ))
717+ whereConditions = append (whereConditions , "qc.reference_id = ?" )
737718 args = append (args , refUUID )
738719 }
739720 }
740721
741722 if distortedID != "" {
742723 if distUUID , err := uuid .Parse (distortedID ); err == nil {
743- argCount ++
744- whereConditions = append (whereConditions , fmt .Sprintf ("qc.distorted_id = $%d" , argCount ))
724+ whereConditions = append (whereConditions , "qc.distorted_id = ?" )
745725 args = append (args , distUUID )
746726 }
747727 }
748728
749729 if status != "" {
750- argCount ++
751- whereConditions = append (whereConditions , fmt .Sprintf ("qc.status = $%d" , argCount ))
730+ whereConditions = append (whereConditions , "qc.status = ?" )
752731 args = append (args , status )
753732 }
754733
@@ -764,23 +743,18 @@ func (r *SQLiteRepository) ListQualityComparisons(ctx context.Context, userID *u
764743 return nil , 0 , err
765744 }
766745
767- // Get paginated results
768- argCount ++
769- limitArg := argCount
770- args = append (args , limit )
771- argCount ++
772- offsetArg := argCount
773- args = append (args , offset )
746+ // Get paginated results - SQLite uses ? placeholders
747+ paginatedArgs := append (args , limit , offset )
774748
775749 query := fmt .Sprintf (`
776750 SELECT qc.id, qc.reference_id, qc.distorted_id, qc.comparison_type, qc.status,
777751 qc.result_summary, qc.processing_time, qc.created_at, qc.completed_at, qc.error_msg
778752 %s %s
779753 ORDER BY qc.created_at DESC
780- LIMIT $%d OFFSET $%d
781- ` , baseQuery , whereClause , limitArg , offsetArg )
754+ LIMIT ? OFFSET ?
755+ ` , baseQuery , whereClause )
782756
783- err = r .db .DB .SelectContext (ctx , & comparisons , query , args ... )
757+ err = r .db .DB .SelectContext (ctx , & comparisons , query , paginatedArgs ... )
784758 if err != nil {
785759 return nil , 0 , err
786760 }
0 commit comments