5 (MetadataTypes.library_obj_tbl,`RefObj) ::
6 (MetadataTypes.library_sort_tbl,`RefSort) ::
7 (MetadataTypes.library_rel_tbl,`RefRel) ::
8 (MetadataTypes.library_name_tbl,`ObjectName) ::
9 (MetadataTypes.library_hits_tbl,`Hits) ::
10 (MetadataTypes.library_count_tbl,`Count) :: []
13 prerr_string "\nusage:";
14 prerr_string ("\t" ^ argv_o ^ " what tablename[=rename]\n");
15 prerr_string ("\t" ^ argv_o ^ " what all\n\n");
16 prerr_endline "what:";
17 prerr_endline "\tlist\tlist table names";
18 prerr_endline "\ttable\toutput SQL regarding tables";
19 prerr_endline "\tindex\toutput SQL regarding indexes";
20 prerr_endline "\tfill\toutput SQL filling tables (only \"hits\" supported)\n";
21 prerr_string "known tables:\n\t";
22 List.iter (fun (n,_) -> prerr_string (" " ^ n)) map;
25 let eq_RE = Str.regexp "="
29 let parts = Str.split eq_RE s in
30 let len = List.length parts in
31 assert (len = 1 || len = 2);
32 if len = 1 then (s,s) else (List.nth parts 0, List.nth parts 1))
35 let destructor_RE = Str.regexp "table_destructor\\(\\|\\.opt\\)$"
37 let am_i_destructor () =
39 let _ = Str.search_forward destructor_RE Sys.argv.(0) 0 in true
40 with Not_found -> false
43 let len = Array.length Sys.argv in
52 if am_i_destructor () then
53 (SqlStatements.drop_tables,
55 let dbd = HSql.fake_db_for_mysql HSql.Library in
56 SqlStatements.drop_indexes x HSql.Library dbd),
57 fun _ t -> [sprintf "DELETE * FROM %s;" t])
59 (SqlStatements.create_tables,
60 SqlStatements.create_indexes,
61 SqlStatements.fill_hits)
65 match Sys.argv.(1) with
70 | _ -> failwith "what must be one of \"index\", \"table\", \"fill\""
72 let todo = Array.to_list (Array.sub Sys.argv from (len - from)) in
73 let todo = match todo with ["all"] -> List.map fst map | todo -> todo in
74 let todo = parse_args todo in
75 let todo = List.map (fun (x,name) -> name, (List.assoc x map)) todo in
77 | `Index -> print_endline (String.concat "\n" (idx todo))
78 | `Table -> print_endline (String.concat "\n" (tab todo))
80 print_endline (String.concat "\n"
81 (fill MetadataTypes.library_obj_tbl MetadataTypes.library_hits_tbl))
82 | `List -> print_endline (String.concat " " (List.map fst map))