]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/mathql_interpreter/mqint.ml
bumped version to 0.0.3
[helm.git] / helm / ocaml / mathql_interpreter / mqint.ml
index e1dc6f8d988f7fe0034ad06120fc64423f09f313..c67d11d15f655c6a38b6efea5dd9c12341b70b36 100644 (file)
@@ -42,21 +42,37 @@ open Context;;
 open Diff;;
 open Relation;;
 open Func;;
+open Attribute;;
+
+
+exception BooleExpTrue
 
 let init connection_param = Dbconn.init connection_param 
 
 let close () = Dbconn.close ()
 
-let check () = Dbconn.pgc ()
-
-exception BooleExpTrue
+let check () = 
+   let status = Dbconn.pgc () 
+   in ()
 
-let stat = ref false
+let stat = ref true
 
 let set_stat b = stat := b
 
 let get_stat () = ! stat
 
+let postgres_db = "postgres"
+
+let galax_db = "galax"
+
+let dbname = ref galax_db
+
+let set_database s = 
+    if s = postgres_db || s = galax_db then dbname := s
+    else raise (Invalid_argument s)
+
+let get_database () = ! dbname
+
 (* valuta una MathQL.set_exp e ritorna un MathQL.resource_set *)
 
 let rec exec_set_exp c = function
@@ -90,7 +106,7 @@ let rec exec_set_exp c = function
         let before = Sys.time() in
         let c1 = upd_svars c ((svar, exec_set_exp c sexp1) :: c.svars) in 
        let res = exec_set_exp c1 sexp2 in
-       if !stat then
+       if ! stat then
        (print_string ("LETIN " ^ svar ^ " = " ^ string_of_int (List.length res) ^ ": ");
         print_endline (string_of_float (Sys.time() -. before) ^ "s");
          flush stdout); 
@@ -99,19 +115,29 @@ let rec exec_set_exp c = function
         let before = Sys.time() in
        let c1 = upd_vvars c ((vvar, exec_val_exp c vexp) :: c.vvars) in
        let res = exec_set_exp c1 sexp in
-       if !stat then
+       if ! stat then
        (print_string ("LETIN " ^ vvar ^ " = " ^ string_of_int (List.length res) ^ ": ");
          print_endline (string_of_float (Sys.time() -. before) ^ "s");
          flush stdout); 
        res
-   | MathQL.Relation (rop, path, sexp, attl) -> 
+   | MathQL.Relation (inv, rop, path, sexp, attl) -> 
         let before = Sys.time() in
-        let res = relation_ex rop path (exec_set_exp c sexp) attl in
-       if !stat then 
-       (print_string ("RELATION " ^ (List.hd path) ^ " = " ^ string_of_int(List.length res) ^ ": ");
-         print_endline (string_of_float (Sys.time() -. before) ^ "s");
-         flush stdout);
-        res   
+       if ! dbname = postgres_db then
+        (let res = relation_ex rop path (exec_set_exp c sexp) attl in
+        if ! stat then 
+        (print_string ("RELATION " ^ (List.hd path) ^ " = " ^ string_of_int(List.length res) ^ ": ");
+          print_endline (string_of_float (Sys.time() -. before) ^ "s");
+          flush stdout);
+         res)
+       else
+        (let res = relation_galax_ex rop path (exec_set_exp c sexp) attl in
+         if !stat then
+         (print_string ("RELATION-GALAX " ^ (List.hd path) ^ " = " ^ string_of_int(List.length res) ^ ": ");
+          print_endline (string_of_float (Sys.time() -. before) ^ "s");
+          flush stdout);
+         res) 
+       
+       
    | MathQL.Select (rvar, sexp, bexp) ->
         let before = Sys.time() in
         let rset = (exec_set_exp c sexp) in
@@ -123,7 +149,7 @@ let rec exec_set_exp c = function
                   else select_ex tl
         in 
        let res = select_ex rset in
-       if !stat then
+       if ! stat then
        (print_string ("SELECT " ^ rvar ^ " = " ^ string_of_int (List.length res) ^ ": ");
         print_endline (string_of_float (Sys.time() -. before) ^ "s");
          flush stdout); 
@@ -181,7 +207,7 @@ and exec_val_exp c = function
    | MathQL.VVar s -> List.assoc s c.vvars                               
    | MathQL.RefOf sexp -> List.map (fun (s,_) -> s) (exec_set_exp c sexp)
    | MathQL.Fun (s, vexp) -> fun_ex s (exec_val_exp c vexp)
-   | _ -> assert false
+   | MathQL.Attribute (inv, rop, path, vexp) -> attribute_ex rop path inv (exec_val_exp c vexp) 
 
 (* valuta una MathQL.set_exp nel contesto vuoto e ritorna un MathQL.resource_set *)
 and execute x =