- let add_constraint (n,from,where) metadata =
- let cur_tbl = tbln n in
- let cur_ltbl = tbln (n+1) in
- match metadata with
- | `Obj (uri, positions) ->
- let tbl = MetadataTypes.obj_tbl () in
- let ltbl = MetadataTypes.library_obj_tbl in
- let from =
- (sprintf "%s AS %s, %s AS %s" tbl cur_tbl ltbl cur_ltbl) :: from
- in
- let where =
- (sprintf "(%s.h_occurrence = \"%s\" OR %s.h_occurrence = \"%s\")"
- cur_tbl uri cur_ltbl uri) ::
- mk_positions positions cur_tbl ::
- (if n=0 then []
- else [sprintf
- "(table0.source = %s.source OR table0.source = %s.source)"
- cur_tbl cur_ltbl]) @ where
- in
- ((n+2), from, where)
- | `Rel positions ->
- let tbl = MetadataTypes.rel_tbl () in
- let ltbl = MetadataTypes.library_rel_tbl in
- let from =
- (sprintf "%s AS %s, %s AS %s" tbl cur_tbl ltbl cur_ltbl) :: from
- in
- let where =
- mk_positions positions cur_tbl ::
- (if n=0 then []
- else [sprintf
- "(table0.source = %s.source OR table0.source = %s.source)"
- cur_tbl cur_ltbl]) @ where
- in
- ((n+2), from, where)
- | `Sort (sort, positions) ->
- let tbl = MetadataTypes.sort_tbl () in
- let ltbl = MetadataTypes.library_sort_tbl in
- let sort_str = CicPp.ppsort sort in
- let from =
- (sprintf "%s AS %s, %s AS %s" tbl cur_tbl ltbl cur_ltbl) :: from
- in
- let where =
- (sprintf "(%s.h_sort = \"%s\" OR %s.h_sort = \"%s\")"
- cur_tbl sort_str cur_ltbl sort_str) ::
- mk_positions positions cur_tbl ::
- (if n=0 then
- []
- else
- [sprintf
- "(table0.source = %s.source OR table0.source = %s.source)"
- cur_tbl cur_ltbl]) @ where
- in
- ((n+2), from, where)