1 (* Copyright (C) 2004-2005, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
33 ~host:(Helm_registry.get "db.host")
34 ~user:(Helm_registry.get "db.user")
35 ~database:(Helm_registry.get "db.database")
38 fun () -> Lazy.force dbd
41 let xpointer_RE = Pcre.regexp "#.*$"
42 let file_scheme_RE = Pcre.regexp "^file://"
44 let clean_owner_environment () =
45 let dbd = instance () in
46 let obj_tbl = MetadataTypes.obj_tbl () in
47 let sort_tbl = MetadataTypes.sort_tbl () in
48 let rel_tbl = MetadataTypes.rel_tbl () in
49 let name_tbl = MetadataTypes.name_tbl () in
50 let count_tbl = MetadataTypes.count_tbl () in
52 (obj_tbl,`RefObj) ; (sort_tbl,`RefSort) ; (rel_tbl,`RefRel) ;
53 (name_tbl,`ObjectName) ; (count_tbl,`Count) ]
56 (SqlStatements.drop_tables tbls) @ (SqlStatements.drop_indexes tbls)
61 with Mysql.Error _ as exn ->
62 match HMysql.errno dbd with
63 | Mysql.No_such_table -> []
68 let uri = Pcre.replace ~rex:xpointer_RE ~templ:"" uri in
72 HExtlib.safe_remove (Http_getter.resolve (uri ^ suffix))
73 with Http_getter_types.Key_not_found _ -> ())
74 [""; ".body"; ".types"])
76 List.iter (fun statement ->
78 ignore (HMysql.exec dbd statement)
79 with Mysql.Error _ as exn ->
80 match HMysql.errno dbd with
81 | Mysql.Bad_table_error
82 | Mysql.No_such_index | Mysql.No_such_table -> ()
87 let create_owner_environment () =
88 let dbd = instance () in
89 let obj_tbl = MetadataTypes.obj_tbl () in
90 let sort_tbl = MetadataTypes.sort_tbl () in
91 let rel_tbl = MetadataTypes.rel_tbl () in
92 let name_tbl = MetadataTypes.name_tbl () in
93 let count_tbl = MetadataTypes.count_tbl () in
95 (obj_tbl,`RefObj) ; (sort_tbl,`RefSort) ; (rel_tbl,`RefRel) ;
96 (name_tbl,`ObjectName) ; (count_tbl,`Count) ]
99 (SqlStatements.create_tables tbls) @ (SqlStatements.create_indexes tbls)
101 List.iter (fun statement ->
103 ignore (HMysql.exec dbd statement)
106 let status = HMysql.status dbd in
108 | Mysql.StatusError Mysql.Table_exists_error -> ()
109 | Mysql.StatusError Mysql.Dup_keyname -> ()
110 | Mysql.StatusError _ -> raise exn
115 (* removes uri from the ownerized tables, and returns the list of other objects
116 * (theyr uris) that ref the one removed.
117 * AFAIK there is no need to return it, since the MatitaTypes.staus should
118 * contain all defined objects. but to double check we do not garbage the
122 let obj_tbl = MetadataTypes.obj_tbl () in
123 let sort_tbl = MetadataTypes.sort_tbl () in
124 let rel_tbl = MetadataTypes.rel_tbl () in
125 let name_tbl = MetadataTypes.name_tbl () in
126 (*let conclno_tbl = MetadataTypes.conclno_tbl () in
127 let conclno_hyp_tbl = MetadataTypes.fullno_tbl () in*)
128 let count_tbl = MetadataTypes.count_tbl () in
130 let dbd = instance () in
131 let suri = UriManager.string_of_uri uri in
132 let query table suri = sprintf
133 "DELETE FROM %s WHERE source LIKE '%s%%'" table (HMysql.escape suri)
137 ignore (HMysql.exec dbd (query t suri))
139 exn -> raise exn (* no errors should be accepted *)
141 [obj_tbl;sort_tbl;rel_tbl;name_tbl;(*conclno_tbl;conclno_hyp_tbl*)count_tbl];
142 (* and now the debug job *)
144 sprintf "SELECT source FROM %s WHERE h_occurrence LIKE '%s%%'" obj_tbl
148 let rc = HMysql.exec dbd dbg_q in
150 HMysql.iter rc (fun a -> match a.(0) with None ->()|Some a -> l := a:: !l);
151 let l = List.sort Pervasives.compare !l in
154 exn -> raise exn (* no errors should be accepted *)
156 let xpointers_of_ind uri =
157 let dbd = instance () in
158 let name_tbl = MetadataTypes.name_tbl () in
160 "SELECT source FROM %s WHERE source LIKE '%s#xpointer%%'" name_tbl
161 (HMysql.escape (UriManager.string_of_uri uri))
163 let rc = HMysql.exec dbd query in
165 HMysql.iter rc (fun a -> match a.(0) with None ->()|Some a -> l := a:: !l);
166 List.map UriManager.uri_of_string !l