(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: contacts.ml,v 1.2 2005/11/23 11:32:12 rich Exp $
+ * $Id: contacts.ml,v 1.4 2006/12/06 09:46:56 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
open Cocanwiki
open Cocanwiki_template
-let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ =
- let template = get_template dbh hostid "contacts.html" in
+let run r (q : cgi) dbh hostid _ _ =
+ let template = get_template r dbh hostid "contacts.html" in
(* Pull out all the contacts from the database. *)
- let sth = dbh#prepare_cached
- "select c.id, c.name, c.subject,
- (select count(*)::int4 from contact_emails
- where contactid = c.id)
- from contacts c
- where c.hostid = ?
- order by c.name, c.id" in
- sth#execute [`Int hostid];
+ let rows = PGSQL(dbh)
+ "select c.id, c.name, c.subject,
+ (select count(*)::int4 from contact_emails
+ where contactid = c.id)
+ from contacts c
+ where c.hostid = $hostid
+ order by c.name, c.id" in
let table =
- sth#map
- (function
- [`Int id; `String name; `String subject; `Int count] ->
- [ "id", Template.VarString (string_of_int id);
- "name", Template.VarString name;
- "subject", Template.VarString subject;
- "count", Template.VarString (string_of_int count) ]
- | _ -> assert false) in
+ List.map
+ (fun (id, name, subject, count) ->
+ [ "id", Template.VarString (Int32.to_string id);
+ "name", Template.VarString name;
+ "subject", Template.VarString subject;
+ "count", Template.VarString (Int32.to_string (Option.get count)) ]
+ ) rows in
template#table "contacts" table;