| Bad_table_error
| GENERIC_ERROR of string
-exception Error
+exception Error of string
let prerr_endline s = ()(*HLog.debug s;;*)
(* XXX hack, sqlite has a print "%q" that should be used, but is not bound *)
let escape s = Pcre.replace ~pat:"([^'])'([^'])" ~templ:"$1''$2" s
+let string_of_rc = function
+ |Sqlite3.Rc.OK -> "Sqlite3.Rc.OK"
+ |Sqlite3.Rc.ERROR -> "Sqlite3.Rc.ERROR"
+ |Sqlite3.Rc.INTERNAL -> "Sqlite3.Rc.INTERNAL"
+ |Sqlite3.Rc.PERM -> "Sqlite3.Rc.PERM"
+ |Sqlite3.Rc.ABORT -> "Sqlite3.Rc.ABORT"
+ |Sqlite3.Rc.BUSY -> "Sqlite3.Rc.BUSY"
+ |Sqlite3.Rc.LOCKED -> "Sqlite3.Rc.LOCKED"
+ |Sqlite3.Rc.NOMEM -> "Sqlite3.Rc.NOMEM"
+ |Sqlite3.Rc.READONLY -> "Sqlite3.Rc.READONLY"
+ |Sqlite3.Rc.INTERRUPT -> "Sqlite3.Rc.INTERRUPT"
+ |Sqlite3.Rc.IOERR -> "Sqlite3.Rc.IOERR"
+ |Sqlite3.Rc.CORRUPT -> "Sqlite3.Rc.CORRUPT"
+ |Sqlite3.Rc.NOTFOUND -> "Sqlite3.Rc.NOTFOUND"
+ |Sqlite3.Rc.FULL -> "Sqlite3.Rc.FULL"
+ |Sqlite3.Rc.CANTOPEN -> "Sqlite3.Rc.CANTOPEN"
+ |Sqlite3.Rc.PROTOCOL -> "Sqlite3.Rc.PROTOCOL"
+ |Sqlite3.Rc.EMPTY -> "Sqlite3.Rc.EMPTY"
+ |Sqlite3.Rc.SCHEMA -> "Sqlite3.Rc.SCHEMA"
+ |Sqlite3.Rc.TOOBIG -> "Sqlite3.Rc.TOOBIG"
+ |Sqlite3.Rc.CONSTRAINT -> "Sqlite3.Rc.CONSTRAINT"
+ |Sqlite3.Rc.MISMATCH -> "Sqlite3.Rc.MISMATCH"
+ |Sqlite3.Rc.MISUSE -> "Sqlite3.Rc.MISUSE"
+ |Sqlite3.Rc.NOFLS -> "Sqlite3.Rc.NOFLS"
+ |Sqlite3.Rc.AUTH -> "Sqlite3.Rc.AUTH"
+ |Sqlite3.Rc.FORMAT -> "Sqlite3.Rc.FORMAT"
+ |Sqlite3.Rc.RANGE -> "Sqlite3.Rc.RANGE"
+ |Sqlite3.Rc.NOTADB -> "Sqlite3.Rc.NOTADB"
+ |Sqlite3.Rc.ROW -> "Sqlite3.Rc.ROW"
+ |Sqlite3.Rc.DONE -> "Sqlite3.Rc.DONE"
+ |Sqlite3.Rc.UNKNOWN n ->
+ "Sqlite3.Rc.UNKNOWN " ^ string_of_int (Sqlite3.Rc.int_of_unknown n)
+;;
+
+let pp_rc rc = prerr_endline (string_of_rc rc);;
+
let exec db s =
prerr_endline s;
let stored_result = ref [] in
in
match rc with
| Sqlite3.Rc.OK -> !stored_result
- | _ -> raise Error
+ | _ -> raise (Error (string_of_rc rc))
;;
let rec map res ~f =
profiler.HExtlib.profile iter f
;;
-let pp_rc = function
- |Sqlite3.Rc.OK -> prerr_endline "Sqlite3.Rc.OK"
- |Sqlite3.Rc.ERROR -> prerr_endline "Sqlite3.Rc.ERROR"
- |Sqlite3.Rc.INTERNAL -> prerr_endline "Sqlite3.Rc.INTERNAL"
- |Sqlite3.Rc.PERM -> prerr_endline "Sqlite3.Rc.PERM"
- |Sqlite3.Rc.ABORT -> prerr_endline "Sqlite3.Rc.ABORT"
- |Sqlite3.Rc.BUSY -> prerr_endline "Sqlite3.Rc.BUSY"
- |Sqlite3.Rc.LOCKED -> prerr_endline "Sqlite3.Rc.LOCKED"
- |Sqlite3.Rc.NOMEM -> prerr_endline "Sqlite3.Rc.NOMEM"
- |Sqlite3.Rc.READONLY -> prerr_endline "Sqlite3.Rc.READONLY"
- |Sqlite3.Rc.INTERRUPT -> prerr_endline "Sqlite3.Rc.INTERRUPT"
- |Sqlite3.Rc.IOERR -> prerr_endline "Sqlite3.Rc.IOERR"
- |Sqlite3.Rc.CORRUPT -> prerr_endline "Sqlite3.Rc.CORRUPT"
- |Sqlite3.Rc.NOTFOUND -> prerr_endline "Sqlite3.Rc.NOTFOUND"
- |Sqlite3.Rc.FULL -> prerr_endline "Sqlite3.Rc.FULL"
- |Sqlite3.Rc.CANTOPEN -> prerr_endline "Sqlite3.Rc.CANTOPEN"
- |Sqlite3.Rc.PROTOCOL -> prerr_endline "Sqlite3.Rc.PROTOCOL"
- |Sqlite3.Rc.EMPTY -> prerr_endline "Sqlite3.Rc.EMPTY"
- |Sqlite3.Rc.SCHEMA -> prerr_endline "Sqlite3.Rc.SCHEMA"
- |Sqlite3.Rc.TOOBIG -> prerr_endline "Sqlite3.Rc.TOOBIG"
- |Sqlite3.Rc.CONSTRAINT -> prerr_endline "Sqlite3.Rc.CONSTRAINT"
- |Sqlite3.Rc.MISMATCH -> prerr_endline "Sqlite3.Rc.MISMATCH"
- |Sqlite3.Rc.MISUSE -> prerr_endline "Sqlite3.Rc.MISUSE"
- |Sqlite3.Rc.NOFLS -> prerr_endline "Sqlite3.Rc.NOFLS"
- |Sqlite3.Rc.AUTH -> prerr_endline "Sqlite3.Rc.AUTH"
- |Sqlite3.Rc.FORMAT -> prerr_endline "Sqlite3.Rc.FORMAT"
- |Sqlite3.Rc.RANGE -> prerr_endline "Sqlite3.Rc.RANGE"
- |Sqlite3.Rc.NOTADB -> prerr_endline "Sqlite3.Rc.NOTADB"
- |Sqlite3.Rc.ROW -> prerr_endline "Sqlite3.Rc.ROW"
- |Sqlite3.Rc.DONE -> prerr_endline "Sqlite3.Rc.DONE"
- |Sqlite3.Rc.UNKNOWN n ->
- prerr_endline
- ("Sqlite3.Rc.UNKNOWN " ^ string_of_int (Sqlite3.Rc.int_of_unknown n))
-;;
-
let errno = function
| None -> OK
| Some db ->