- ignore (Sys.command cp_to_ram_cmd);
- let mv_to_disk_cmd _ =
- ignore (Sys.command ("mv " ^ tmp_db_name ^ " " ^ db_name))
- in
- at_exit mv_to_disk_cmd;
- Some (Sqlite3.db_open tmp_db_name)
+ let db = Sqlite3.db_open db_to_open in
+ (* attach the REGEX function *)
+ Sqlite3.create_fun2 db "REGEXP"
+ (fun s rex ->
+ match rex, s with
+ | Sqlite3.Data.TEXT rex, Sqlite3.Data.BLOB s
+ | Sqlite3.Data.TEXT rex, Sqlite3.Data.TEXT s ->
+ let r = Str.regexp rex in
+ if Str.string_match r s 0 then
+ Sqlite3.Data.INT 1L
+ else
+ Sqlite3.Data.INT 0L
+ | _ -> raise (Error "wrong types to 'REGEXP'"));
+ Some db