X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=components%2Fhmysql%2FhMysql.ml;h=b9ace8e8321a9a38275002c6bdb383a8e86a27ef;hb=24dd4569daf1d35bffaa813b8164058d8643f14d;hp=94f3efe03fb97b2bc80f596534fbc3878aebb92d;hpb=7f2444c2670cadafddd8785b687ef312158376b0;p=helm.git diff --git a/components/hmysql/hMysql.ml b/components/hmysql/hMysql.ml index 94f3efe03..b9ace8e83 100644 --- a/components/hmysql/hMysql.ml +++ b/components/hmysql/hMysql.ml @@ -27,22 +27,24 @@ type dbd = Mysql.dbd option type result = Mysql.result option -type error_code = Mysql.error_code +type error_code = + | OK + | Table_exists_error + | Dup_keyname + | No_such_table + | No_such_index + | Bad_table_error + | GENERIC_ERROR of string +exception Error of string let profiler = HExtlib.profile "mysql" -let use_real_db () = - not (Helm_registry.get_opt_default Helm_registry.bool - ~default:false "db.nodb") - let quick_connect ?host ?database ?port ?password ?user () = profiler.HExtlib.profile - (fun () -> - if use_real_db () then - (Some (Mysql.quick_connect ?host ?database ?port ?password ?user ())) - else - None) + (fun () -> + Some (Mysql.quick_connect ?host ?database ?port ?password ?user ())) () +;; let disconnect = function | None -> () @@ -51,10 +53,13 @@ let disconnect = function let escape s = profiler.HExtlib.profile Mysql.escape s -let exec dbd s = +let exec s dbd = match dbd with | None -> None - | Some dbd -> Some (profiler.HExtlib.profile (Mysql.exec dbd) s) + | Some dbd -> + try + Some (profiler.HExtlib.profile (Mysql.exec dbd) s) + with Mysql.Error s -> raise (Error s) let map res ~f = match res with @@ -65,16 +70,23 @@ let map res ~f = let iter res ~f = match res with - | None -> () + | None -> () | Some res -> let iter f = Mysql.iter res ~f in profiler.HExtlib.profile iter f let errno = function - | None -> Mysql.Connection_error - | Some dbd -> profiler.HExtlib.profile Mysql.errno dbd + | None -> GENERIC_ERROR "Mysql.Connection_error" + | Some dbd -> + match Mysql.errno dbd with + | Mysql.No_such_table -> No_such_table + | Mysql.Table_exists_error -> Table_exists_error + | Mysql.Dup_keyname -> Dup_keyname + | Mysql.No_such_index -> No_such_index + | Mysql.Bad_table_error -> Bad_table_error + | _ -> GENERIC_ERROR "Mysql_generic_error" +;; -let status = function - | None -> Mysql.StatusError Mysql.Connection_error - | Some dbd -> profiler.HExtlib.profile Mysql.status dbd +let isMysql = true +let escape_string_for_like = ("ESCAPE \"\\\\\"" : ('a,'b,'c,'a) format4);;