* http://cs.unibo.it/helm/.
*)
-exception InvalidConnection
-
-type flag = Postgres | Galax | Stat | Quiet | Warn
+type flag = Postgres | Galax | Stat | Quiet | Warn | Log
type handle = {log : string -> unit; (* logging function *)
set : flag list; (* options *)
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"
| Stat -> "S"
| Quiet -> "Q"
| Warn -> "W"
+ | Log -> "L"
let flag_of_char = function
| 'P' -> [Postgres]
| 'S' -> [Stat]
| 'Q' -> [Quiet]
| 'W' -> [Warn]
+ | 'L' -> [Log]
| _ -> []
let string_fold_left f a 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
- in
{log = mylog; set = myflags;
pgc = if List.mem Galax myflags
- then None else Dbconn.init connection_string
+ then None else MQIPostgres.init ()
}
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