]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/matita/matitaDb.ml
ocaml 3.09 transition
[helm.git] / helm / matita / matitaDb.ml
index 17aac37450cf091faad1fbaced5d1589eb89f408..e3c7041ddadd927d4f6b86fe0b0e4e3d0c42b306 100644 (file)
@@ -27,7 +27,7 @@ open Printf ;;
 
 let instance =
   let dbd = lazy (
-    Mysql.quick_connect
+    HMysql.quick_connect
       ~host:(Helm_registry.get "db.host")
       ~user:(Helm_registry.get "db.user")
       ~database:(Helm_registry.get "db.database")
@@ -37,6 +37,7 @@ let instance =
 
 
 let xpointer_RE = Pcre.regexp "#.*$"
+let file_scheme_RE = Pcre.regexp "^file://"
 
 let clean_owner_environment () =
   let dbd = instance () in
@@ -57,7 +58,7 @@ let clean_owner_environment () =
     try
       MetadataDb.clean ~dbd
     with Mysql.Error _ as exn ->
-      match Mysql.errno dbd with 
+      match HMysql.errno dbd with 
       | Mysql.No_such_table -> []
       | _ -> raise exn
   in
@@ -65,17 +66,17 @@ let clean_owner_environment () =
     (fun uri ->
       let uri = Pcre.replace ~rex:xpointer_RE ~templ:"" uri in
       List.iter
-        (fun suffix -> 
-          (*prerr_endline ("unregistering " ^ uri ^ suffix);*)
-          Http_getter.unregister (uri ^ suffix))
-        
+        (fun suffix ->
+          try
+           MatitaMisc.safe_remove (Http_getter.resolve (uri ^ suffix))
+          with Http_getter_types.Key_not_found _ -> ())
         [""; ".body"; ".types"])
     owned_uris;
   List.iter (fun statement -> 
     try
-      ignore (Mysql.exec dbd statement)
+      ignore (HMysql.exec dbd statement)
     with Mysql.Error _ as exn ->
-      match Mysql.errno dbd with 
+      match HMysql.errno dbd with 
       | Mysql.Bad_table_error 
       | Mysql.No_such_index | Mysql.No_such_table -> () 
       | _ -> raise exn
@@ -98,12 +99,13 @@ let create_owner_environment () =
   in
   List.iter (fun statement -> 
     try
-      ignore (Mysql.exec dbd statement)
+      ignore (HMysql.exec dbd statement)
     with
       exn -> 
-         let status = Mysql.status dbd in
+         let status = HMysql.status dbd in
          match status with 
          | Mysql.StatusError Mysql.Table_exists_error -> ()
+         | Mysql.StatusError Mysql.Dup_keyname -> ()
          | Mysql.StatusError _ -> raise exn
          | _ -> ()
       ) statements
@@ -127,11 +129,11 @@ let remove_uri uri =
   let dbd = instance () in
   let suri = UriManager.string_of_uri uri in 
   let query table suri = sprintf 
-    "DELETE FROM %s WHERE source LIKE '%s%%'" table (Mysql.escape suri)
+    "DELETE FROM %s WHERE source LIKE '%s%%'" table (HMysql.escape suri)
   in
   List.iter (fun t -> 
     try 
-      ignore (Mysql.exec dbd (query t suri))
+      ignore (HMysql.exec dbd (query t suri))
     with
       exn -> raise exn (* no errors should be accepted *)
     )
@@ -139,14 +141,14 @@ let remove_uri uri =
   (* and now the debug job *)  
   let dbg_q = 
     sprintf "SELECT source FROM %s WHERE h_occurrence LIKE '%s%%'" obj_tbl
-    (Mysql.escape suri)
+    (HMysql.escape suri)
   in
   try 
-    let rc = Mysql.exec dbd dbg_q in
+    let rc = HMysql.exec dbd dbg_q in
     let l = ref [] in
-    Mysql.iter rc (fun a -> match a.(0) with None ->()|Some a -> l := a:: !l);
+    HMysql.iter rc (fun a -> match a.(0) with None ->()|Some a -> l := a:: !l);
     let l = List.sort Pervasives.compare !l in
-    MatitaMisc.list_uniq l
+    HExtlib.list_uniq l
   with
     exn -> raise exn (* no errors should be accepted *)
 
@@ -155,9 +157,10 @@ let xpointers_of_ind uri =
   let name_tbl =  MetadataTypes.name_tbl () in
   let query = sprintf 
     "SELECT source FROM %s WHERE source LIKE '%s#xpointer%%'" name_tbl 
-      (Mysql.escape (UriManager.string_of_uri uri))
+      (HMysql.escape (UriManager.string_of_uri uri))
   in
-  let rc = Mysql.exec dbd query in
+  let rc = HMysql.exec dbd query in
   let l = ref [] in
-  Mysql.iter rc (fun a ->  match a.(0) with None ->()|Some a -> l := a:: !l);
+  HMysql.iter rc (fun a ->  match a.(0) with None ->()|Some a -> l := a:: !l);
   List.map UriManager.uri_of_string !l
+