]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/library/libraryDb.ml
Bug fixed: name in letin was printed as "previous" even if given.
[helm.git] / helm / software / components / library / libraryDb.ml
index d3e7e9831b39977da16e2ea1e40338d2b38fff6d..e6af1eb814bf198e3f3d714eca0556450fbfdc63 100644 (file)
@@ -29,7 +29,7 @@ open Printf ;;
 
 let instance =
   let dbd = lazy (
-    HMysql.quick_connect
+    HSql.quick_connect
       ~host:(Helm_registry.get "db.host")
       ~user:(Helm_registry.get "db.user")
       ~database:(Helm_registry.get "db.database")
@@ -58,9 +58,9 @@ let clean_owner_environment () =
   let owned_uris =
     try
       MetadataDb.clean ~dbd
-    with Mysql.Error _ as exn ->
-      match HMysql.errno dbd with 
-      | Mysql.No_such_table -> []
+    with (HSql.Error _) as exn ->
+      match HSql.errno dbd with 
+      | HSql.No_such_table -> []
       | _ -> raise exn
   in
   List.iter
@@ -76,11 +76,12 @@ let clean_owner_environment () =
     owned_uris;
   List.iter (fun statement -> 
     try
-      ignore (HMysql.exec dbd statement)
-    with Mysql.Error _ as exn ->
-      match HMysql.errno dbd with 
-      | Mysql.Bad_table_error 
-      | Mysql.No_such_index | Mysql.No_such_table -> () 
+      ignore (HSql.exec dbd statement)
+    with (HSql.Error _) as exn ->
+      match HSql.errno dbd with 
+      | HSql.No_such_table
+      | HSql.Bad_table_error
+      | HSql.No_such_index -> prerr_endline statement; ()
       | _ -> raise exn
     ) statements;
 ;;
@@ -113,15 +114,19 @@ let create_owner_environment () =
   in
   List.iter (fun statement -> 
     try
-      ignore (HMysql.exec dbd statement)
+      ignore (HSql.exec dbd statement)
     with
-      exn -> 
-         let status = HMysql.status dbd in
-         match status with 
-         | Mysql.StatusError Mysql.Table_exists_error -> ()
-         | Mysql.StatusError Mysql.Dup_keyname -> ()
-         | Mysql.StatusError _ -> raise exn
-         | _ -> ()
+      (HSql.Error _) as exc -> 
+      let status = HSql.errno dbd in 
+      match status with 
+      | HSql.Table_exists_error -> ()
+      | HSql.Dup_keyname -> ()
+      | HSql.GENERIC_ERROR _ -> 
+          prerr_endline statement;
+          raise exc
+      | _ -> ()
+
+
       ) statements
 ;;
 
@@ -142,12 +147,14 @@ let remove_uri uri =
   
   let dbd = instance () in
   let suri = UriManager.string_of_uri uri in 
-  let query table suri = sprintf 
-    "DELETE QUICK LOW_PRIORITY FROM %s WHERE source='%s'" table (HMysql.escape suri)
+  let query table suri = 
+    if HSql.isMysql then 
+      sprintf "DELETE QUICK LOW_PRIORITY FROM %s WHERE source='%s'" table (HSql.escape suri)
+    else sprintf "DELETE FROM %s WHERE source='%s'" table (HSql.escape suri)
   in
   List.iter (fun t -> 
     try 
-      ignore (HMysql.exec dbd (query t suri))
+      ignore (HSql.exec dbd (query t suri))
     with
       exn -> raise exn (* no errors should be accepted *)
     )
@@ -157,12 +164,16 @@ let remove_uri uri =
 let xpointers_of_ind uri =
   let dbd = instance () in
   let name_tbl =  MetadataTypes.name_tbl () in
+  let escape s =
+    Pcre.replace ~pat:"([^\\\\])_" ~templ:"$1\\_" (HSql.escape s)
+  in
   let query = sprintf 
-    "SELECT source FROM %s WHERE source LIKE '%s#xpointer%%'" name_tbl 
-      (HMysql.escape (UriManager.string_of_uri uri))
+    ("SELECT source FROM %s WHERE source LIKE '%s#xpointer%%' "
+     ^^ HSql.escape_string_for_like)
+    name_tbl (escape (UriManager.string_of_uri uri))
   in
-  let rc = HMysql.exec dbd query in
+  let rc = HSql.exec dbd query in
   let l = ref [] in
-  HMysql.iter rc (fun a ->  match a.(0) with None ->()|Some a -> l := a:: !l);
+  HSql.iter rc (fun a ->  match a.(0) with None ->()|Some a -> l := a:: !l);
   List.map UriManager.uri_of_string !l