Changes done on the Mac.
[cocanwiki.git] / scripts / orphans.ml
index a83f883..cddc0fe 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: orphans.ml,v 1.3 2006/03/27 18:09:46 rich Exp $
+ * $Id: orphans.ml,v 1.4 2006/03/28 13:20:00 rich Exp $
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -33,10 +33,8 @@ let run r (q : cgi) dbh hostid _ _ =
   (* Start with the front page, the contents of the site menu and the
    * special "copyright" page.
    *)
-  let sth = dbh#prepare_cached "select url from sitemenu where hostid = ?" in
-  sth#execute [Some hostid];
-
-  let start_pages = sth#map (function [Some s] -> s | _ -> assert false) in
+  let start_pages =
+    PGSQL(dbh) "select url from sitemenu where hostid = $hostid" in
   let start_pages = "index" :: "copyright" :: start_pages in
 
   (* The find the list of orphans, we first construct the list of
@@ -55,37 +53,27 @@ let run r (q : cgi) dbh hostid _ _ =
      * pages @ border is a list of distinct pages
      *)
     let pages' = pages @ border in
-    let qs = Dbi.placeholders (List.length border) in
-    let qs' = Dbi.placeholders (List.length pages') in
-    let sth =
-      dbh#prepare_cached ("select distinct to_url from links
-                            where hostid = ? and from_url in " ^ qs ^ "
-                              and to_url not in " ^ qs') in
-    sth#execute (Some hostid ::
-                  (List.map (fun s -> Some s) border) @
-                  (List.map (fun s -> Some s) pages'));
-    let border' = sth#map (function [Some s] -> s | _ -> assert false) in
-
+    let border' =
+      PGSQL(dbh) "select distinct to_url from links
+                   where hostid = $hostid and from_url in $@border
+                              and to_url not in $@pages')" in
     if border' = [] then pages'
     else loop pages' border'
   in
   let non_orphans = loop [] start_pages in
 
   (* Get the actual orphans, which are pages which do not appear in this list*)
-  let qs = Dbi.placeholders (List.length non_orphans) in
-  let sth = dbh#prepare_cached ("select url, title from pages
-                                  where hostid = ?
-                                    and url is not null
-                                    and redirect is null
-                                    and url not in " ^ qs ^ "
-                                  order by 1") in
-  sth#execute (Some hostid :: (List.map (fun s -> Some s) non_orphans));
+  let rows = PGSQL(dbh)
+    "select url, title from pages
+      where hostid = $hostid
+        and url is not null and redirect is null
+        and url not in $@non_orphans
+      order by 1" in
 
   let table =
-    sth#map (function [Some page; Some title] ->
+    List.map (fun (page, title) ->
               [ "page", Template.VarString page;
-                "title", Template.VarString title ]
-              | _ -> assert false) in
+                "title", Template.VarString title ]) rows in
 
   template#table "pages" table;