(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: admin.ml,v 1.7 2006/03/27 18:09:47 rich Exp $
+ * $Id: admin.ml,v 1.8 2006/03/28 16:24:08 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
let run r (q : cgi) dbh _ _ _ =
(* Select out the alternative hostnames. *)
- let sth = dbh#prepare_cached
- "select hs.hostid, hs.name from hostnames hs
- where not exists (select 1 from hosts
- where id = hs.hostid
- and canonical_hostname = hs.name)" in
- sth#execute [];
-
- let hostnames = sth#map (function [`Int hostid; `String name] ->
- hostid, name
- | _ -> assert false) in
+ let hostnames = PGSQL(dbh)
+ "select hs.hostid, hs.name from hostnames hs
+ where not exists (select 1 from hosts
+ where id = hs.hostid
+ and canonical_hostname = hs.name)" in
(* Pull out the details of all the wikis on the server. *)
- let sth = dbh#prepare_cached
- "select h.id, h.canonical_hostname,
- (select count(*) from pages
- where hostid = h.id and url is not null),
- (select max(last_modified_date) from pages
- where hostid = h.id and url is not null)
- from hosts h
- order by 2" in
- sth#execute [];
+ let rows = PGSQL(dbh)
+ "select h.id, h.canonical_hostname,
+ (select count(*) from pages
+ where hostid = h.id and url is not null),
+ (select max(last_modified_date) from pages
+ where hostid = h.id and url is not null)
+ from hosts h
+ order by 2" in
let table =
- sth#map
- (function [`Int id; `String canonical_hostname;
- (`Null | `Int _) as page_count;
- (`Null | `Timestamp _) as last_modified_date] ->
+ List.map (
+ function (id, canonical_hostname,
+ page_count, last_modified_date) ->
let page_count = match page_count with
- `Null -> 0
- | `Int n -> n in
+ | None -> 0L
+ | Some n -> n in
let last_modified_date = match last_modified_date with
- `Null -> "-"
- | `Timestamp date -> printable_date date in
+ | None -> "-"
+ | Some date -> printable_date date in
let hostnames =
List.filter (fun (i, _) -> i = id) hostnames in
[ "hostname", Template.VarString hostname ])
hostnames in
- [ "id", Template.VarString (string_of_int id);
+ [ "id", Template.VarString (Int32.to_string id);
"canonical_hostname", Template.VarString canonical_hostname;
- "page_count", Template.VarString (string_of_int page_count);
+ "page_count", Template.VarString (Int64.to_string page_count);
"last_modified_date", Template.VarString last_modified_date;
"hostnames", Template.VarTable hostnames ]
-
- | _ -> assert false) in
+ ) rows in
template#table "hosts" table;