]> matita.cs.unibo.it Git - helm.git/commitdiff
Quick patch to make everything work with MySql.
authorClaudio Sacerdoti Coen <claudio.sacerdoticoen@unibo.it>
Tue, 24 Feb 2004 14:50:11 +0000 (14:50 +0000)
committerClaudio Sacerdoti Coen <claudio.sacerdoticoen@unibo.it>
Tue, 24 Feb 2004 14:50:11 +0000 (14:50 +0000)
Note: to compile you need to make a symbolic link from mQIDataBase.ml
to mQIPostgres.ml or mQIMySql.ml

helm/ocaml/mathql_interpreter/.depend
helm/ocaml/mathql_interpreter/Makefile
helm/ocaml/mathql_interpreter/mQIConn.ml
helm/ocaml/mathql_interpreter/mQIConn.mli
helm/ocaml/mathql_interpreter/mQIDataBase.mli [new file with mode: 0644]
helm/ocaml/mathql_interpreter/mQIMySql.ml [new file with mode: 0644]
helm/ocaml/mathql_interpreter/mQIMySql.mli [new file with mode: 0644]
helm/ocaml/mathql_interpreter/mQIPostgres.ml
helm/ocaml/mathql_interpreter/mQIPostgres.mli
helm/ocaml/mathql_interpreter/mQIProperty.ml

index 7d9b3c6257f0e968ea03155348276c90fbf448f7..c9d883b213944e3639d64bc1d1c9ee048ae1d311 100644 (file)
@@ -1,4 +1,4 @@
-mQIConn.cmi: mQIMap.cmi 
+mQIConn.cmi: mQIMap.cmi mQIPostgres.cmi 
 mQIProperty.cmi: mQIConn.cmi 
 mQueryInterpreter.cmi: mQIConn.cmi 
 mQueryTParser.cmo: mQueryTParser.cmi 
@@ -9,15 +9,19 @@ mQueryUtil.cmo: mQueryTLexer.cmo mQueryTParser.cmi mQueryUtil.cmi
 mQueryUtil.cmx: mQueryTLexer.cmx mQueryTParser.cmx mQueryUtil.cmi 
 mQIUtil.cmo: mQIUtil.cmi 
 mQIUtil.cmx: mQIUtil.cmi 
+mQIDataBase.cmo: mQIDataBase.cmi 
+mQIDataBase.cmx: mQIDataBase.cmi 
 mQIPostgres.cmo: mQIPostgres.cmi 
 mQIPostgres.cmx: mQIPostgres.cmi 
+mQIMySql.cmo: mQIMySql.cmi 
+mQIMySql.cmx: mQIMySql.cmi 
 mQIMap.cmo: mQueryUtil.cmi mQIMap.cmi 
 mQIMap.cmx: mQueryUtil.cmx mQIMap.cmi 
-mQIConn.cmo: mQIMap.cmi mQIPostgres.cmi mQIConn.cmi 
-mQIConn.cmx: mQIMap.cmx mQIPostgres.cmx mQIConn.cmi 
-mQIProperty.cmo: mQIConn.cmi mQIMap.cmi mQIPostgres.cmi mQIUtil.cmi \
+mQIConn.cmo: mQIDataBase.cmi mQIMap.cmi mQIConn.cmi 
+mQIConn.cmx: mQIDataBase.cmx mQIMap.cmx mQIConn.cmi 
+mQIProperty.cmo: mQIConn.cmi mQIDataBase.cmi mQIMap.cmi mQIUtil.cmi \
     mQIProperty.cmi 
-mQIProperty.cmx: mQIConn.cmx mQIMap.cmx mQIPostgres.cmx mQIUtil.cmx \
+mQIProperty.cmx: mQIConn.cmx mQIDataBase.cmx mQIMap.cmx mQIUtil.cmx \
     mQIProperty.cmi 
 mQueryInterpreter.cmo: mQIConn.cmi mQIProperty.cmi mQIUtil.cmi mQueryUtil.cmi \
     mQueryInterpreter.cmi 
