]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/mathql_interpreter/dbconn.ml
First very-very-very-very-alfa release of a MathQL Interpreter implemented
[helm.git] / helm / ocaml / mathql_interpreter / dbconn.ml
diff --git a/helm/ocaml/mathql_interpreter/dbconn.ml b/helm/ocaml/mathql_interpreter/dbconn.ml
new file mode 100644 (file)
index 0000000..5f1d256
--- /dev/null
@@ -0,0 +1,52 @@
+
+(*
+ * gestione della connessione al database
+ *)
+
+(*
+ * le eccezzioni lanciate dalle funzioni init e pgc sono
+ * definite nel modulo Mathql 
+ *)
+open Mathql;;
+
+(*
+ * paramentri della connessione
+ *)
+(*let connection_param = "host=127.0.0.1 dbname=helm";;*)
+let connection_param = "host=dotto.cs.unibo.it dbname=helm user=helm";;
+
+(*
+ * connessione al db
+ *)
+let conn = ref None;;
+
+(*
+ * controllo sulla connessione
+ *)
+let pgc () =
+   match !conn with
+      None -> raise (MQInvalidConnection connection_param)
+   |  Some c -> c
+;;
+
+(*
+ * inizializzazione della connessione
+ *
+ * TODO
+ * passare i parametri della connessione come argomento di init
+ *)
+let init () =
+   try (
+    conn := Some (new Postgres.connection connection_param);
+   ) with
+    _ -> raise (MQConnectionFailed ("init: " ^ connection_param))
+;;
+
+(*
+ * chiusura della connessione
+ *)
+let close () =
+   match !conn with
+      None -> ()
+   |  Some c -> c#close
+;;