X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Focaml%2Fmathql_interpreter%2FmQIConn.ml;h=aaf16fac4c0c692c037eaa793b58c80a7c734622;hb=4167cea65ca58897d1a3dbb81ff95de5074700cc;hp=d0dedf143ca20beed109c4db9399d15412a6e940;hpb=bcec0bb27e0dce3e72c97011f9c9dd210f604705;p=helm.git diff --git a/helm/ocaml/mathql_interpreter/mQIConn.ml b/helm/ocaml/mathql_interpreter/mQIConn.ml index d0dedf143..aaf16fac4 100644 --- a/helm/ocaml/mathql_interpreter/mQIConn.ml +++ b/helm/ocaml/mathql_interpreter/mQIConn.ml @@ -26,14 +26,18 @@ (* AUTOR: Ferruccio Guidi *) +type connection = MySQL_C of HMysql.dbd + | Postgres_C of Postgres.connection + | No_C + 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 *) + log : string -> unit; (* logging function *) + set : flag list; (* options *) + pgc : connection; (* 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 @@ -54,7 +58,7 @@ let string_of_flag = function | Galax -> "G" | Postgres -> "P" | Queries -> "Q" - | Result -> "R" + | Result -> "R" | Source -> "S" | Times -> "T" | Warn -> "W" @@ -94,21 +98,31 @@ let init ?(flags = []) ?(log = ignore) () = 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"); + pgc = begin + try + if List.mem Galax flags then No_C else + if List.mem Postgres flags then Postgres_C (MQIPostgres.init ()) else + MySQL_C (MQIMySql.init ()) + with Failure "mqi_connection" -> No_C + end; pgm = m; pga = a } let close handle = - if set handle Galax then () else MQIPostgres.close handle.pgc + match pgc handle with + | MySQL_C c -> MQIMySql.close c + | Postgres_C c -> MQIPostgres.close c + | No_C -> () + +let exec handle out table cols ct cfl = + match pgc handle with + | MySQL_C c -> MQIMySql.exec (c, out) table cols ct cfl + | Postgres_C c -> MQIPostgres.exec (c, out) table cols ct cfl + | No_C -> [] let connected handle = - if set handle Galax then false else (pgc handle) <> None + pgc handle <> No_C let init_if_connected ?(flags = []) ?(log = ignore) () = let handle = init ~flags:flags ~log:log () in - ignore (pgc handle); handle + if connected handle then handle else raise (Failure "mqi connection failed")