index 88c66ac8ed5d478cbb22789dc0f8f36653179f50..f6f655d28f6443b472722656c67c3123a5a9943a 100644 (file)
@@ -1,11 +1,11 @@
 PACKAGE = mathql_interpreter
-REQUIRES = helm-urimanager helm-mathql postgres
+REQUIRES = helm-urimanager helm-mathql mysql postgres
 #natile-galax 
 
 PREDICATES =
 
 INTERFACE_FILES = mQueryUtil.mli mQIUtil.mli \
-                 mQIPostgres.mli mQIMap.mli mQIConn.mli \
+                 mQIDataBase.mli mQIPostgres.mli mQIMySql.mli mQIMap.mli mQIConn.mli \
                  mQIProperty.mli mQueryInterpreter.mli
 
 IMPLEMENTATION_FILES = mQueryTParser.ml mQueryTLexer.ml \
index d0dedf143ca20beed109c4db9399d15412a6e940..4e27c9782c7afcf7cf61ad2e53ff9cdd8ef05754 100644 (file)
@@ -31,7 +31,7 @@ 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           *)
+   pgc : MQIDataBase.connection option; (* PG connection           *)
    pgm : MQIMap.pg_map;              (* PG conversion function  *)
    pga : MQIMap.pg_alias             (* PG table aliases        *)
 }
@@ -98,13 +98,13 @@ let init ?(flags = []) ?(log = ignore) () =
      if List.mem Galax flags then
       None
      else
-      MQIPostgres.init
+      MQIDataBase.init
        (Helm_registry.get "mathql_interpreter.postgresql_connection_string");
     pgm = m; pga = a
    }      
 
 let close handle =
-   if set handle Galax then () else MQIPostgres.close handle.pgc
+   if set handle Galax then () else MQIDataBase.close handle.pgc
 
 let connected handle =
    if set handle Galax then false else (pgc handle) <> None  
index b83453ae9683ba8a183233019ff032a88c1d8b79..fba3d4263388b9ab8eda2cad7eaa59b4e5238106 100644 (file)
@@ -45,7 +45,7 @@ val init_if_connected : ?flags:(flag list) -> ?log:(string -> unit) -> unit -> h
 
 val log     : handle -> string -> unit
 val set     : handle -> flag -> bool   
-val pgc     : handle -> Postgres.connection option
+val pgc     : handle -> MQIDataBase.connection option
 val flags   : handle -> flag list  
 val tables  : handle -> MathQL.path -> MQIMap.pg_tables
 val field   : handle -> MathQL.path -> string -> string
