From: Enrico Tassi Date: Tue, 3 May 2005 14:37:30 +0000 (+0000) Subject: added DROP statements to sqlStatements X-Git-Tag: single_binding~113 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=5510cb3ef87e360d71d8b20593c6d3ee50e35d29;p=helm.git added DROP statements to sqlStatements --- diff --git a/helm/ocaml/metadata/sqlStatements.ml b/helm/ocaml/metadata/sqlStatements.ml index 0c51feba6..897e15489 100644 --- a/helm/ocaml/metadata/sqlStatements.ml +++ b/helm/ocaml/metadata/sqlStatements.ml @@ -4,49 +4,61 @@ type tbl = [ `RefObj| `RefSort| `RefRel| `ObjectName| `Owners| `Count] (* TABLES *) -let sprintf_refObj_format name = [sprintf " -CREATE TABLE %s ( +let sprintf_refObj_format name = [ +sprintf "CREATE TABLE %s ( source varchar(255) binary not null, h_occurrence varchar(255) binary not null, h_position varchar(255) binary not null, h_depth integer );" name] -let sprintf_refSort_format name = [sprintf " -CREATE TABLE %s ( +let sprintf_refSort_format name = [ +sprintf "CREATE TABLE %s ( source varchar(255) binary not null, h_position varchar(255) binary not null, h_depth integer not null, h_sort varchar(255) binary not null );" name] -let sprintf_refRel_format name = [sprintf " -CREATE TABLE %s ( +let sprintf_refRel_format name = [ +sprintf "CREATE TABLE %s ( source varchar(255) binary not null, h_position varchar(255) binary not null, h_depth integer not null );" name] -let sprintf_objectName_format name = [sprintf " -CREATE TABLE %s ( +let sprintf_objectName_format name = [ +sprintf "CREATE TABLE %s ( source varchar(255) binary not null, value varchar(255) binary not null );" name] -let sprintf_owners_format name = [sprintf " -CREATE TABLE %s ( +let sprintf_owners_format name = [ +sprintf "CREATE TABLE %s ( source varchar(255) binary not null, owner varchar(255) binary not null );" name] -let sprintf_count_format name = [sprintf " -CREATE TABLE %s ( +let sprintf_count_format name = [ +sprintf "CREATE TABLE %s ( source varchar(255) binary unique not null, conclusion smallint(6) not null, hypothesis smallint(6) not null, statement smallint(6) not null );" name] +let sprintf_refObj_drop name = [sprintf "DROP TABLE %s;" name] + +let sprintf_refSort_drop name = [sprintf "DROP TABLE %s;" name] + +let sprintf_refRel_drop name = [sprintf "DROP TABLE %s;" name] + +let sprintf_objectName_drop name = [sprintf "DROP TABLE %s;" name] + +let sprintf_owners_drop name = [sprintf "DROP TABLE %s;" name] + +let sprintf_count_drop name = [sprintf "DROP TABLE %s;" name] + (* INDEXES *) let sprintf_refObj_index name = [ @@ -71,9 +83,32 @@ sprintf "CREATE INDEX %s_conclusion ON %s (conclusion);" name name; sprintf "CREATE INDEX %s_hypothesis ON %s (hypothesis);" name name; sprintf "CREATE INDEX %s_statement ON %s (statement);" name name] - let sprintf_refRel_index name = [] +let sprintf_refObj_index_drop name = [ +sprintf "DROP INDEX %s_source ON %s;" name name ; +sprintf "DROP INDEX %s_target ON %s;" name name ; +sprintf "DROP INDEX %s_position ON %s;" name name ] + +let sprintf_refSort_index_drop name = [sprintf " +DROP INDEX %s_source ON %s; +" name name] + +let sprintf_objectName_index_drop name = [ +sprintf " DROP INDEX %s_value ON %s;" name name] + +let sprintf_owners_index_drop name = [ +sprintf "DROP INDEX %s_owner ON %s;" name name ; +sprintf "DROP INDEX %s_source ON %s;" name name] + +let sprintf_count_index_drop name = [ +sprintf "DROP INDEX %s_source ON %s;" name name; +sprintf "DROP INDEX %s_conclusion ON %s;" name name; +sprintf "DROP INDEX %s_hypothesis ON %s;" name name; +sprintf "DROP INDEX %s_statement ON %s;" name name] + +let sprintf_refRel_index_drop name = [] + (* FUNCTIONS *) let get_table_format t named = @@ -93,10 +128,35 @@ let get_index_format t named = | `ObjectName -> sprintf_objectName_index named | `Owners -> sprintf_owners_index named | `Count -> sprintf_count_index named + +let get_table_drop t named = + match t with + | `RefObj -> sprintf_refObj_drop named + | `RefSort -> sprintf_refSort_drop named + | `RefRel -> sprintf_refRel_drop named + | `ObjectName -> sprintf_objectName_drop named + | `Owners -> sprintf_owners_drop named + | `Count -> sprintf_count_drop named + +let get_index_drop t named = + match t with + | `RefObj -> sprintf_refObj_index_drop named + | `RefSort -> sprintf_refSort_index_drop named + | `RefRel -> sprintf_refRel_index_drop named + | `ObjectName -> sprintf_objectName_index_drop named + | `Owners -> sprintf_owners_index_drop named + | `Count -> sprintf_count_index_drop named let create_tables l = List.fold_left (fun s (name,table) -> s @ get_table_format table name) [] l let create_indexes l = List.fold_left (fun s (name,table) -> s @ get_index_format table name) [] l + +let drop_tables l = + List.fold_left (fun s (name,table) -> s @ get_table_drop table name) [] l + +let drop_indexes l = + List.fold_left (fun s (name,table) -> s @ get_index_drop table name) [] l + diff --git a/helm/ocaml/metadata/sqlStatements.mli b/helm/ocaml/metadata/sqlStatements.mli index d73215134..05fec142c 100644 --- a/helm/ocaml/metadata/sqlStatements.mli +++ b/helm/ocaml/metadata/sqlStatements.mli @@ -5,3 +5,7 @@ val create_tables: (string * tbl) list -> string list val create_indexes: (string * tbl) list -> string list +val drop_tables: (string * tbl) list -> string list + +val drop_indexes: (string * tbl) list -> string list + diff --git a/helm/ocaml/metadata/table_creator/Makefile b/helm/ocaml/metadata/table_creator/Makefile index 8b08e6d51..3368e5229 100644 --- a/helm/ocaml/metadata/table_creator/Makefile +++ b/helm/ocaml/metadata/table_creator/Makefile @@ -3,18 +3,25 @@ REQUIRES = mysql helm-metadata INTERFACE_FILES = IMPLEMENTATION_FILES = $(INTERFACE_FILES:%.mli=%.ml) EXTRA_OBJECTS_TO_INSTALL = -EXTRA_OBJECTS_TO_CLEAN =table_creator table_creator.opt +EXTRA_OBJECTS_TO_CLEAN = \ + table_creator table_creator.opt table_destructor table_destructor.opt -all: table_creator -opt: table_creator.opt +all: table_creator table_destructor +opt: table_creator.opt table_destructor.opt table_creator: table_creator.ml $(OCAMLFIND) ocamlc \ -thread -package mysql,helm-metadata -linkpkg -o $@ $< +table_destructor: table_creator + ln -f $< $@ + table_creator.opt: table_creator.ml $(OCAMLFIND) ocamlopt \ -thread -package mysql,helm-metadata -linkpkg -o $@ $< + +table_destructor.opt: table_creator.opt + ln -f $< $@ include ../../Makefile.common include .depend diff --git a/helm/ocaml/metadata/table_creator/table_creator.ml b/helm/ocaml/metadata/table_creator/table_creator.ml index 4eb84ad74..6cd9da9bf 100644 --- a/helm/ocaml/metadata/table_creator/table_creator.ml +++ b/helm/ocaml/metadata/table_creator/table_creator.ml @@ -23,6 +23,13 @@ let parse_args l = assert (len = 1 || len = 2); if len = 1 then (s,s) else (List.nth parts 0, List.nth parts 1)) l + +let destructor_RE = Str.regexp "table_destructor\\(\\|\\.opt\\)$" + +let am_i_destructor () = + try + let _ = Str.search_forward destructor_RE Sys.argv.(0) 0 in true + with Not_found -> false let main () = let len = Array.length Sys.argv in @@ -33,13 +40,19 @@ let main () = end else begin + let tab,idx = + if am_i_destructor () then + (SqlStatements.drop_tables,SqlStatements.drop_indexes) + else + (SqlStatements.create_tables,SqlStatements.create_indexes) + in let from, index = if Sys.argv.(1) = "-index" then 2,true else 1,false in let todo = Array.to_list (Array.sub Sys.argv from (len - from)) in let todo = parse_args todo in let todo = List.map (fun (x,name) -> name, (List.assoc x map)) todo in - print_endline (String.concat "\n" (SqlStatements.create_tables todo)); + print_endline (String.concat "\n" (tab todo)); if index then - print_endline (String.concat "\n" (SqlStatements.create_indexes todo)) + print_endline (String.concat "\n" (idx todo)) end let _ = main ()