<commit_before>(*
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *)

open! IStd
module F = Format
module L = Logging

let get_all ~filter () =
  let db = ResultsDatabase.get_database () in
  let stmt = Sqlite3.prepare db "SELECT proc_attributes FROM procedures" in
  SqliteUtils.result_fold_rows db ~log:"reading all procedure names" stmt ~init:[]
    ~f:(fun rev_results stmt ->
      let attrs = Sqlite3.column stmt 1 |> ProcAttributes.SQLite.deserialize in
      let source_file = attrs.ProcAttributes.translation_unit in
      let proc_name = ProcAttributes.get_proc_name attrs in
      if filter source_file proc_name then proc_name :: rev_results else rev_results )


let select_proc_names_interactive ~filter =
  let proc_names = get_all ~filter () |> List.rev in
  let proc_names_len = List.length proc_names in
  match (proc_names, Config.select) with
  | [], _ ->
      F.eprintf "No procedures found" ;
      None
  | _, Some (`Select n) when n >= proc_names_len ->
      L.die UserError "Cannot select result #%d out of only %d procedures" n proc_names_len
  | [proc_name], _ ->
      F.eprintf "Selected proc name: %a@." Procname.pp proc_name ;
      Some proc_names
  | _, Some `All ->
      Some proc_names
  | _, Some (`Select n) ->
      let proc_names_array = List.to_array proc_names in
      Some [proc_names_array.(n)]
  | _, None ->
      let proc_names_array = List.to_array proc_names in
      Array.iteri proc_names_array ~f:(fun i proc_name ->
          F.eprintf "%d: %a@\n" i Procname.pp proc_name ) ;
      let rec ask_user_input () =<commit_msg>[sqlite] Fix column number used in Procedures.get_all<commit_after>(*
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *)

open! IStd
module F = Format
module L = Logging

let get_all ~filter () =
  let db = ResultsDatabase.get_database () in
  let stmt = Sqlite3.prepare db "SELECT proc_attributes FROM procedures" in
  SqliteUtils.result_fold_rows db ~log:"reading all procedure names" stmt ~init:[]
    ~f:(fun rev_results stmt ->
      let attrs = Sqlite3.column stmt 0 |> ProcAttributes.SQLite.deserialize in
      let source_file = attrs.ProcAttributes.translation_unit in
      let proc_name = ProcAttributes.get_proc_name attrs in
      if filter source_file proc_name then proc_name :: rev_results else rev_results )


let select_proc_names_interactive ~filter =
  let proc_names = get_all ~filter () |> List.rev in
  let proc_names_len = List.length proc_names in
  match (proc_names, Config.select) with
  | [], _ ->
      F.eprintf "No procedures found" ;
      None
  | _, Some (`Select n) when n >= proc_names_len ->
      L.die UserError "Cannot select result #%d out of only %d procedures" n proc_names_len
  | [proc_name], _ ->
      F.eprintf "Selected proc name: %a@." Procname.pp proc_name ;
      Some proc_names
  | _, Some `All ->
      Some proc_names
  | _, Some (`Select n) ->
      let proc_names_array = List.to_array proc_names in
      Some [proc_names_array.(n)]
  | _, None ->
      let proc_names_array = List.to_array proc_names in
      Array.iteri proc_names_array ~f:(fun i proc_name ->
          F.eprintf "%d: %a@\n" i Procname.pp proc_name ) ;
      let rec ask_user_input () =
{'fraction_non_alphanumeric': 0.09335260115606936, 'fraction_numerical': 0.0017341040462427746, 'mean_word_length': 3.2834158415841586, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1532470', 'n_tokens_mistral': 1116, 'n_tokens_neox': 1092, 'n_words': 360}