X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Focaml%2Fmathql_interpreter%2FmQIPostgres.ml;fp=helm%2Focaml%2Fmathql_interpreter%2FmQIPostgres.ml;h=21a623f551c0e682d060bcb586e19b154d20ca47;hb=06b6527a689f994864c13f0ffe401a5b8c052002;hp=7b73451286d39550d7b0df83f82cfeb0462b1d61;hpb=980a9931d3f7b8ce073247c88d7ecd42a672ad74;p=helm.git diff --git a/helm/ocaml/mathql_interpreter/mQIPostgres.ml b/helm/ocaml/mathql_interpreter/mQIPostgres.ml index 7b7345128..21a623f55 100644 --- a/helm/ocaml/mathql_interpreter/mQIPostgres.ml +++ b/helm/ocaml/mathql_interpreter/mQIPostgres.ml @@ -47,35 +47,35 @@ let quote s = in "'" ^ quote_aux s ^ "'" -let exec c q = (c#exec q)#get_list, q +let exec (c, out) q = out q; (c#exec q)#get_list let exec c table cols ct cfl = - let rec iter f sep = function - | [] -> "" + let rec iter f last sep = function + | [] -> last | [head] -> f head - | head :: tail -> f head ^ sep ^ iter f sep tail + | head :: tail -> f head ^ sep ^ iter f last sep tail in - let avs_iter f sep v = + let avs_iter f last sep v = let aux a s = function | true -> a ^ (f s) ^ sep | false -> a ^ (f s) in - I.iter aux "" v + if v = I.empty then sep else I.iter aux "" v in - let pg_cols = iter (fun x -> x) ", " cols in - let pg_msval v = avs_iter quote ", " v in + let pg_cols = iter (fun x -> x) "" ", " cols in + let pg_msval v = avs_iter quote "" ", " v in let pg_con (pat, col, v) = if col <> "" then let f s = col ^ " ~ " ^ quote ("^" ^ s ^ "$") in - if pat then "(" ^ avs_iter f " or " v ^ ")" - else match I.single v with - | Some s -> col ^ " = " ^ (quote s) - | None -> col ^ " in (" ^ pg_msval v ^ ")" + if pat then "(" ^ avs_iter f "false" " or " v ^ ")" + else match I.single v with + | Some s -> col ^ " = " ^ (quote s) + | None -> col ^ " in (" ^ pg_msval v ^ ")" else "true" in - let pg_cons l = iter pg_con " and " l in + let pg_cons l = iter pg_con "true" " and " l in let pg_cons_not l = "not (" ^ pg_cons l ^ ")" in - let pg_cons_not_l ll = iter pg_cons_not " and " ll in + let pg_cons_not_l ll = iter pg_cons_not "true" " and " ll in let pg_where = match ct, cfl with | [], [] -> "" | lt, [] -> " where " ^ pg_cons lt @@ -83,13 +83,13 @@ let exec c table cols ct cfl = | lt, llf -> " where " ^ pg_cons lt ^ " and " ^ pg_cons_not_l llf in if cols = [] then - let r, q = exec c ("select count (source) from " ^ table ^ pg_where) in + let r = exec c ("select count(source) from " ^ table ^ pg_where) in match r with - | [[s]] when int_of_string s > 0 -> [[]], q - | _ -> [], q + | [[s]] when int_of_string s > 0 -> [[]] + | _ -> [] else exec c ("select " ^ pg_cols ^ " from " ^ table ^ pg_where ^ - " order by " ^ List.hd cols ^ " asc") (* desc *) + " order by " ^ List.hd cols ^ " asc") (* funzioni vecchie ********************************************************) (*