+let add_constraint tables (n,from,where) metadata =
+ let obj_tbl,rel_tbl,sort_tbl,conclno_tbl,fullno_tbl,hypno_tbl = tables in
+ let cur_tbl = tbln n in
+ match metadata with
+ | `Obj (uri, positions) ->
+ let from = (sprintf "%s as %s" obj_tbl cur_tbl) :: from in
+ let where =
+ (sprintf "(%s.h_occurrence = \"%s\")" cur_tbl uri) ::
+ mk_positions positions cur_tbl ::
+ (if n=0 then []
+ else [sprintf "table0.source = %s.source" cur_tbl]) @
+ where
+ in
+ ((n+2), from, where)
+ | `Rel positions ->
+ let from = (sprintf "%s as %s" rel_tbl cur_tbl) :: from in
+ let where =
+ mk_positions positions cur_tbl ::
+ (if n=0 then []
+ else [sprintf "table0.source = %s.source" cur_tbl]) @
+ where
+ in
+ ((n+2), from, where)
+ | `Sort (sort, positions) ->
+ let sort_str = CicPp.ppsort sort in
+ let from = (sprintf "%s as %s" sort_tbl cur_tbl) :: from in
+ let where =
+ (sprintf "%s.h_sort = \"%s\"" cur_tbl sort_str ) ::
+ mk_positions positions cur_tbl ::
+ (if n=0 then
+ []
+ else
+ [sprintf "table0.source = %s.source" cur_tbl ]) @ where
+ in
+ ((n+2), from, where)
+
+let at_least ~(dbd:Mysql.dbd) ?concl_card ?full_card ?diff ?rating tables