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 exec dbd s =
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
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);;