-let pg_query table cols ct cf =
- let rec iter f sep = function
- | [] -> ""
- | [head] -> f head
- | head :: tail -> f head ^ sep ^ iter f sep tail
- in
- let pg_cols = iter (fun x -> x) ", " cols in
- let pg_msval v = 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 col ^ " in (" ^ pg_msval v ^ ")"
- else "true"
- in
- let pg_cons l = iter pg_con " and " l in
- let pg_cons_not l = "not (" ^ pg_cons l ^ ")" in
- let pg_where = match ct, cf with
- | [], [] -> ""
- | lt, [] -> " where " ^ pg_cons lt
- | [], lf -> " where " ^ pg_cons_not lf
- | lt, lf -> " where " ^ pg_cons lt ^ " and " ^ pg_cons_not lf
- in
- if cols = [] then [] else begin
- let q = "select " ^ pg_cols ^ " from " ^ table ^ pg_where ^
- " order by " ^ List.hd cols ^ " asc" in
- prerr_endline q;
- P.exec q end
-