From: Enrico Tassi Date: Tue, 3 May 2005 13:55:07 +0000 (+0000) Subject: more friendly sqlStatements api X-Git-Tag: single_binding~114 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=30e88ee56b57607a22e9c668dd96a0972329f074;p=helm.git more friendly sqlStatements api --- diff --git a/helm/ocaml/metadata/sqlStatements.ml b/helm/ocaml/metadata/sqlStatements.ml index b57c661f3..0c51feba6 100644 --- a/helm/ocaml/metadata/sqlStatements.ml +++ b/helm/ocaml/metadata/sqlStatements.ml @@ -4,78 +4,75 @@ type tbl = [ `RefObj| `RefSort| `RefRel| `ObjectName| `Owners| `Count] (* TABLES *) -let sprintf_refObj_format name = sprintf " +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 +);" name] -let sprintf_refSort_format name = sprintf " +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 +);" name] -let sprintf_refRel_format name = sprintf " +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 +);" name] -let sprintf_objectName_format name = sprintf " +let sprintf_objectName_format name = [sprintf " CREATE TABLE %s ( source varchar(255) binary not null, value varchar(255) binary not null -);" name +);" name] -let sprintf_owners_format name = sprintf " +let sprintf_owners_format name = [sprintf " CREATE TABLE %s ( source varchar(255) binary not null, owner varchar(255) binary not null -);" name +);" name] -let sprintf_count_format name = sprintf " +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 +);" name] (* INDEXES *) -let sprintf_refObj_index name = sprintf " -CREATE INDEX %s_source ON %s (source); -CREATE INDEX %s_target ON %s (h_occurrence); -CREATE INDEX %s_position ON %s (h_position); -" name name name name name name +let sprintf_refObj_index name = [ +sprintf "CREATE INDEX %s_source ON %s (source);" name name ; +sprintf "CREATE INDEX %s_target ON %s (h_occurrence);" name name ; +sprintf "CREATE INDEX %s_position ON %s (h_position);" name name ] -let sprintf_refSort_index name = sprintf " +let sprintf_refSort_index name = [sprintf " CREATE INDEX %s_source ON %s (source); -" name name +" name name] -let sprintf_objectName_index name = sprintf " -CREATE INDEX %s_value ON %s (value); -" name name +let sprintf_objectName_index name = [ +sprintf " CREATE INDEX %s_value ON %s (value);" name name] -let sprintf_owners_index name = sprintf " -CREATE INDEX %s_owner ON %s (owner); -CREATE INDEX %s_source ON %s (source); -" name name name name +let sprintf_owners_index name = [ +sprintf "CREATE INDEX %s_owner ON %s (owner);" name name ; +sprintf "CREATE INDEX %s_source ON %s (source);" name name] -let sprintf_count_index name = sprintf " -CREATE INDEX %s_source ON %s (source); -CREATE INDEX %s_conclusion ON %s (conclusion); -CREATE INDEX %s_hypothesis ON %s (hypothesis); -CREATE INDEX %s_statement ON %s (statement); -" name name name name name name name name +let sprintf_count_index name = [ +sprintf "CREATE INDEX %s_source ON %s (source);" name name; +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_refRel_index name = [] (* FUNCTIONS *) @@ -98,8 +95,8 @@ let get_index_format t named = | `Count -> sprintf_count_index named let create_tables l = - List.fold_left (fun s (name,table) -> s ^ get_table_format table name) "" 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 + List.fold_left (fun s (name,table) -> s @ get_index_format table name) [] l diff --git a/helm/ocaml/metadata/sqlStatements.mli b/helm/ocaml/metadata/sqlStatements.mli index caf1e037b..d73215134 100644 --- a/helm/ocaml/metadata/sqlStatements.mli +++ b/helm/ocaml/metadata/sqlStatements.mli @@ -1,7 +1,7 @@ type tbl = [ `RefObj| `RefSort| `RefRel| `ObjectName| `Owners| `Count] -val create_tables: (string * tbl) list -> string +val create_tables: (string * tbl) list -> string list -val create_indexes: (string * tbl) list -> string +val create_indexes: (string * tbl) list -> string list diff --git a/helm/ocaml/metadata/table_creator/table_creator.ml b/helm/ocaml/metadata/table_creator/table_creator.ml index 7cd3b35f2..4eb84ad74 100644 --- a/helm/ocaml/metadata/table_creator/table_creator.ml +++ b/helm/ocaml/metadata/table_creator/table_creator.ml @@ -37,8 +37,9 @@ let main () = 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) + print_endline (String.concat "\n" (SqlStatements.create_tables todo)); + if index then + print_endline (String.concat "\n" (SqlStatements.create_indexes todo)) end let _ = main ()