From dd50d161ff273c1fb1f4eaca9a5b0eed54d4326d Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Thu, 19 Jul 2007 10:01:13 +0000 Subject: [PATCH] fixed an escaping error, added more infos to the generic error, callback catches and prints exceptions --- helm/software/components/hmysql/hSqlite3.ml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/helm/software/components/hmysql/hSqlite3.ml b/helm/software/components/hmysql/hSqlite3.ml index 3693e445b..d5c5f0fcc 100644 --- a/helm/software/components/hmysql/hSqlite3.ml +++ b/helm/software/components/hmysql/hSqlite3.ml @@ -43,7 +43,7 @@ type error_code = exception Error of string -let prerr_endline s = ()(*HLog.debug s;;*) +let prerr_endline s = () (*HLog.debug s*);; let profiler = HExtlib.profile "Sqlite3" @@ -77,6 +77,7 @@ let quick_connect (* 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 -> @@ -85,7 +86,8 @@ let quick_connect 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 ;; @@ -98,7 +100,13 @@ let disconnect 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" @@ -150,7 +158,7 @@ let exec s db = 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 = -- 2.39.2