From: Claudio Sacerdoti Coen Date: Tue, 24 Feb 2004 14:50:11 +0000 (+0000) Subject: Quick patch to make everything work with MySql. X-Git-Tag: v0_0_4~92 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=b5503c72c5560e8da3337e99bf058f0caab350e8;p=helm.git Quick patch to make everything work with MySql. Note: to compile you need to make a symbolic link from mQIDataBase.ml to mQIPostgres.ml or mQIMySql.ml --- diff --git a/helm/ocaml/mathql_interpreter/.depend b/helm/ocaml/mathql_interpreter/.depend index 7d9b3c625..c9d883b21 100644 --- a/helm/ocaml/mathql_interpreter/.depend +++ b/helm/ocaml/mathql_interpreter/.depend @@ -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 diff --git a/helm/ocaml/mathql_interpreter/Makefile b/helm/ocaml/mathql_interpreter/Makefile index 88c66ac8e..f6f655d28 100644 --- a/helm/ocaml/mathql_interpreter/Makefile +++ b/helm/ocaml/mathql_interpreter/Makefile @@ -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 \ diff --git a/helm/ocaml/mathql_interpreter/mQIConn.ml b/helm/ocaml/mathql_interpreter/mQIConn.ml index d0dedf143..4e27c9782 100644 --- a/helm/ocaml/mathql_interpreter/mQIConn.ml +++ b/helm/ocaml/mathql_interpreter/mQIConn.ml @@ -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 diff --git a/helm/ocaml/mathql_interpreter/mQIConn.mli b/helm/ocaml/mathql_interpreter/mQIConn.mli index b83453ae9..fba3d4263 100644 --- a/helm/ocaml/mathql_interpreter/mQIConn.mli +++ b/helm/ocaml/mathql_interpreter/mQIConn.mli @@ -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 index 000000000..8fa7acc3b --- /dev/null +++ b/helm/ocaml/mathql_interpreter/mQIDataBase.mli @@ -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 + *) + +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 index 000000000..f5d30d1ed --- /dev/null +++ b/helm/ocaml/mathql_interpreter/mQIMySql.ml @@ -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 + *) + +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 index 000000000..8fa7acc3b --- /dev/null +++ b/helm/ocaml/mathql_interpreter/mQIMySql.mli @@ -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 + *) + +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/mQIPostgres.ml b/helm/ocaml/mathql_interpreter/mQIPostgres.ml index 6f8a6f7ba..0e6d7c2cc 100644 --- a/helm/ocaml/mathql_interpreter/mQIPostgres.ml +++ b/helm/ocaml/mathql_interpreter/mQIPostgres.ml @@ -26,6 +26,8 @@ (* AUTOR: Ferruccio Guidi *) +type connection = Postgres.connection + let init connection_string = try Some (new Postgres.connection connection_string) with _ -> raise (Failure ("MQIPostgres.init: " ^ connection_string)) diff --git a/helm/ocaml/mathql_interpreter/mQIPostgres.mli b/helm/ocaml/mathql_interpreter/mQIPostgres.mli index 342c91eaa..8fa7acc3b 100644 --- a/helm/ocaml/mathql_interpreter/mQIPostgres.mli +++ b/helm/ocaml/mathql_interpreter/mQIPostgres.mli @@ -26,10 +26,12 @@ (* AUTOR: Ferruccio Guidi *) -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 diff --git a/helm/ocaml/mathql_interpreter/mQIProperty.ml b/helm/ocaml/mathql_interpreter/mQIProperty.ml index 639fc6bb0..0433afd5e 100644 --- a/helm/ocaml/mathql_interpreter/mQIProperty.ml +++ b/helm/ocaml/mathql_interpreter/mQIProperty.ml @@ -27,7 +27,7 @@ *) module M = MathQL -module P = MQIPostgres +module P = MQIDataBase module C = MQIConn module U = MQIUtil module A = MQIMap