diff --git a/helm/ocaml/mathql_interpreter/mQIDataBase.mli b/helm/ocaml/mathql_interpreter/mQIDataBase.mli
new file mode 100644 (file)
index 0000000..8fa7acc
--- /dev/null
@@ -0,0 +1,37 @@
+(* Copyright (C) 2000, HELM Team.
+ * 
+ * This file is part of HELM, an Hypertextual, Electronic
+ * Library of Mathematics, developed at the Computer Science
+ * Department, University of Bologna, Italy.
+ * 
+ * HELM is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * 
+ * HELM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HELM; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA  02111-1307, USA.
+ * 
+ * For details, see the HELM World-Wide-Web page,
+ * http://cs.unibo.it/helm/.
+ *)
+
+(*  AUTOR: Ferruccio Guidi <fguidi@cs.unibo.it>
+ *)
+
+type connection
+
+val init  : string -> connection option
+
+val close : connection option -> unit
+
+val exec  : connection option -> string -> string list list
+
+val quote : string -> string
diff --git a/helm/ocaml/mathql_interpreter/mQIMySql.ml b/helm/ocaml/mathql_interpreter/mQIMySql.ml
new file mode 100644 (file)
index 0000000..f5d30d1
--- /dev/null
@@ -0,0 +1,62 @@
+(* Copyright (C) 2000, HELM Team.
+ * 
+ * This file is part of HELM, an Hypertextual, Electronic
+ * Library of Mathematics, developed at the Computer Science
+ * Department, University of Bologna, Italy.
+ * 
+ * HELM is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * 
+ * HELM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HELM; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA  02111-1307, USA.
+ * 
+ * For details, see the HELM World-Wide-Web page,
+ * http://cs.unibo.it/helm/.
+ *)
+
+(*  AUTOR: Ferruccio Guidi <fguidi@cs.unibo.it>
+ *)
+
+type connection = Mysql.dbd
+
+let init connection_string =
+   try
+    Some
+     (Mysql.quick_connect
+       ~host:"mowgli.cs.unibo.it" ~database:"mowgli" ~user:"helm" ())
+   with _ -> raise (Failure ("MQIPostgres.init: " ^ connection_string))
+
+let close = function
+   |  None   -> ()
+   |  Some c -> Mysql.disconnect c
+
+let exec c q = match c with
+   | None   -> []
+   | Some c ->
+      Mysql.map
+       ~f:(function a ->
+         List.map
+          (function
+              None -> raise (Failure ("NULL found in a table"))
+            | Some v -> v
+          ) (Array.to_list a)
+       ) (Mysql.exec c q)
+   
+let quote s =
+   let rec quote_aux s =
+      try
+         let l = String.length s in
+         let i = String.index s '\'' in
+         String.sub s 0 i ^ "\\'" ^ quote_aux (String.sub s (succ i) (l - (succ i)))
+      with Not_found -> s
+   in
+   "'" ^ quote_aux s ^ "'"
diff --git a/helm/ocaml/mathql_interpreter/mQIMySql.mli b/helm/ocaml/mathql_interpreter/mQIMySql.mli
new file mode 100644 (file)
index 0000000..8fa7acc
--- /dev/null
@@ -0,0 +1,37 @@
+(* Copyright (C) 2000, HELM Team.
+ * 
+ * This file is part of HELM, an Hypertextual, Electronic
+ * Library of Mathematics, developed at the Computer Science
+ * Department, University of Bologna, Italy.
+ * 
+ * HELM is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * 
+ * HELM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HELM; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA  02111-1307, USA.
+ * 
+ * For details, see the HELM World-Wide-Web page,
+ * http://cs.unibo.it/helm/.
+ *)
+
+(*  AUTOR: Ferruccio Guidi <fguidi@cs.unibo.it>
+ *)
+
+type connection
+
+val init  : string -> connection option
+
+val close : connection option -> unit
+
+val exec  : connection option -> string -> string list list
+
+val quote : string -> string
index 6f8a6f7ba5af27a48af61bdc80b97f0a6c668f19..0e6d7c2cccbbd415723f52e594d6893a3fbba733 100644 (file)
@@ -26,6 +26,8 @@
 (*  AUTOR: Ferruccio Guidi <fguidi@cs.unibo.it>
  *)
 
+type connection = Postgres.connection
+
 let init connection_string =
    try Some (new Postgres.connection connection_string)
    with _ -> raise (Failure ("MQIPostgres.init: " ^ connection_string))
index 342c91eaa551e9c50a54e25ea774e6f1922aa85f..8fa7acc3b0bc33f3df32bd550c90841b7f8db06a 100644 (file)
 (*  AUTOR: Ferruccio Guidi <fguidi@cs.unibo.it>
  *)
 
-val init  : string -> Postgres.connection option
+type connection
 
-val close : Postgres.connection option -> unit
+val init  : string -> connection option
 
-val exec  : Postgres.connection option -> string -> string list list
+val close : connection option -> unit
+
+val exec  : connection option -> string -> string list list
 
 val quote : string -> string
index 639fc6bb00f4baef2003dbcd3dcf60907d1deeba..0433afd5eb37fdd051be9136204a15e81f5ede6c 100644 (file)
@@ -27,7 +27,7 @@
  *)
 
 module M = MathQL
-module P = MQIPostgres
+module P = MQIDataBase
 module C = MQIConn
 module U = MQIUtil
 module A = MQIMap