exception Error of string
-let prerr_endline s = ()(*HLog.debug s;;*)
+let prerr_endline s = () (*HLog.debug s*);;
let profiler = HExtlib.profile "Sqlite3"
(* attach the REGEX function *)
Sqlite3.create_fun2 db "REGEXP"
(fun s rex ->
+ try
match rex, s with
| Sqlite3.Data.TEXT rex, Sqlite3.Data.BLOB s
| Sqlite3.Data.TEXT rex, Sqlite3.Data.TEXT s ->
Sqlite3.Data.INT 1L
else
Sqlite3.Data.INT 0L
- | _ -> raise (Error "wrong types to 'REGEXP'"));
+ | _ -> raise (Error "wrong types to 'REGEXP'")
+ with exn -> HLog.error (Printexc.to_string exn); raise exn);
Some db
;;
;;
(* 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 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;
+ s_escaped
+;;
let string_of_rc = function
|Sqlite3.Rc.OK -> "Sqlite3.Rc.OK"
in
match rc with
| Sqlite3.Rc.OK -> !stored_result
- | _ -> raise (Error (string_of_rc rc))
+ | _ -> raise (Error (string_of_rc rc ^ ": " ^ Sqlite3.errmsg db ))
;;
let rec map res ~f =