X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;ds=sidebyside;f=helm%2Focaml%2Fmathql_interpreter%2FmQIConn.ml;h=11dbd1674a058ada15206614b505aee47dd8198f;hb=fde0ad77237a2fbdfb5621d5b5085fe7c82e3f92;hp=f38964f060f6e90f1f71542ba8b416a06177596d;hpb=39b9497090ee5cc501de1e3d9044d71fdc5cf1fb;p=helm.git diff --git a/helm/ocaml/mathql_interpreter/mQIConn.ml b/helm/ocaml/mathql_interpreter/mQIConn.ml index f38964f06..11dbd1674 100644 --- a/helm/ocaml/mathql_interpreter/mQIConn.ml +++ b/helm/ocaml/mathql_interpreter/mQIConn.ml @@ -23,23 +23,32 @@ * http://cs.unibo.it/helm/. *) -exception InvalidConnection +(* AUTOR: Ferruccio Guidi + *) + +type flag = Postgres | Galax | Stat | Quiet | Warn | Log + +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 *) +} -type flag = Postgres | Galax | Stat | Quiet | Warn +let tables handle p = MQIMap.get_tables handle.pgm p -type handle = {log : string -> unit; (* logging function *) - set : flag list; (* options *) - pgc : Postgres.connection option (* Postgres connection *) - } +let field handle p t = MQIMap.get_field handle.pgm p t + +let resolve handle a = MQIMap.resolve handle.pga a let log handle = handle.log let set handle flag = List.mem flag handle.set -let pgc handle = - match handle.pgc with - | None -> raise InvalidConnection - | Some c -> c +let pgc handle = handle.pgc + +let flags handle = handle.set let string_of_flag = function | Postgres -> "P" @@ -47,6 +56,7 @@ let string_of_flag = function | Stat -> "S" | Quiet -> "Q" | Warn -> "W" + | Log -> "L" let flag_of_char = function | 'P' -> [Postgres] @@ -54,6 +64,7 @@ let flag_of_char = function | 'S' -> [Stat] | 'Q' -> [Quiet] | 'W' -> [Warn] + | 'L' -> [Log] | _ -> [] let string_fold_left f a s = @@ -68,24 +79,22 @@ let flags_of_string s = string_fold_left (fun l c -> l @ flag_of_char c) [] s let init myflags mylog = - let default_connection_string = - "host=mowgli.cs.unibo.it dbname=helm_mowgli_new_schema user=helm" - in - let connection_string = - try Sys.getenv "POSTGRESQL_CONNECTION_STRING" - with Not_found -> default_connection_string + let s, m, a = + let g = + if List.mem Galax myflags + then MQIMap.empty_map else MQIMap.read_map + in g () in {log = mylog; set = myflags; - pgc = if List.mem Galax myflags - then None else Dbconn.init connection_string + pgc = if List.mem Galax myflags then None else MQIPostgres.init s; + pgm = m; pga = a } let close handle = - if set handle Galax then () else Dbconn.close handle.pgc + if set handle Galax then () else MQIPostgres.close handle.pgc let connected handle = - if set handle Galax then false else - try ignore (pgc handle); true with InvalidConnection -> false + if set handle Galax then false else (pgc handle) <> None let init_if_connected myflags mylog = let handle = init myflags mylog in