]> matita.cs.unibo.it Git - helm.git/commitdiff
better debug printings
authorEnrico Tassi <enrico.tassi@inria.fr>
Sat, 8 Sep 2007 23:40:46 +0000 (23:40 +0000)
committerEnrico Tassi <enrico.tassi@inria.fr>
Sat, 8 Sep 2007 23:40:46 +0000 (23:40 +0000)
components/hmysql/hSqlite3.ml

index 0038c650f7406db53fc12e08e9fe0e138a29ac34..b8687c5e9e20e85ce89a3f8a96c06e0508007519 100644 (file)
 type result = Mysql.result option
 *)
 
+
+let debug = false
+let debug_print = 
+  if debug then prerr_endline else (fun _ ->())
+;;
+
 type result = Sqlite3.row list
 type dbd = Sqlite3.db option
 
@@ -43,8 +49,6 @@ type error_code =
 
 exception Error of string
 
-let prerr_endline s = () (*HLog.debug s*);;
-
 let profiler = HExtlib.profile "Sqlite3"
 
 let quick_connect 
@@ -60,20 +64,21 @@ let quick_connect
     let files = HExtlib.find ~test:(Pcre.pmatch ~pat:(base^"[0-9]+")) root in
     let rec aux = function
       | [] -> 
-         HLog.debug ("HSqlite3: no valid db files found in memory");
+         debug_print ("HSqlite3: no valid db files found in memory");
          let name = root ^ base ^ string_of_int (Unix.getpid ()) in
-         HLog.debug ("HSqlite3: memory db file name: "^name);
+         debug_print ("HSqlite3: memory db file name: "^name);
          name, true
       | x::tl -> 
-         HLog.debug ("HSqlite3: found a .db in memory: " ^ x);
+         debug_print ("HSqlite3: found a .db in memory: " ^ x);
          match Array.to_list (Pcre.extract ~pat:"\\.([0-9]+)$" x) with
          | [] | _::_::_::_ -> assert false
          | [_;p] when HExtlib.is_dir ("/proc/" ^ p) -> 
-            HLog.debug ("HSqlite3: found valid db file: " ^ x);
+            debug_print ("HSqlite3: found valid db file: " ^ x);
             x, false
          | _ ->
             HLog.warn ("HSqlite3: dead process db file found: " ^ x);
-            HLog.warn ("HSqlite3: ignoring: " ^ x);
+            HLog.warn ("HSqlite3: removing: " ^ x);
+            ignore (Sys.command ("rm " ^ x));
             aux tl
     in
       aux files
@@ -87,11 +92,11 @@ let quick_connect
       let cp_to_ram_cmd = "cp " ^ db_name ^ " " ^ tmp_db_name in
       if first_time then 
         if HExtlib.is_regular db_name then ignore (Sys.command cp_to_ram_cmd)
-        else HLog.debug ("HSqlite3: no initial db: " ^ db_name)
-      else HLog.debug "HSqlite3: not copying the db, already in memory";
+        else debug_print ("HSqlite3: no initial db: " ^ db_name)
+      else debug_print "HSqlite3: not copying the db, already in memory";
       let mv_to_disk_cmd _ = 
         if first_time then ignore (Sys.command ("mv "^tmp_db_name^" "^db_name)) 
-        else HLog.debug "HSqlite3: not copying back the db"
+        else debug_print "HSqlite3: not copying back the db"
       in
       at_exit mv_to_disk_cmd;
       tmp_db_name)
@@ -121,15 +126,15 @@ let disconnect db =
   | None -> ()
   | Some db -> 
       let b = Sqlite3.db_close db in
-      if b=false then prerr_endline "No Closed DataBase"
+      if b=false then debug_print "No Closed DataBase"
 ;;
 
 (* XXX hack, sqlite has a print "%q" that should be used, but is not bound *)
 let escape s = 
   let s_escaped = Pcre.replace ~pat:"'" ~templ:"''" s in
   (*let s_escaped = Pcre.replace ~pat:"([^'])'([^'])" ~templ:"$1''$2" s in*)
-  prerr_endline s;
-  prerr_endline s_escaped;
+  debug_print s;
+  debug_print s_escaped;
   s_escaped
 ;;
 
@@ -167,10 +172,10 @@ let string_of_rc = function
     "Sqlite3.Rc.UNKNOWN " ^ string_of_int (Sqlite3.Rc.int_of_unknown n)
 ;;
 
-let pp_rc rc = prerr_endline (string_of_rc rc);;
+let pp_rc rc = debug_print (string_of_rc rc);;
 
 let exec s db =
prerr_endline s;
debug_print s;
   let stored_result = ref [] in
   let store row =
     stored_result := row :: !stored_result