- let add_constraint (n,from,where) metadata =
- let cur_tbl = tbln n in
- match metadata with
- | `Obj (uri, pos, depth_opt) ->
- let tbl = MetadataTypes.obj_tbl in
- let pos_str = MetadataPp.pp_position pos in
- let from = (sprintf "%s as %s" tbl cur_tbl) :: from in
- let where =
- (sprintf "%s.h_position = \"%s\"" cur_tbl pos_str) ::
- (sprintf "%s.h_occurrence = \"%s\"" cur_tbl uri) ::
- (if n=0 then []
- else [sprintf "table0.source = %s.source" cur_tbl]) @
- where
- in
- let where = add_depth_constr depth_opt cur_tbl where in
- ((n+1), from, where)
- | `Rel (pos, depth) ->
- let tbl = MetadataTypes.rel_tbl in
- let pos_str = MetadataPp.pp_position (pos :> MetadataTypes.position) in
- let from = (sprintf "%s as %s" tbl cur_tbl) :: from in
- let where =
- (sprintf "%s.h_position = \"%s\"" cur_tbl pos_str) ::
- (if n=0 then []
- else [sprintf "table0.source = %s.source" cur_tbl]) @
- where
- in
- let where = add_depth_constr (Some depth) cur_tbl where in
- ((n+1), from, where)
- | `Sort (sort, pos, depth) ->
- let tbl = MetadataTypes.sort_tbl in
- let pos_str = MetadataPp.pp_position (pos :> MetadataTypes.position) in
- let sort_str = MetadataPp.pp_sort sort in
- let from = (sprintf "%s as %s" tbl cur_tbl) :: from in
- let where =
- (sprintf "%s.h_position = \"%s\"" cur_tbl pos_str) ::
- (sprintf "%s.h_sort = \"%s\"" cur_tbl sort_str) ::
- (if n=0 then []
- else [sprintf "table0.source = %s.source" cur_tbl]) @
- where
- in
- let where = add_depth_constr (Some depth) cur_tbl where in
- ((n+1), from, where)