Don't forget the date\!
[cocanwiki.git] / scripts / contact_show.ml
index d65c99c..ba13bb8 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: contact_show.ml,v 1.1 2004/09/17 16:03:34 rich Exp $
+ * $Id: contact_show.ml,v 1.3 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
@@ -27,36 +27,32 @@ open Printf
 open Cocanwiki
 open Cocanwiki_template
 
-let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ =
-  let template = get_template dbh hostid "contact_show.html" in
+let run r (q : cgi) dbh hostid _ _ =
+  let template = get_template dbh hostid "contact_show.html" in
 
-  let id = int_of_string (q#param "id") in
-  template#set "id" (string_of_int id);
+  let id = Int32.of_string (q#param "id") in
+  template#set "id" (Int32.to_string id);
 
   (* Pull out all the details out of the database. *)
-  let sth = dbh#prepare_cached
-             "select name, subject
-                 from contacts where hostid = ? and id = ?" in
-  sth#execute [`Int hostid; `Int id];
+  let rows = PGSQL(dbh)
+    "select name, subject from contacts
+      where hostid = $hostid and id = $id" in
 
   let name, subject =
-    match sth#fetch1 () with
-       [ `String name; `String subject ] -> name, subject
-      | _ -> assert false in
+    match rows with
+    | [row] -> row
+    | _ -> assert false in
 
   template#set "name" name;
   template#set "subject" subject;
 
   (* Get the emails. *)
-  let sth = dbh#prepare_cached
-             "select email from contact_emails where contactid = ?
-                order by 1" in
-  sth#execute [`Int id];
-
-  let table = sth#map (function [`String email] ->
-                        [ "email", Template.VarString email ]
-                        | _ -> assert false) in
+  let rows = PGSQL(dbh)
+    "select email from contact_emails where contactid = $id
+      order by 1" in
 
+  let table =
+    List.map (fun email -> [ "email", Template.VarString email ]) rows in
   template#table "emails" table;
 
   q#template template