1 (** Global list of tables *)
8 let all : table list
ref = ref []
10 (** FIXME table names case sensitivity? *)
11 let by_name name
= fun (n
,_
) -> n
= name
13 (** @raise Error when no such table *)
14 let get_from tables name
=
16 List.find
(by_name name
) tables
17 with Not_found
-> failwith
(sprintf
"no such table %s" name
)
19 let get name
= get_from !all name
20 let get_schema name
= snd
(get name
)
21 let check name
= ignore
(get name
)
24 let (name
,schema
) = v
in
25 match List.find_all
(by_name name
) !all with
26 | [] -> all := v
:: !all
27 | _
-> failwith
(sprintf
"table %s already exists" name
)
29 let drop name
= check name
; all := List.remove_if
(by_name name
) !all
32 let alter_scheme ((n
,s
) as table
) =
38 all := List.map
alter_scheme !all
40 let alter_add name col pos
= alter name
(fun s
-> RA.Schema.add s col pos
)
41 let alter_drop name col
= alter name
(fun s
-> RA.Schema.drop s col
)
43 let print () = List.iter
RA.print_table
!all
45 let reset () = all := []