From 5d5a1108d6c8198fc8425b914db803009941785a Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Tue, 29 May 2007 16:22:49 +0000 Subject: [PATCH] hSqlite3.ml used create_fun_2 to define REGEXP. this functions is not official, patch sent upstream --- components/hmysql/hSqlite3.ml | 24 +++++++++++++++++++----- components/library/libraryClean.ml | 27 +++++++++++++++++---------- matita/Makefile | 12 ++++-------- 3 files changed, 40 insertions(+), 23 deletions(-) diff --git a/components/hmysql/hSqlite3.ml b/components/hmysql/hSqlite3.ml index 80c939ac8..da14a2f3f 100644 --- a/components/hmysql/hSqlite3.ml +++ b/components/hmysql/hSqlite3.ml @@ -51,16 +51,17 @@ let quick_connect ?host ?(database = "sqlite") ?port ?password ?user () = let username = Helm_registry.get "user.name" in let tmp_db_name = if HExtlib.is_dir "/dev/shm/" && HExtlib.writable_dir "/dev/shm/" then - (HLog.debug "using /dev/shm to store the working copy of the db"; + ((*HLog.debug "using /dev/shm to store the working copy of the db";*) "/dev/shm/matita.db." ^ username ^ "." ^ string_of_int (Unix.getpid ())) else - (HLog.debug "/dev/shm not available"; + ((*HLog.debug "/dev/shm not available";*) Helm_registry.get "matita.basedir" ^ "/matita.db." ^ username ^ "." ^ string_of_int (Unix.getpid ())) in let db_name = Helm_registry.get "matita.basedir" ^ "/" ^ database ^ ".db" in - (* XXX big hack XXX *) - let standard_db_name = "/usr/share/matita/metadata.db" in + let standard_db_name = + Helm_registry.get "matita.rt_base_dir" ^ "/metadata.db" + in let cp_to_ram_cmd = if HExtlib.is_regular db_name then "cp " ^ db_name ^ " " ^ tmp_db_name @@ -73,7 +74,20 @@ let quick_connect ?host ?(database = "sqlite") ?port ?password ?user () = 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 tmp_db_name in + (* attach the REGEX function *) + Sqlite3.create_fun_2 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 ;; let disconnect db = diff --git a/components/library/libraryClean.ml b/components/library/libraryClean.ml index 54aa860c9..46e2dd18c 100644 --- a/components/library/libraryClean.ml +++ b/components/library/libraryClean.ml @@ -51,17 +51,20 @@ let one_step_depend suri = let buri = buri ^ "/" in let buri = HSql.escape buri in let obj_tbl = MetadataTypes.obj_tbl () in - if HSql.isMysql then - sprintf ("SELECT source, h_occurrence FROM %s WHERE " - ^^ "h_occurrence REGEXP '^%s[^/]*$'") obj_tbl buri - else - begin + if HSql.isMysql then + sprintf ("SELECT source, h_occurrence FROM %s WHERE " + ^^ "h_occurrence REGEXP '^%s[^/]*$'") obj_tbl buri + else + begin + sprintf ("SELECT source, h_occurrence FROM %s WHERE " + ^^ "REGEXP(h_occurrence, '^%s[^/]*$')") obj_tbl buri + (* implementation with vanilla ocaml-sqlite3 HLog.debug "Warning SELECT without REGEXP"; - sprintf - ("SELECT source, h_occurrence FROM %s WHERE " ^^ - "h_occurrence LIKE '%s%%'") - obj_tbl buri - end + sprintf + ("SELECT source, h_occurrence FROM %s WHERE " ^^ + "h_occurrence LIKE '%s%%'") + obj_tbl buri*) + end in try let rc = HSql.exec (LibraryDb.instance ()) query in @@ -94,11 +97,15 @@ let db_uris_of_baseuri buri = ^^ "source REGEXP '^%s[^/]*$'") obj_tbl buri else begin + sprintf ("SELECT source FROM %s WHERE " + ^^ "REGEXP(source, '^%s[^/]*$')") obj_tbl buri + (* implementation with vanilla ocaml-sqlite3 HLog.debug "Warning SELECT without REGEXP"; sprintf ("SELECT source, h_occurrence FROM %s WHERE " ^^ "h_occurrence LIKE '%s%%'") obj_tbl buri + *) end in try diff --git a/matita/Makefile b/matita/Makefile index 97158f9dd..81e67db64 100644 --- a/matita/Makefile +++ b/matita/Makefile @@ -84,16 +84,12 @@ MAINCMOS = $(MAINCML:%.ml=%.cmo) CMXS = $(patsubst %.cmo,%.cmx,$(CMOS)) CCMXS = $(patsubst %.cmo,%.cmx,$(CCMOS)) MAINCMXS = $(patsubst %.cmo,%.cmx,$(MAINCMOS)) -$(CMOS): $(LIB_DEPS) +$(CMOS) : $(LIB_DEPS) $(CMXOS): $(LIBX_DEPS) -ifeq ($(MAKECMDGOALS),all) - $(CMOS:%.cmo=%.cmi): $(LIB_DEPS) -endif -ifeq ($(MAKECMDGOALS),) - $(CMOS:%.cmo=%.cmi): $(LIB_DEPS) -endif ifeq ($(MAKECMDGOALS),opt) - $(CMOS:%.cmo=%.cmi): $(LIBX_DEPS) + $(MLI:%.mli=%.cmi): $(LIBX_DEPS) +else + $(MLI:%.mli=%.cmi): $(LIB_DEPS) endif LIB_DEPS := $(shell $(OCAMLFIND) query -recursive -predicates "byte" -format "%d/%a" $(MATITA_REQUIRES)) -- 2.39.2