(* * implementazione dei comandi USE/USED BY *) open Utility;; open Dbconn;; (* * implementazione dei comandi USE/USED BY * * parametri: * alist: string list list; lista su cui eseguire il comando USE/USED BY * asvar: string; nome della variabile del comando use * usek: string; nome della tabella in cui ricercare le occorrenze; * la distinzione fra l'esecuzione del comando USE e USED BY * sta nell'utilizzo della tabella 'backPointer' per USE * e 'refObj' per USED BY * * output: string list list; lista su cui e' stato eseguito il * comando USE/USED BY * * TODO * USE e USED BY sono identici dal punto di vista algoritmico, per questo * sono stati accorpati in una sola funzione; stilisticamente, sarebbe meglio * avere due implementazioni distinte... *) let use_ex alist asvar usek = let c = pgc () in List.fold_left (fun parziale xres -> let r1 = pgresult_to_string (c#exec ("select att0 from property where att2='" ^ usek ^ "'")) and r2 = pgresult_to_string (c#exec "select att0 from property where att2='position'") and r3 = pgresult_to_string (c#exec "select att0 from property where att2='occurrence'") in let res = c#exec ( "select distinct t" ^ r3 ^ ".att1, t" ^ r2 ^ ".att1 " ^ "from t" ^ r3 ^ ", t" ^ r2 ^ ", t" ^ r1 ^ " " ^ "where " ^ "t" ^ r1 ^ ".att0 = '" ^ (List.hd xres) ^ "' and t" ^ r1 ^ ".att1 = t" ^ r2 ^ ".att0 and t" ^ r1 ^ ".att1 = t" ^ r3 ^ ".att0") in parziale @ if not (List.mem asvar (List.tl (List.hd alist))) then List.map (fun l -> [List.hd l] @ List.tl xres @ List.tl l) res#get_list else List.map (fun l -> let t = match xres with hd::tl -> (List.hd l)::tl | [] -> [] in List.map snd (Utility.set_assoc asvar (List.hd (List.tl l)) (List.combine (List.hd alist) t) ) ) (List.find_all (fun l -> let currv = List.hd (List.tl l) and xresv = try ( List.assoc asvar (List.combine (List.tl (List.hd alist)) (List.tl xres) ) ) with Not_found -> "" in xresv = "" or xresv = currv ) res#get_list ) ) [ (List.hd alist) @ if not (List.mem asvar (List.tl (List.hd alist))) then [asvar] else [] ] (List.tl alist) ;; (** TEST **) (* let use_ex alist asvar = if (List.find_all asvar (List.tl (List.hd alist))) = [] then use_ex_nc alist asvar else use_ex_co alist asvar ;; List.map (fun l -> let t = match xres with hd::tl -> (List.hd l)::tl | [] -> [] in let hash = List.combine (List.hd alist) t in snd (set_assoc asvar (snd l) hash) ) (List.find_all (fun l -> let currv = List.hd (List.tl l) and xresv = try ( List.assoc asvar (List.combine (List.tl (List.hd alist)) (List.tl xres)) ) with Not_found -> "" in xresv = "" or xresv = currv ) res#get_list ) ;; *)