From: Ferruccio Guidi Date: Tue, 8 Oct 2002 12:04:36 +0000 (+0000) Subject: the db connection parameters are now parametrized istead of hard-coded X-Git-Tag: new_mathql_before_first_merge~13 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=5953b6e29b26a296d18dee9d453cec1255d65c1c;p=helm.git the db connection parameters are now parametrized istead of hard-coded we use Sys.time () instead of Unix.time () Let-in for vvars fixed --- diff --git a/helm/ocaml/mathql_interpreter/dbconn.ml b/helm/ocaml/mathql_interpreter/dbconn.ml index 17264f5cb..b38eabe87 100644 --- a/helm/ocaml/mathql_interpreter/dbconn.ml +++ b/helm/ocaml/mathql_interpreter/dbconn.ml @@ -33,32 +33,21 @@ *) open MathQL;; -exception DBInvalidURI of string -exception DBConnectionFailed of string -exception DBInvalidConnection of string - - - -(* - * paramentri della connessione - * - * TODO: bisogna scegliere se questi parametri vengono - * passati come argomento - *) -(*let connection_param = "dbname=helm";;*) -let connection_param = "host=mowgli.cs.unibo.it dbname=helm user=helm";; +exception InvalidURI of string +exception ConnectionFailed of string +exception InvalidConnection (* * connessione al db *) -let conn = ref None;; +let conn = ref None (* * controllo sulla connessione *) let pgc () = match !conn with - None -> raise (DBInvalidConnection connection_param) + None -> raise InvalidConnection | Some c -> c ;; @@ -68,12 +57,11 @@ let pgc () = * TODO * passare i parametri della connessione come argomento di init *) -let init () = +let init connection_param = try ( conn := Some (new Postgres.connection connection_param); - prerr_endline "connected." ) with - _ -> raise (DBConnectionFailed ("init: " ^ connection_param)) + _ -> raise (ConnectionFailed ("init: " ^ connection_param)) ;; (* diff --git a/helm/ocaml/mathql_interpreter/dbconn.mli b/helm/ocaml/mathql_interpreter/dbconn.mli index c162cf00e..ecfbcd66a 100644 --- a/helm/ocaml/mathql_interpreter/dbconn.mli +++ b/helm/ocaml/mathql_interpreter/dbconn.mli @@ -24,5 +24,5 @@ *) val pgc : unit -> Postgres.connection -val init : unit -> unit +val init : string -> unit val close : unit -> unit diff --git a/helm/ocaml/mathql_interpreter/diff.ml b/helm/ocaml/mathql_interpreter/diff.ml index 28e874c86..b4e09196e 100644 --- a/helm/ocaml/mathql_interpreter/diff.ml +++ b/helm/ocaml/mathql_interpreter/diff.ml @@ -83,9 +83,9 @@ let rec diff_ex rs1 rs2 = let diff_ex l1 l2 = - let before = Unix.time () in + let before = Sys.time () in let res = diff_ex l1 l2 in - let after = Unix.time () in + let after = Sys.time () in let ll1 = string_of_int (List.length l1) in let ll2 = string_of_int (List.length l2) in let diff = string_of_float (after -. before) in diff --git a/helm/ocaml/mathql_interpreter/intersect.ml b/helm/ocaml/mathql_interpreter/intersect.ml index 8a2f55ff2..6503a3942 100644 --- a/helm/ocaml/mathql_interpreter/intersect.ml +++ b/helm/ocaml/mathql_interpreter/intersect.ml @@ -89,71 +89,3 @@ let intersect_ex rs1 rs2 = res ;; -(* - -let intersect_ex l1 l2 = - (* PRE-CLAUDIO - (*let _ = print_string ("INTERSECT ") - and t = Unix.time () in*) - let result = - match (l1, l2) with - ((head1::tail1), (head2::tail2)) -> - (match (head1, head2) with - ([], _) -> assert false (* gli header non devono mai essere vuoti *) - | (_, []) -> assert false (* devono contenere almeno [retVal] *) - | (_, _) -> - (match (tail1, tail2) with - ([], _) -> [["retVal"]] (* se una delle due code e' vuota... *) - | (_, []) -> [["retVal"]] (* ... l'intersezione e' vuota *) - | (_, _) -> - [head2 @ - (List.find_all - (function t -> not (List.mem t head2)) - head1 - ) - ] (* header del risultato finale *) - @ - intersect_tails (List.tl head1) tail1 (List.tl head2) tail2 - (* - List.fold_left - (fun par1 elem1 -> par1 @ - List.map - (fun elem2 -> - [(List.hd elem1)] @ - (xres_join_context (List.tl head1) (List.tl elem1) - (List.tl head2) (List.tl elem2) - ) - ) - (List.find_all (* *) - (fun elem2 -> (* trova tutti gli elementi della lista tail2 *) - ((List.hd elem1) = (List.hd elem2)) && (* che stanno in tail1 *) - not ((xres_join_context (List.tl head1) (List.tl elem1) - (List.tl head2) (List.tl elem2)) = []) - (* e per i quali la xres_join_context non sia vuota *) - ) - tail2 (* List.find_all *) - ) - ) - [] - tail1 (* per ogni elemento di tail1 applica la List.fold_left *) - *) - ) (* match *) - ) - | _ -> [] - in - (*let _ = print_endline (string_of_float (Unix.time () -. t)); flush stdout in*) - result*) - let before = Sys.time () in - let res = intersect_ex l1 l2 in - let after = Sys.time () in - let ll1 = string_of_int (List.length l1) in - let ll2 = string_of_int (List.length l2) in - let diff = string_of_float (after -. before) in - print_endline - ("INTERSECT(" ^ ll1 ^ "," ^ ll2 ^ ") = " ^ string_of_int (List.length res) ^ - ": " ^ diff ^ "s") ; - flush stdout ; - res -;; - -*) diff --git a/helm/ocaml/mathql_interpreter/mqint.ml b/helm/ocaml/mathql_interpreter/mqint.ml index 84b3522f2..bfe85f7ea 100644 --- a/helm/ocaml/mathql_interpreter/mqint.ml +++ b/helm/ocaml/mathql_interpreter/mqint.ml @@ -110,7 +110,7 @@ let rec execute_ex env = intersect_ex (execute_ex env l1) (execute_ex env l2) | MQListRVar rvar -> [List.assoc rvar env] | MQLetIn (lvar, l1, l2) -> - let t = Unix.time () in + let t = Sys.time () in let res = (*CSC: The interesting code *) let _ = letin_ex lvar (execute_ex env l1) in @@ -119,7 +119,7 @@ let rec execute_ex env = in letdispose (); print_string ("LETIN = " ^ string_of_int (List.length res) ^ ": ") ; - print_endline (string_of_float (Unix.time () -. t) ^ "s") ; + print_endline (string_of_float (Sys.time () -. t) ^ "s") ; flush stdout ; res | MQListLVar lvar -> @@ -151,7 +151,7 @@ Select.execute := execute_ex;; * sono associati anche i valori delle variabili che ancora non sono state valutate * perche', ad esempio, si trovano in altri rami dell'albero. * - * Esempio: +* Esempio: * SELECT x IN USE PATTERN "cic:/**.con" POSITION $a WHERE $a IS MainConclusion * L'albero corrispondente a questa query e': * @@ -236,7 +236,7 @@ let prop_pool = ref None;; *****************************************************************************) -let init () = Dbconn.init () +let init connection_param = Dbconn.init connection_param (* let c = pgc () in let res = @@ -269,8 +269,13 @@ let rec exec_set_exp c = function | MathQL.Union (sexp1, sexp2) -> union_ex (exec_set_exp c sexp1) (exec_set_exp c sexp2) | MathQL.LetSVar (svar, sexp1, sexp2) -> let _ = (svar, (exec_set_exp c sexp1)):: (List.remove_assoc svar c.svars) in (exec_set_exp c sexp2) - | MathQL.LetVVar (vvar, vexp, sexp) -> let _ = (vvar, (exec_val_exp c vexp)):: (List.remove_assoc vvar c.vvars) - in (exec_set_exp c sexp) + | MathQL.LetVVar (vvar, vexp, sexp) -> + 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 + 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) -> relation_ex rop path (exec_set_exp c sexp) attl | MathQL.Select (rvar, sexp, bexp) -> let rset = (exec_set_exp c sexp) in let rec select_ex rset = @@ -345,12 +350,3 @@ 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 ();; - diff --git a/helm/ocaml/mathql_interpreter/mqint.mli b/helm/ocaml/mathql_interpreter/mqint.mli index d86772622..d7dcf9ebc 100644 --- a/helm/ocaml/mathql_interpreter/mqint.mli +++ b/helm/ocaml/mathql_interpreter/mqint.mli @@ -23,7 +23,7 @@ * http://cs.unibo.it/helm/. *) -val init : unit -> unit (* open database *) +val init : string -> unit (* open database *) val execute : MathQL.query -> MathQL.result (* execute query *) diff --git a/helm/ocaml/mathql_interpreter/pattern.ml b/helm/ocaml/mathql_interpreter/pattern.ml index 576226008..993617bb8 100644 --- a/helm/ocaml/mathql_interpreter/pattern.ml +++ b/helm/ocaml/mathql_interpreter/pattern.ml @@ -35,7 +35,7 @@ open Mathql_semantics;; let pattern_ex (apreamble, apattern, afragid) = let c = pgc () in (*let _ = print_string ("USE ") - and t = Unix.time () in*) + and t = Sys.time () in*) (*let r1 = helm_class_id "MathResource" in*) (*let qq = "select att0 from t" ^ r1 ^ " where att0 " ^ (pattern_match apreamble apattern afragid) ^ " order by t" ^ r1 ^ ".att0 asc" in*) (*PRE-CLAUDIO @@ -52,7 +52,7 @@ print_endline qq ; flush stderr ; c#exec (qq) in (* PRE-CLAUDIO - (*let _ = print_endline (string_of_float (Unix.time () -. t)); flush stdout in*) + (*let _ = print_endline (string_of_float (Sys.time () -. t)); flush stdout in*) result*) List.map (function uri -> {uri = uri ; attributes = [] ; extra = ""}) diff --git a/helm/ocaml/mathql_interpreter/relation.ml b/helm/ocaml/mathql_interpreter/relation.ml index 2fbb24bf8..4776e694c 100644 --- a/helm/ocaml/mathql_interpreter/relation.ml +++ b/helm/ocaml/mathql_interpreter/relation.ml @@ -50,7 +50,7 @@ let vvar = if attl = [] then "position" in (*let (uril,atts) = List.split rset in*) let _ = print_string ("RELATION "^usek) -and t = Unix.time () in +and t = Sys.time () in let result = let c = pgc () in @@ -79,7 +79,7 @@ in in print_string (" = " ^ string_of_int (List.length result) ^ ": ") ; -print_endline (string_of_float (Unix.time () -. t) ^ "s") ; +print_endline (string_of_float (Sys.time () -. t) ^ "s") ; flush stdout ; result ;; diff --git a/helm/ocaml/mathql_interpreter/select.ml b/helm/ocaml/mathql_interpreter/select.ml index 960a0a2ba..ee9f329ba 100644 --- a/helm/ocaml/mathql_interpreter/select.ml +++ b/helm/ocaml/mathql_interpreter/select.ml @@ -139,12 +139,12 @@ let rec is_good env = *) let select_ex env avar alist abool = let _ = print_string ("SELECT = ") - and t = Unix.time () in + and t = Sys.time () in let result = List.filter (function entry -> is_good ((avar,entry)::env) abool) alist in print_string (string_of_int (List.length result) ^ ": ") ; - print_endline (string_of_float (Unix.time () -. t) ^ "s") ; + print_endline (string_of_float (Sys.time () -. t) ^ "s") ; flush stdout ; result ;; *) diff --git a/helm/ocaml/mathql_interpreter/sortedby.ml b/helm/ocaml/mathql_interpreter/sortedby.ml index 177cf3c03..b9a05a002 100644 --- a/helm/ocaml/mathql_interpreter/sortedby.ml +++ b/helm/ocaml/mathql_interpreter/sortedby.ml @@ -35,7 +35,7 @@ open Utility;; * implementazione del comando SORTEDBY *) let sortedby_ex alist order afunc = - let before = Unix.time () in + let before = Sys.time () in let res = let module S = Mathql_semantics in (Sort.list @@ -50,7 +50,7 @@ let sortedby_ex alist order afunc = ) ) in - let after = Unix.time () + let after = Sys.time () and ll1 = string_of_int (List.length alist) in let diff = string_of_float (after -. before) in print_endline diff --git a/helm/ocaml/mathql_interpreter/union.ml b/helm/ocaml/mathql_interpreter/union.ml index a02fbd0f5..35999170c 100644 --- a/helm/ocaml/mathql_interpreter/union.ml +++ b/helm/ocaml/mathql_interpreter/union.ml @@ -128,9 +128,9 @@ let rec union_ex rs1 rs2 = ;; let union_ex l1 l2 = - let before = Unix.time () in + let before = Sys.time () in let res = union_ex l1 l2 in - let after = Unix.time () in + let after = Sys.time () in let ll1 = string_of_int (List.length l1) in let ll2 = string_of_int (List.length l2) in let diff = string_of_float (after -. before) in diff --git a/helm/ocaml/mathql_interpreter/use.ml b/helm/ocaml/mathql_interpreter/use.ml index 654c3e69b..f5648cab1 100644 --- a/helm/ocaml/mathql_interpreter/use.ml +++ b/helm/ocaml/mathql_interpreter/use.ml @@ -55,7 +55,7 @@ let relation_ex rop path rset attl = let usek = get_prop_id (List.hd path) in let _ = print_string ("RELATION "^usek) -and t = Unix.time () in +and t = Sys.time () in let result = let c = pgc () in Sort.list @@ -83,7 +83,7 @@ let result = ) in print_string (" = " ^ string_of_int (List.length result) ^ ": ") ; -print_endline (string_of_float (Unix.time () -. t) ^ "s") ; +print_endline (string_of_float (Sys.time () -. t) ^ "s") ; flush stdout ; result ;;