]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/metadata/metadataConstraints.ml
fix for instance
[helm.git] / helm / ocaml / metadata / metadataConstraints.ml
index cbeaad49d5112825ce632f122b4c7cdee1417f42..952aa5a575a5ed98d725497fcb41918de92ee787 100644 (file)
@@ -151,6 +151,7 @@ let at_least ~(dbd:Mysql.dbd) ?concl_card ?full_card ?diff ?rating tables
   let (n,from,where) =
     List.fold_left (add_constraint tables) (0,[],[]) metadata
   in
+  let selected = if metadata = [] then count_tbl else "table0" in
   let (n,from,where) =
     add_all_constr count_tbl (n,from,where) concl_card full_card diff
   in
@@ -158,12 +159,12 @@ let at_least ~(dbd:Mysql.dbd) ?concl_card ?full_card ?diff ?rating tables
   let where = String.concat " and " where in
   let query =
     match rating with
-    | None -> sprintf "select table0.source from %s where %s" from where
+    | None -> sprintf "select %s.source from %s where %s" selected from where
     | Some `Hits ->
         sprintf
-          ("select table0.source from %s, hits where %s"
-           ^^ " and hits.source = table0.source order by hits.no desc")
-          from where
+          ("select %s.source from %s, hits where %s"
+           ^^ " and hits.source = %s.source order by hits.no desc")
+          selected from where selected
   in
   prerr_endline query; 
   let result = Mysql.exec dbd query in