failwith "MetadataQuery.at_least: no constraints given";
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 from = (sprintf "%s as %s" tbl cur_tbl) :: from 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\"" cur_tbl uri) ::
+ (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" cur_tbl]) @
- where
+ else [sprintf
+ "(table0.source = %s.source AND table0.source = %s.source)"
+ cur_tbl cur_ltbl]) @ where
in
- ((n+1), from, where)
+ ((n+2), from, where)
| `Rel positions ->
let tbl = MetadataTypes.rel_tbl () in
- let from = (sprintf "%s as %s" tbl cur_tbl) :: from 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" cur_tbl]) @
- where
+ else [sprintf
+ "(table0.source = %s.source AND table0.source = %s.source)"
+ cur_tbl cur_ltbl]) @ where
in
- ((n+1), from, where)
+ ((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" tbl cur_tbl) :: from 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\"" cur_tbl sort_str) ::
- mk_positions positions cur_tbl ::
- (if n=0 then []
- else [sprintf "table0.source = %s.source" cur_tbl]) @
- 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 AND table0.source = %s.source)"
+ cur_tbl cur_ltbl]) @ where
in
- ((n+1), from, where)
+ ((n+2), from, where)
in
let (n,from,where) = List.fold_left add_constraint (0,[],[]) metadata in
let (n,from,where) =
"\"MainHypothesis\""]
in
let query =
- sprintf "select h_occurrence from refObj where source=\"%s\" and (%s)"
- uri (String.concat " or " positions)
+ sprintf ("SELECT h_occurrence FROM %s WHERE source=\"%s\" AND (%s) UNION"^^
+ "SELECT h_occurrence FROM %s WHERE source=\"%s\" AND (%s)")
+ (MetadataTypes.obj_tbl ()) uri (String.concat " OR " positions)
+ MetadataTypes.library_obj_tbl uri (String.concat " OR " positions)
+
in
let result = Mysql.exec dbd query in
let set = ref StringSet.empty in