+csv dep for PG'OCaml.
[cocanwiki.git] / scripts / dead_ends.ml
index 1fe5d04..08afefc 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: dead_ends.ml,v 1.2 2004/10/04 15:19:56 rich Exp $
+ * $Id: dead_ends.ml,v 1.4 2006/12/06 09:46:57 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
@@ -27,27 +27,28 @@ open Printf
 open Cocanwiki
 open Cocanwiki_template
 
-let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ =
-  let template = get_template dbh hostid "dead_ends.html" in
+let run r (q : cgi) dbh hostid _ _ =
+  let template = get_template dbh hostid "dead_ends.html" in
 
-  let sth =
-    dbh#prepare_cached
+  let rows =
+    PGSQL(dbh)
       "select p.url, p.title, count (l.to_url)
          from pages p left outer join links l
               on p.hostid = l.hostid and p.url = l.from_url
-        where p.hostid = ?
+        where p.hostid = $hostid
           and p.url is not null
           and p.redirect is null
         group by 1, 2
        having count(l.to_url) = 0
         order by 1" in
-  sth#execute [`Int hostid];
 
   let table =
-    sth#map (function [`String page; `String title; _] ->
-              [ "page", Template.VarString page;
-                "title", Template.VarString title ]
-              | _ -> assert false) in
+    List.map (
+      fun (page, title, _) ->
+       let page = Option.get page in
+       [ "page", Template.VarString page;
+         "title", Template.VarString title ]
+    ) rows in
 
   template#table "pages" table;