1 (* Copyright (C) 2004, 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/
30 let prepare_insert () =
31 let insert_owner a b =
32 sprintf "INSERT %s VALUES (\"%s\", \"%s\")" owners_tbl a b
34 let insert_sort a b c d =
35 sprintf "INSERT %s VALUES (\"%s\", \"%s\", %d, \"%s\")" sort_tbl a b c d
37 let insert_rel a b c =
38 sprintf "INSERT %s VALUES (\"%s\", \"%s\", %d)" rel_tbl a b c
40 let insert_obj a b c d =
41 sprintf "INSERT %s VALUES (\"%s\", \"%s\", \"%s\", %s)" obj_tbl a b c d
43 (insert_owner, insert_sort, insert_rel, insert_obj)
45 let execute_insert dbd (insert_owner, insert_sort, insert_rel, insert_obj)
46 uri owner (sort_cols, rel_cols, obj_cols)
48 ignore (Mysql.exec dbd (insert_owner uri owner));
50 | [`String a; `String b; `Int c; `String d] ->
51 ignore (Mysql.exec dbd (insert_sort a b c d))
55 | [`String a; `String b; `Int c] ->
56 ignore (Mysql.exec dbd (insert_rel a b c))
60 | [`String a; `String b; `String c; `Int d] ->
61 ignore (Mysql.exec dbd (insert_obj a b c (string_of_int d)))
62 | [`String a; `String b; `String c; `Null] ->
63 ignore (Mysql.exec dbd (insert_obj a b c "NULL"))
67 let insert_const_no dbd uri =
69 sprintf "INSERT %s SELECT \"%s\", COUNT(DISTINCT h_occurrence) FROM %s WHERE (h_position=\"%s\" OR h_position=\"%s\") AND source LIKE \"%s%%\""
70 conclno_tbl uri obj_tbl inconcl_pos mainconcl_pos uri
74 SELECT \"%s\",COUNT(DISTINCT h_occurrence)
76 WHERE NOT (h_position=\"%s\") AND (source = \"%s\")"
77 conclno_hyp_tbl uri obj_tbl inbody_pos uri
79 ignore (Mysql.exec dbd inconcl_no);
80 ignore (Mysql.exec dbd concl_hyp)
82 let insert_name ~dbd ~uri ~name =
84 sprintf "INSERT %s VALUES (\"%s\", \"%s\")" name_tbl uri name
86 ignore (Mysql.exec dbd query)
89 MetadataPp.t list list * MetadataPp.t list list * MetadataPp.t list list
91 let index_constant ~dbd =
92 let query = prepare_insert () in
93 fun ~owner ~uri ~body ~ty ->
94 let name = UriManager.name_of_uri uri in
95 let uri = UriManager.string_of_uri uri in
96 let metadata = MetadataExtractor.compute ~body ~ty in
97 let columns = MetadataPp.columns_of_metadata ~about:uri metadata in
98 execute_insert dbd query uri owner (columns :> columns);
99 insert_const_no dbd uri;
100 insert_name ~dbd ~uri ~name
102 let index_inductive_def ~dbd =
103 let query = prepare_insert () in
104 fun ~owner ~uri ~types ->
105 let metadata = MetadataExtractor.compute_ind ~uri ~types in
106 let uri_of (a,b,c) = a in
107 let uris = UriManager.string_of_uri uri :: List.map uri_of metadata in
108 let uri = UriManager.string_of_uri uri in
109 let columns = MetadataPp.columns_of_ind_metadata metadata in
110 execute_insert dbd query uri owner (columns :> columns);
111 List.iter (insert_const_no dbd) uris;
112 List.iter (fun (uri, name, _) -> insert_name ~dbd ~uri ~name) metadata
114 let clean ~(dbd:Mysql.dbd) ~owner =
115 let owned_uris = (* list of uris in list-of-columns format *)
117 sprintf "SELECT source FROM %s WHERE owner = \"%s\"" owners_tbl owner
119 let result = Mysql.exec dbd query in
120 Mysql.map result (fun cols ->
123 | None -> assert false)
126 let query s = sprintf "DELETE FROM %s WHERE source LIKE \"%s%%\"" tbl s in
128 (fun source_col -> ignore (Mysql.exec dbd (query source_col)))
132 [sort_tbl; rel_tbl; obj_tbl; conclno_tbl; conclno_hyp_tbl; name_tbl;