]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/mathql_interpreter/mqint.ml
Db connection ok!
[helm.git] / helm / ocaml / mathql_interpreter / mqint.ml
index c28aa02a071ba028fde818eebeba1f0d7a300e78..84b3522f26ea49e324bee03f04a847935b613f11 100644 (file)
@@ -33,8 +33,9 @@
 open MathQL;;
 open Eval;;
 open Utility;;
-open Dbconn;;
+
 open Pattern;;*)
+open Dbconn;;
 open Union;;
 open Intersect;;
 open Meet;;
@@ -76,25 +77,7 @@ let see_prop_pool () =
   (match !prop_pool with Some l -> l | _ -> print_endline "ciao"; assert false)
 ;;
 
-(*
- * inizializzazione della connessione al database
- *)
-let init () =
- let _ = Dbconn.init () in
-  let c = pgc () in
-   let res = 
-    c#exec "select name,id from property where ns_id in (select id from namespace where url='http://www.cs.unibo.it/helm/schemas/mattone.rdf#')"
-   in
-    prop_pool := Some
-     (
-      List.map
-       (function
-           a::b::_ -> (a, b)
-         | _       -> print_endline "no"; assert false
-       )
-       res#get_list
-     )
-;;
+
 
 let get_prop_id prop =
  if prop="refObj" then "F"
@@ -249,18 +232,30 @@ let execute q =
     MQList qq -> xres_to_res (execute_ex [] qq)
 ;;
 
-(*
- * chiusura della connessione al database
- *)
-let close () = Dbconn.close ();;
+let prop_pool = ref None;;
 
 *****************************************************************************)
 
-let init () = () (* FG: implementare l'apertura del database *)
-
-let close () = () (* FG: implementare la chiusura del database *)
+let init () = Dbconn.init () 
+(*
+   let c = pgc () in
+   let res = 
+      c#exec "select name,id from property where ns_id in (select id from namespace where url='http://www.cs.unibo.it/helm/schemas/mattone.rdf#')"
+   in
+   prop_pool := Some
+     (
+      List.map
+       (function
+           a::b::_ -> (a, b)
+         | _       -> print_endline "no"; assert false
+       )
+       res#get_list
+     )
+*) 
 
+let close () = Dbconn.close ()
 
+let check () = Dbconn.pgc ()
 
 exception BooleExpTrue
 
@@ -281,8 +276,8 @@ let rec exec_set_exp c = function
                                           let rec select_ex rset =
                                            match rset with 
                                                      [] -> []
-                                           | r::tl -> upd_rvars c ((rvar,r)::c.rvars);                     
-                                              if (exec_boole_exp c bexp) then r::(select_ex tl)
+                                           | r::tl -> let c1 = upd_rvars c ((rvar,r)::c.rvars) in                      
+                                              if (exec_boole_exp c1 bexp) then r::(select_ex tl)
                                               else select_ex tl
                                           in select_ex rset
                                                       
@@ -315,8 +310,8 @@ and exec_boole_exp c = function
              | (uri,attl)::tail1 -> let rec sub_prod attl =
                                      match attl with
 (*per ogni el. di attl  *)             [] -> () 
-(*devo andare in ric. su tail1*)      | att::tail2 -> upd_groups c ((uri,att)::c.groups);             
-                                                      prod c tail1; sub_prod tail2 
+(*devo andare in ric. su tail1*)      | att::tail2 -> let c1 = upd_groups c ((uri,att)::c.groups) in             
+                                                      prod c1 tail1; sub_prod tail2 
                                     in       
                                      sub_prod attl 
             in
@@ -327,11 +322,15 @@ and exec_boole_exp c = function
 (* valuta una MathQL.val_exp e ritorna un MathQL.value *)
 
 and exec_val_exp c = function
-   | MathQL.Const x -> let ol = List.sort compare x in 
+   | MathQL.Const x -> let
+   ol = List.sort compare x in 
                        let rec edup = function
+                       
                           [] -> [] 
-                        | s::tl -> if s = (List.tl tl) then edup tl
-                                   else s::(edup tl)
+                        | s::tl -> if tl <> [] then  
+                                                if s = (List.hd tl) then edup tl
+                                                else s::(edup tl)
+                                   else s::[]
                        in
                         edup ol
    | MathQL.Record (rvar, vvar) -> List.assoc vvar (List.assoc rvar c.groups) 
@@ -347,3 +346,11 @@ and exec_val_exp c = function
 and execute x =
    exec_set_exp {svars = []; rvars = []; groups = []; vvars = []} x 
 
+
+
+
+(*
+ * chiusura della connessione al database
+  *)
+  let close () = Dbconn.close ();;
+