]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/mathql_interpreter/mQIConn.ml
interpreter flags were reorganized
[helm.git] / helm / ocaml / mathql_interpreter / mQIConn.ml
index 1de6663e4a36369deaf5737d2e4b22eabca276bc..d0dedf143ca20beed109c4db9399d15412a6e940 100644 (file)
  * http://cs.unibo.it/helm/.
  *)
 
-type flag = Postgres | Galax | Stat | Quiet | Warn | Log
+(*  AUTOR: Ferruccio Guidi <fguidi@cs.unibo.it>
+ *)
+
+type flag = Galax | Postgres | Queries | Result | Source | Times | Warn
+
+type handle = {
+   log : string -> unit;             (* logging function        *)
+   set : flag list;                  (* options                 *)
+   pgc : Postgres.connection option; (* PG connection           *)
+   pgm : MQIMap.pg_map;              (* PG conversion function  *)
+   pga : MQIMap.pg_alias             (* PG table aliases        *)
+}
+
+let tables handle p = MQIMap.get_tables handle.pgm p
+
+let field handle p t = MQIMap.get_field handle.pgm p t
 
-type handle = {log : string -> unit;            (* logging function    *)
-               set : flag list;                 (* options             *)
-              pgc : Postgres.connection option (* Postgres connection *)
-             }
+let resolve handle a = MQIMap.resolve handle.pga a
 
 let log handle = handle.log
 
@@ -39,20 +51,22 @@ let pgc handle = handle.pgc
 let flags handle = handle.set 
 
 let string_of_flag = function
-      | Postgres -> "P"
       | Galax    -> "G"
-      | Stat     -> "S"
-      | Quiet    -> "Q"
+      | Postgres -> "P"
+      | Queries  -> "Q"
+      | Result    -> "R"
+      | Source   -> "S"      
+      | Times    -> "T"
       | Warn     -> "W"
-      | Log      -> "L"
 
 let flag_of_char = function
-      | 'P' -> [Postgres]
       | 'G' -> [Galax]
-      | 'S' -> [Stat]
-      | 'Q' -> [Quiet] 
+      | 'P' -> [Postgres]
+      | 'Q' -> [Queries] 
+      | 'R' -> [Result]
+      | 'S' -> [Source]
+      | 'T' -> [Times]
       | 'W' -> [Warn] 
-      | 'L' -> [Log]
       | _   -> []
 
 let string_fold_left f a s =
@@ -66,10 +80,27 @@ let string_of_flags flags =
 let flags_of_string s =
    string_fold_left (fun l c -> l @ flag_of_char c) [] s
 
-let init myflags mylog =
-   {log = mylog; set = myflags; 
-    pgc = if List.mem Galax myflags 
-       then None else MQIPostgres.init ()
+let init ?(flags = []) ?(log = ignore) () =
+   let flags = 
+      if flags = [] then
+         flags_of_string (Helm_registry.get "mathql_interpreter.flags")
+      else 
+         flags
+   in
+   let m, a =
+      let g = 
+         if List.mem Galax flags 
+           then MQIMap.empty_map else MQIMap.read_map
+      in g ()
+   in
+   {log = log; set = flags; 
+    pgc =
+     if List.mem Galax flags then
+      None
+     else
+      MQIPostgres.init
+       (Helm_registry.get "mathql_interpreter.postgresql_connection_string");
+    pgm = m; pga = a
    }      
 
 let close handle =
@@ -78,7 +109,6 @@ let close handle =
 let connected handle =
    if set handle Galax then false else (pgc handle) <> None  
 
-let init_if_connected myflags mylog =
-   let handle = init myflags mylog in
+let init_if_connected ?(flags = []) ?(log = ignore) () =
+   let handle = init ~flags:flags ~log:log () in
    ignore (pgc handle); handle