]> matita.cs.unibo.it Git - helm.git/commitdiff
some new features of mathql-1.3 where included
authorFerruccio Guidi <ferruccio.guidi@unibo.it>
Wed, 14 Apr 2004 13:42:59 +0000 (13:42 +0000)
committerFerruccio Guidi <ferruccio.guidi@unibo.it>
Wed, 14 Apr 2004 13:42:59 +0000 (13:42 +0000)
helm/ocaml/mathql_interpreter/.depend
helm/ocaml/mathql_interpreter/mQIMySql.ml
helm/ocaml/mathql_interpreter/mQIPostgres.ml
helm/ocaml/mathql_interpreter/mQIProperty.ml

index 82921d3229a3b46067f541e65f653adaad2efe38..bf1f5a3d695ec061f4c5ae38fd56ea4f0aa0af96 100644 (file)
@@ -2,7 +2,7 @@ mQIMySql.cmi: mQITypes.cmo
 mQIPostgres.cmi: mQITypes.cmo 
 mQIConn.cmi: mQIMap.cmi mQITypes.cmo 
 mQILib.cmi: mQIConn.cmi 
-mQIProperty.cmi: mQIConn.cmi 
+mQIProperty.cmi: mQIConn.cmi mQITypes.cmo 
 mQueryIO.cmi: mQILib.cmi 
 mQueryInterpreter.cmi: mQIConn.cmi 
 mQIMySql.cmo: mQIMySql.cmi 
index 591bfe87972c973a0390e48e852a3eef58a0db73..40bb16c46d4cc7766d8d5c563a37e699c0e4677a 100644 (file)
@@ -45,38 +45,38 @@ let quote s =
    in
    "'" ^ quote_aux s ^ "'"
 
-let exec c q = 
+let exec (c, out) q = 
    let g = function None -> "" | Some v -> v in
    let f a = List.map g (Array.to_list a) in
-   Mysql.map ~f:f (Mysql.exec c q), q
+   out q; Mysql.map ~f:f (Mysql.exec c q)
 
 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 last 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 ^ " regexp " ^ quote ("^" ^ s ^ "$") in
-        if pat then "(" ^ avs_iter f " or " v ^ ")"
-        else match I.single v with 
-           | Some s -> "binary " ^ col ^ " = " ^ (quote s)     
-           | None   -> "binary " ^ col ^ " in (" ^ pg_msval v ^ ")"
+         let f s = col ^ " regexp " ^ quote ("^" ^ s ^ "$") in
+         if pat then "(" ^ avs_iter f "0" " or " v ^ ")"
+         else match I.single v with 
+            | Some s -> col ^ " = " ^ (quote s)     
+            | None   -> col ^ " in (" ^ pg_msval v ^ ")"
       else "1"
    in
-   let pg_cons l = iter pg_con " and " l in
+   let pg_cons l = iter pg_con "1" " 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 "1" " and " ll in
    let pg_where = match ct, cfl with
       | [], []  -> ""
       | lt, []  -> " where " ^ pg_cons lt
@@ -84,10 +84,10 @@ 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")
index 7b73451286d39550d7b0df83f82cfeb0462b1d61..21a623f551c0e682d060bcb586e19b154d20ca47 100644 (file)
@@ -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  ********************************************************)
 (*
index e721606de39867a283e5c51ec24f2b3ccf0ec974..acb5df43a84c48a0ec163eaaf42725822e9728fb 100644 (file)
@@ -81,9 +81,9 @@ let exec_single h mc ct cfl el table =
    let cons_false = List.map mk_con cfl in
    let other_cols = List.map (fun (p, _) -> conv p) el in 
    let cols = if first = "" then other_cols else first :: other_cols in
-   let result, q = C.exec h (C.resolve h table) cols cons_true cons_false in
-   if C.set h C.Queries then C.log h (q ^ "\n");   
-   pg_result first el result 
+   let out q = if C.set h C.Queries then C.log h (q ^ "\n") in
+   let r = C.exec h out (C.resolve h table) cols cons_true cons_false in
+   pg_result first el r
    
 let deadline = 100