X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;ds=inline;f=helm%2Focaml%2Fmathql_interpreter%2FmQIProperty.ml;h=1e634d7c11c03c8312192f8047829dc0305bed93;hb=da16c76907f567b9aa4d3d026f6ab309006b3d86;hp=be559adc7f107bb7dda849d4ebb7a4480c252bde;hpb=1c7fb836e2af4f2f3d18afd0396701f2094265ff;p=helm.git diff --git a/helm/ocaml/mathql_interpreter/mQIProperty.ml b/helm/ocaml/mathql_interpreter/mQIProperty.ml index be559adc7..1e634d7c1 100644 --- a/helm/ocaml/mathql_interpreter/mQIProperty.ml +++ b/helm/ocaml/mathql_interpreter/mQIProperty.ml @@ -27,9 +27,10 @@ *) module M = MathQL +module I = M.I +module U = AvsUtil module P = MQIPostgres module C = MQIConn -module U = MQIUtil module A = MQIMap let not_supported s = @@ -65,15 +66,22 @@ let pg_query h table cols ct cfl = | [head] -> f head | head :: tail -> f head ^ sep ^ iter f sep tail in + let avs_iter f sep v = + let aux a s = function + | true -> a ^ (f s) ^ sep + | false -> a ^ (f s) + in + I.iter aux "" v + in let pg_cols = iter (fun x -> x) ", " cols in - let pg_msval v = iter P.quote ", " v in + let pg_msval v = avs_iter P.quote ", " v in let pg_con (pat, col, v) = if col <> "" then let f s = col ^ " ~ " ^ P.quote ("^" ^ s ^ "$") in - if pat then "(" ^ iter f " or " v ^ ")" - else match v with - | [s] -> col ^ " = " ^ (P.quote s) - | v -> col ^ " in (" ^ pg_msval v ^ ")" + if pat then "(" ^ avs_iter f " or " v ^ ")" + else match I.single v with + | Some s -> col ^ " = " ^ (P.quote s) + | None -> col ^ " in (" ^ pg_msval v ^ ")" else "true" in let pg_cons l = iter pg_con " and " l in @@ -92,7 +100,7 @@ let pg_query h table cols ct cfl = | _ -> [] else exec ("select " ^ pg_cols ^ " from " ^ table ^ pg_where ^ - " order by " ^ List.hd cols ^ " asc") + " order by " ^ List.hd cols ^ " asc") (* desc *) (* Galax backend ***********************************************************) @@ -100,18 +108,15 @@ let gx_query h table cols ct cfl = not_supported "Galax" (* Common functions ********************************************************) -let pg_result distinct subj el res = - let compose = if distinct then List.map else fun f -> U.mql_iter (fun x -> [f x]) in +let pg_result subj el res = let get_name = function (p, None) -> p | (_, Some p) -> p in let names = List.map get_name el in - let mk_grp l = - let grp = U.mql_iter2 (fun p s -> [(p, [s])]) names l in - if grp = [] then [] else [grp] - in - let mk_avs l = - if subj = "" then ("", mk_grp l) else (List.hd l, mk_grp (List.tl l)) + let mk_grp l = U.grp_iter2 I.grp_make names l in + let mk_avs l = + if subj = "" then I.make "" (mk_grp l) + else I.make (List.hd l) (mk_grp (List.tl l)) in - compose mk_avs res + U.iter mk_avs res let get_table h mc ct cfl el = let aux_c ts (_, p, _) = A.refine_tables ts (C.tables h p) in @@ -131,7 +136,7 @@ let exec_single h mc ct cfl el table = let cols = if first = "" then other_cols else first :: other_cols in let low_level = if C.set h C.Galax then gx_query else pg_query in let result = low_level h (C.resolve h table) cols cons_true cons_false in - pg_result false first el result + pg_result first el result let deadline = 100 @@ -139,9 +144,9 @@ let exec h refine mc ct cfl el = if refine <> M.RefineExact then not_supported "exec"; let table = get_table h mc ct cfl el in let rec exec_aux ct = match ct with - | (pat, p, v) :: tail when List.length v > deadline -> - let single s = exec_aux ((pat, p, [s]) :: tail) in - U.mql_iter single v + | (pat, p, v) :: tail when U.count v > deadline -> + let single a s _ = I.union a (exec_aux ((pat, p, I.make s I.grp_empty) :: tail)) in + I.iter single U.val_false v | _ -> exec_single h mc ct cfl el table in exec_aux ct @@ -155,3 +160,4 @@ let pg_name h s = | _ -> "" let get_id b = if b then ["B"] else ["F"] +