(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: edit_contact_form.ml,v 1.1 2004/09/21 18:24:15 rich Exp $
+ * $Id: edit_contact_form.ml,v 1.3 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
open Cocanwiki
open Cocanwiki_template
-let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ =
- let template = get_template dbh hostid "edit_contact_form.html" in
+let run r (q : cgi) dbh hostid _ _ =
+ let template = get_template r dbh hostid "edit_contact_form.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);
(* Get details from 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;
- 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