(* 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 = [
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 =
| `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
+
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
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 ()