From c5abd4206112221708a06dbb1bb9df1eb38a451c Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Tue, 3 May 2005 13:39:34 +0000 Subject: [PATCH] added table_creator (comman line frontend to SqlStatements) --- helm/ocaml/metadata/table_creator/.depend | 4 ++ helm/ocaml/metadata/table_creator/Makefile | 20 +++++++++ .../metadata/table_creator/table_creator.ml | 45 +++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 helm/ocaml/metadata/table_creator/.depend create mode 100644 helm/ocaml/metadata/table_creator/Makefile create mode 100644 helm/ocaml/metadata/table_creator/table_creator.ml diff --git a/helm/ocaml/metadata/table_creator/.depend b/helm/ocaml/metadata/table_creator/.depend new file mode 100644 index 000000000..1cf113d91 --- /dev/null +++ b/helm/ocaml/metadata/table_creator/.depend @@ -0,0 +1,4 @@ +sql.cmo: sql.cmi +sql.cmx: sql.cmi +table_creator.cmo: sql.cmi +table_creator.cmx: sql.cmx diff --git a/helm/ocaml/metadata/table_creator/Makefile b/helm/ocaml/metadata/table_creator/Makefile new file mode 100644 index 000000000..8b08e6d51 --- /dev/null +++ b/helm/ocaml/metadata/table_creator/Makefile @@ -0,0 +1,20 @@ +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 + +all: table_creator +opt: table_creator.opt + +table_creator: table_creator.ml + $(OCAMLFIND) ocamlc \ + -thread -package mysql,helm-metadata -linkpkg -o $@ $< + +table_creator.opt: table_creator.ml + $(OCAMLFIND) ocamlopt \ + -thread -package mysql,helm-metadata -linkpkg -o $@ $< + +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 new file mode 100644 index 000000000..7cd3b35f2 --- /dev/null +++ b/helm/ocaml/metadata/table_creator/table_creator.ml @@ -0,0 +1,45 @@ + +let map = + (MetadataTypes.library_obj_tbl,`RefObj) :: + (MetadataTypes.library_sort_tbl,`RefSort) :: + (MetadataTypes.library_rel_tbl,`RefRel) :: + (MetadataTypes.library_name_tbl,`ObjectName) :: +(* (MetadataTypes.library_???_tbl,`Owners) :: *) + (MetadataTypes.library_count_tbl,`Count) :: [] + +let usage argv_o = + prerr_string "\nusage:"; + prerr_string ("\t" ^ argv_o ^ " [-index] tablename[=rename]\n\n"); + prerr_string "known tables:"; + List.iter (fun (n,_) -> prerr_string (" " ^ n)) map; + prerr_endline "\n" + +let eq_RE = Str.regexp "=" + +let parse_args l = + List.map (fun s -> + let parts = Str.split eq_RE s in + let len = List.length parts in + assert (len = 1 || len = 2); + if len = 1 then (s,s) else (List.nth parts 0, List.nth parts 1)) + l + +let main () = + let len = Array.length Sys.argv in + if len < 2 then + begin + usage Sys.argv.(0); + exit 1 + end + else + begin + 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 (SqlStatements.create_tables todo); + if index then print_endline (SqlStatements.create_indexes todo) + end + +let _ = main () + -- 2.39.2